3 // $Id: index.php 11645 2009-01-21 23:09:49Z thierry $
6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_minitabs.php';
19 require_once 'plc_tables.php';
20 require_once 'plc_details.php';
22 // --------------------
23 // recognized URL arguments
24 $person_id=intval($_GET['id']);
25 if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; }
28 // Get all columns as we focus on only one entry
29 $persons= $api->GetPersons( array($person_id));
31 if (empty($persons)) {
32 drupal_set_message ("Person " . $person_id . " not found");
37 $first_name= $person['first_name'];
38 $last_name= $person['last_name'];
39 $title= $person['title'];
41 $phone= $person['phone'];
42 $email= $person['email'];
43 $enabled= $person['enabled'];
44 $peer_id=$person['peer_id'];
47 $role_ids= $person['role_ids'];
48 $roles= $person['roles'];
49 $site_ids= $person['site_ids'];
50 $slice_ids= $person['slice_ids'];
51 $key_ids= $person['key_ids'];
53 // gets more data from API calls
54 $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
55 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
56 $keys= $api->GetKeys( $key_ids );
58 drupal_set_title("Details for account " . $first_name . " " . $last_name);
60 $plc_hash=plc_peer_get_hash($api);
62 $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
63 $is_my_account = plc_my_person_id() == $person_id;
64 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
68 if ($local_peer && $privileges) {
70 $tabs['Events'] = array('url'=>l_event("Person","person",$person_id),
71 'bubble'=>'Related events',
72 'image'=>'/planetlab/icons/event.png',
75 $tabs['Disable'] = array ('method'=>'POST',
76 'url'=>'/db/persons/person_actions.php',
77 'values'=> array ('person_id'=>$person_id,
79 'bubble'=>"Disable $first_name");
81 $tabs['Enable'] = array ('method'=>'POST',
82 'url'=>'/db/persons/person_actions.php',
83 'values'=> array ('person_id'=>$person_id,
85 'bubble'=>"Enable $first_name");
86 $tabs['Delete'] = array ('method'=>'POST',
87 'url'=>'/db/persons/person_actions.php',
88 'values'=> array ('person_id'=>$person_id,
90 'bubble'=>"Delete $first_name",
91 'confirm'=>"Are you sure to delete $first_name $last_name");
94 if ($privileges || $is_my_account)
95 $tabs['Update'] = array('url'=>'/db/persons/update.php',
96 'values'=>array('id'=>$person_id),
97 'bubble'=>"Update $first_name");
99 $tabs['Persons'] = array ('url'=>l_persons());
104 plc_details_line("First Name",$first_name);
105 plc_details_line("Last Name",$last_name);
106 plc_details_line("Title",$title);
107 plc_details_line("Email",href("mailto:$email",$email));
108 plc_details_line("Phone",$phone);
109 plc_details_line("URL",$url);
116 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
117 plc_table_title('Keys');
118 if ( empty( $key_ids ) ) {
119 echo "<span class='plc-warning'> This user has no known key</span>";
121 echo "<p><table border=0 width=450>\n";
122 echo "<thead><tr><th>Type</th><th>Key</th>";
123 if ( $can_manage_keys )
124 echo "<th>Remove</th>";
125 echo "</tr></thead><tbody>\n";
127 foreach( $keys as $key ) {
128 $key_type= $key['key_type'];
129 $key_id= $key['key_id'];
130 $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
131 echo "<tr><td>$key_type</td><td>$key_text";
133 if ( $can_manage_keys )
134 echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
139 echo "</tbody></table>\n";
140 if ($can_manage_keys)
141 echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
144 if( $can_manage_keys ){
145 echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
146 <input type='submit' name='Upload' value='Upload'>\n
151 plc_table_title('Sites');
154 if (empty( $sites ) ) {
155 plc_warning('This user is not affiliated with a site !!');
158 $columns['Name']="string";
159 $columns['Login_base']="string";
160 $columns['Remove']="string";
161 $table_options = array('notes_area'=>false,'search_area'=>false);
162 plc_table_start ("person_slices",$columns,1,$table_options);
163 foreach( $sites as $site ) {
164 $site_name= $site['name'];
165 $site_id= $site['site_id'];
166 $login_base=$site['login_base'];
167 plc_table_row_start();
168 plc_table_cell (l_site_t($site_id,$site_name));
169 plc_table_cell ($login_base);
170 plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
171 plc_table_row_end ();
173 plc_table_end($table_options);
176 echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
179 // diplay site select list to add another site for user
180 if ($local_peer && plc_is_admin()) {
182 $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
185 $person_site= arr_diff( $all_sites, $sites );
187 $person_site= $all_sites;
189 // sort_sites( $person_site );
191 echo "<p>Select a site to add this user to: ";
192 echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
194 foreach( $person_site as $site ) {
195 echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
205 echo "<h3>Roles</h3>\n";
207 echo "<thead><tr><th>Role</th>";
209 echo "<th>Remove</th>";
210 echo "</tr></thead><tbody>\n";
212 // construct role array
213 for( $n=0; $n<count($roles); $n++ ) {
214 $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
218 if ( !empty ($roles) ) {
219 foreach( $proles as $role ) {
220 $role_name= $role['name'];
221 $role_id= $role['role_id'];
223 echo "<tr><td>$role_name";
226 if( plc_is_admin()) {
227 echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
228 if ( ! $button_shown ) {
229 $rowspan=count($roles);
230 echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
238 echo "<span class='plc-warning'> This user has no known role !!</span>";
240 echo "</tbody></table>\n";
242 // if admin show roles to add
243 if( plc_is_admin()) {
244 $all_roles= $api->GetRoles();
245 $addable_roles= arr_diff( $all_roles, $proles );
246 ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
247 ##return an empty array and the scrolling roles list is not displayed in this case
248 ##assign to addablerole all the roles
249 if (count($proles)==0)
250 $addable_roles=$all_roles;
252 if( !empty( $addable_roles ) ) {
253 echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
255 foreach( $addable_roles as $arole ) {
256 echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
268 plc_table_title('Slices');
270 if( empty( $slices ) ) {
271 drupal_set_message ("User has no slice");
273 $columns=array('Slice name'=>'string');
274 $table_options=array();
275 plc_table_start("person_slices",$columns,1,$table_options);
277 foreach( $slices as $slice ) {
278 $slice_name= $slice['name'];
279 $slice_id= $slice['slice_id'];
280 plc_table_row_start();
281 plc_table_cell(l_slice_t($slice_id,$slice_name));
284 plc_table_end($table_options);
287 plc_peer_block_end();
292 include 'plc_footer.php';