3 // Thierry on 2007-02-20
4 // There's no reason why we should see this page with a foreign slice, at least
5 // so long as the UI is used in a natural way, given the UI's logic as of now
6 // however it's always possible that someone forges her own url like
7 // http://one-lab.org/db/slices/slice_users?id=176
8 // So just to be consistent, we protect ourselves against such a usage
11 require_once 'plc_login.php';
13 // Get session and API handles
14 require_once 'plc_session.php';
15 global $plc, $api, $adm;
18 require_once 'plc_drupal.php';
19 drupal_set_title('Slices');
20 include 'plc_header.php';
23 require_once 'plc_functions.php';
24 require_once 'plc_sorts.php';
27 $_person= $plc->person;
28 $_roles= $_person['role_ids'];
30 //print_r( $_person );
32 // if no id ... redirect to slice index
33 if( !$_GET['id'] && !$_POST['id'] ) {
34 plc_redirect(l_slices());
38 // get slice id from GET or POST
40 $slice_id= intval( $_GET['id'] );
41 elseif ( $_POST['id'] )
42 $slice_id= intval( $_POST['id'] );
44 echo "no slice_id<br />\n";
46 // if add node submitted add the nodes to slice
48 $add_user= $_POST['add_user'];
50 foreach( $add_user as $user) {
51 $api->AddPersonToSlice( intval( $user ), $slice_id );
54 $added= "<font color=blue>People Added.</font><br />";
57 // if rem node submitted remove the nodes from slice
58 if( $_POST['remove'] ) {
59 $rem_user= $_POST['rem_user'];
61 foreach( $rem_user as $user) {
62 $api->DeletePersonFromSlice( intval( $user ), $slice_id );
65 $removed= "<font color=blue>People Removed.</font><br />";
69 $slice_info= $api->GetSlices( array( $slice_id ), array( "name", "person_ids" , "peer_id") );
70 $slice_readonly = $slice_info[0]['peer_id'];
71 drupal_set_title("Slice " . $slice_info[0]['name'] . " - Users");
74 if( !empty( $slice_info[0]['person_ids'] ) ) {
75 $person_info= $adm->GetPersons( $slice_info[0]['person_ids'], array( "first_name", "last_name", "email", "person_id","roles" ) );
76 sort_persons( $person_info );
79 // if site_id is in post use it, if not use the user's primary
80 if( $_POST['site_id'] )
81 $site_id= $_POST['site_id'];
83 $site_id= $_person['site_ids'][0];
85 // get site nodes for $site_id
86 $sid= intval( $site_id );
87 $site_user_info= $adm->GetSites( array( $sid ), array( "person_ids" ) );
88 $site_user= $site_user_info[0]['person_ids'];
91 // gets all person_ids from site that arent already associated with the slice
92 foreach( $site_user as $suser) {
93 if( !in_array( $suser, $slice_info[0]['person_ids'] ) )
98 // Get person info from new list
99 if( !empty( $susers ) ) {
100 $all_suser_info= $adm->GetPersons( $susers, array( "email", "first_name", "last_name", "person_id", "role_ids", 'roles' ) );
101 //Filter the new list of user info to omit the tech user
102 foreach( $all_suser_info as $user_info) {
103 if ( (count($user_info["role_ids"])==1 ) && ( in_array(40, $user_info["role_ids"]) )) {
106 $suser_info[]= $user_info;
108 if ( ! empty($suser_info) ) {
109 sort_persons( $suser_info );
115 if ( $slice_readonly)
116 echo "<div class='plc-foreign'>";
118 echo "<form action='slice_users.php?id=$slice_id' method=post>\n";
120 // section for adding people : for local slices only
121 if ( ! $slice_readonly ) {
123 echo "<h5>Select a site to add People from.</h5>\n";
124 echo "<select name='site_id' onChange='submit()'>\n";
126 // get site names and ids
127 $site_info= $adm->GetSites( NULL, array( "site_id", "name" ) );
128 sort_sites( $site_info );
130 foreach( $site_info as $site ) {
131 echo "<option value=". $site['site_id'];
132 if( $site['site_id'] == $site_id )
134 echo ">". $site['name'] ."</option>\n";
143 echo "<table cellpadding=2><tbody >\n<tr>";
144 echo "<th></th> <th> Email </th><th> First Name </th><th> Last Name </th><th> Roles </th>
147 foreach( $suser_info as $susers ) {
148 foreach ( $susers['roles'] as $prole)
150 echo "<tr><td><input type=checkbox name='add_user[]' value=". $susers['person_id'] ."> </td><td> ". $susers['email'] ." </td><td align='center'> ". $susers['first_name'] ."</td><td align='center'> ". $susers['last_name'] ."</td><td align='center'> ".$proles."</td></tr>\n";
154 echo "</tbody></table>\n";
155 echo "<p><input type=submit value='Add People' name='add'>\n";
157 echo "<p>All People on site already added.\n";
164 // show all people currently associated
166 echo "<h5>People currently associated with slice</h5>\n";
168 if ( ! $slice_readonly ) {
169 echo "<u>Check boxes of people to remove:</u>\n";
170 echo "<table cellpadding=2><tbody >\n<tr>";
171 echo "<th></th><th> Email </th><th> First Name</th><th> Last Name</th><th> Roles </th>
174 echo "<table cellpadding=2><tbody>\n";
175 echo "<tr><th> E-mail <th> First name <th> Last name<th> Roles </th> </tr>";
178 foreach( $person_info as $person ) {
179 foreach ( $person['roles'] as $prole)
181 if ( ! $slice_readonly )
182 echo "<tr><td><input type=checkbox name='rem_user[]' value=". $person['person_id'] ."> </td><td> ". $person['email'] ." </td><td align='center'> ". $person['first_name']." </td><td align='center'>".$person['last_name'] ." </td><td align='center'>".$proles."</td></tr>\n";
184 echo "<tr><td align='center'>" . $person['email'] . "</td><td align='center'>" . $person['first_name'] . "</td><td align='center'>" . $person['last_name'] ." </td><td align='center'>".$proles."</td></tr>";
188 echo "</tbody></table>\n";
189 if ( ! $slice_readonly )
190 echo "<p><input type=submit value='Remove People' name='remove'>\n";
193 echo "<p>No People associated with slice.\n";
201 echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
204 include 'plc_footer.php';