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 header( "location: index.php" );
39 // get slice id from GET or POST
41 $slice_id= intval( $_GET['id'] );
42 elseif ( $_POST['id'] )
43 $slice_id= intval( $_POST['id'] );
45 echo "no slice_id<br />\n";
47 // if add node submitted add the nodes to slice
49 $add_user= $_POST['add_user'];
51 foreach( $add_user as $user) {
52 $api->AddPersonToSlice( intval( $user ), $slice_id );
55 $added= "<font color=blue>People Added.</font><br />";
58 // if rem node submitted remove the nodes from slice
59 if( $_POST['remove'] ) {
60 $rem_user= $_POST['rem_user'];
62 foreach( $rem_user as $user) {
63 $api->DeletePersonFromSlice( intval( $user ), $slice_id );
66 $removed= "<font color=blue>People Removed.</font><br />";
70 $slice_info= $api->GetSlices( array( $slice_id ), array( "name", "person_ids" , "peer_id") );
71 $slice_readonly = $slice_info[0]['peer_id'];
72 drupal_set_title("Slice " . $slice_info[0]['name'] . " - Users");
75 if( !empty( $slice_info[0]['person_ids'] ) ) {
76 $person_info= $adm->GetPersons( $slice_info[0]['person_ids'], array( "first_name", "last_name", "email", "person_id","roles" ) );
77 sort_persons( $person_info );
80 // if site_id is in post use it, if not use the user's primary
81 if( $_POST['site_id'] )
82 $site_id= $_POST['site_id'];
84 $site_id= $_person['site_ids'][0];
86 // get site nodes for $site_id
87 $sid= intval( $site_id );
88 $site_user_info= $adm->GetSites( array( $sid ), array( "person_ids" ) );
89 $site_user= $site_user_info[0]['person_ids'];
92 // gets all person_ids from site that arent already associated with the slice
93 foreach( $site_user as $suser) {
94 if( !in_array( $suser, $slice_info[0]['person_ids'] ) )
99 // Get person info from new list
100 if( !empty( $susers ) ) {
101 $all_suser_info= $adm->GetPersons( $susers, array( "email", "first_name", "last_name", "person_id", "role_ids", 'roles' ) );
102 //Filter the new list of user info to omit the tech user
103 foreach( $all_suser_info as $user_info) {
104 if ( (count($user_info["role_ids"])==1 ) && ( in_array(40, $user_info["role_ids"]) )) {
107 $suser_info[]= $user_info;
109 if ( ! empty($suser_info) ) {
110 sort_persons( $suser_info );
116 if ( $slice_readonly)
117 echo "<div class='plc-foreign'>";
119 echo "<form action='slice_users.php?id=$slice_id' method=post>\n";
121 // section for adding people : for local slices only
122 if ( ! $slice_readonly ) {
124 echo "<h5>Select a site to add People from.</h5>\n";
125 echo "<select name='site_id' onChange='submit()'>\n";
127 // get site names and ids
128 $site_info= $adm->GetSites( NULL, array( "site_id", "name" ) );
129 sort_sites( $site_info );
131 foreach( $site_info as $site ) {
132 echo "<option value=". $site['site_id'];
133 if( $site['site_id'] == $site_id )
135 echo ">". $site['name'] ."</option>\n";
144 echo "<table cellpadding=2><tbody >\n<tr>";
145 echo "<th></th> <th> Email </th><th> First Name </th><th> Last Name </th><th> Roles </th>
148 foreach( $suser_info as $susers ) {
149 foreach ( $susers['roles'] as $prole)
151 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";
155 echo "</tbody></table>\n";
156 echo "<p><input type=submit value='Add People' name='add'>\n";
158 echo "<p>All People on site already added.\n";
165 // show all people currently associated
167 echo "<h5>People currently associated with slice</h5>\n";
169 if ( ! $slice_readonly ) {
170 echo "<u>Check boxes of people to remove:</u>\n";
171 echo "<table cellpadding=2><tbody >\n<tr>";
172 echo "<th></th><th> Email </th><th> First Name</th><th> Last Name</th><th> Roles </th>
175 echo "<table cellpadding=2><tbody>\n";
176 echo "<tr><th> E-mail <th> First name <th> Last name<th> Roles </th> </tr>";
179 foreach( $person_info as $person ) {
180 foreach ( $person['roles'] as $prole)
182 if ( ! $slice_readonly )
183 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";
185 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>";
189 echo "</tbody></table>\n";
190 if ( ! $slice_readonly )
191 echo "<p><input type=submit value='Remove People' name='remove'>\n";
194 echo "<p>No People associated with slice.\n";
202 echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
205 include 'plc_footer.php';