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';
21 require_once 'plc_forms.php';
23 // --------------------
24 // recognized URL arguments
25 $person_id=intval($_GET['id']);
27 plc_error('Malformed URL - id not set');
32 // Get all columns as we focus on only one entry
33 $persons= $api->GetPersons( array($person_id));
35 if (empty($persons)) {
36 drupal_set_message ("Person " . $person_id . " not found");
42 $enabled= $person['enabled'];
43 $first_name= $person['first_name'];
44 $last_name= $person['last_name'];
45 $email= $person['email'];
47 $phone= $person['phone'];
48 $title= $person['title'];
50 $peer_id=$person['peer_id'];
53 $role_ids= $person['role_ids'];
54 $roles= $person['roles'];
55 $site_ids= $person['site_ids'];
56 $slice_ids= $person['slice_ids'];
57 $key_ids= $person['key_ids'];
59 // gets more data from API calls
60 $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
61 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
62 $keys= $api->GetKeys( $key_ids );
64 drupal_set_title("Details for account " . $first_name . " " . $last_name);
66 $plc_hash=plc_peer_get_hash($api);
68 $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
69 $is_my_account = plc_my_person_id() == $person_id;
70 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
75 if ($privileges || $is_my_account)
76 $tabs['Update'] = array('url'=>'/db/persons/update.php',
77 'values'=>array('id'=>$person_id),
78 'bubble'=>"Update $first_name $last_name");
81 if ($local_peer && $privileges)
83 $tabs['Disable'] = array ('method'=>'POST',
84 'url'=>l_person_actions(),
85 'values'=> array ('person_id'=>$person_id,
86 'action'=>'disable-person'),
87 'bubble'=>"Disable $first_name $last_name",
88 'confirm'=>"Are you sure you want to disable $first_name $last_name");
90 $tabs['Enable'] = array ('method'=>'POST',
91 'url'=>l_person_actions(),
92 'values'=> array ('person_id'=>$person_id,
93 'action'=>'enable-person'),
94 'bubble'=>"Enable $first_name $last_name",
95 'confirm'=>"Are you sure you want to enable $first_name $last_name");
98 if (plc_is_admin() && ! $is_my_account)
99 $tabs['Become'] = array('url'=>l_person_actions(),
100 'values'=>array('action'=>'become-person',
101 'person_id'=>$person_id),
102 'bubble'=>"Become $first_name $last_name",
103 'confirm'=>"Are you sure you want to su $first_name $last_name");
106 if ($local_peer && $privileges)
107 $tabs['Delete'] = array ('method'=>'POST',
108 'url'=>l_person_actions(),
109 'values'=> array ('person_id'=>$person_id,
110 'action'=>'delete-person'),
111 'bubble'=>"Delete $first_name $last_name",
112 'confirm'=>"Are you sure to delete $first_name $last_name");
113 // events for that person
115 $tabs['Events'] = array('url'=>l_events(),
116 'values'=>array('type'=>'Person','person'=>$person_id),
117 'bubble'=>"Events about $first_name $last_name",
118 'image'=>'/planetlab/icons/event.png',
122 $tabs['All Users'] = array ('url'=>l_persons(),
123 'bubble'=>'Back to the Users page');
127 if ($local_peer && $privileges && ! $enabled )
128 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
130 $enabled_text="Enabled";
131 if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
134 plc_details_line("Enabled",$enabled_text);
135 plc_details_line("First Name",$first_name);
136 plc_details_line("Last Name",$last_name);
137 plc_details_line("Email",href("mailto:$email",$email));
138 plc_details_line("URL",$url);
139 plc_details_line("Phone",$phone);
140 plc_details_line("Title",$title);
141 plc_details_line("Bio",wordwrap($bio,50,"<br/>"));
144 //////////////////// slices
146 plc_table_title('Slices');
148 if( empty( $slices ) ) {
149 drupal_set_message ("User has no slice");
151 $columns=array('Slice name'=>'string');
152 plc_table_start("person_slices",$columns,1,$table_options);
154 foreach( $slices as $slice ) {
155 $slice_name= $slice['name'];
156 $slice_id= $slice['slice_id'];
157 plc_table_row_start();
158 plc_table_cell(l_slice_t($slice_id,$slice_name));
161 plc_table_end("person_slices");
166 plc_table_title ("Keys");
168 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
169 if ( empty( $key_ids ) ) {
170 plc_warning("This user has no known key");
172 // we don't set 'action', but use the submit button name instead
173 plc_form_start(l_person_actions(),
174 array("person_id"=>$person_id));
177 $columns=array("Type"=>"string",
179 if ($can_manage_keys) $columns['Remove']="none";
180 // table overall options
181 $table_options=array("search_area"=>false,"notes_area"=>false);
182 // add the 'remove site' button and key upload areas as the table footer
183 if ($can_manage_keys) {
184 $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
185 $upload_key_left_area= plc_form_label_text("Upload new key","key") . plc_form_file_text("key",60);
186 $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
187 $table_options['footer']="";
188 $table_options['footer'].="<tr><td colspan=3 style='text-align:right'> $remove_keys_area </td></tr>";
189 $table_options['footer'].="<tr><td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
190 "<td> $upload_key_right_area </td></tr>";
192 plc_table_start("person_keys",$columns,"1",$table_options);
194 foreach( $keys as $key ) {
195 $key_id=$key['key_id'];
196 plc_table_row_start($key_id);
197 plc_table_cell ($key['key_type']);
198 plc_table_cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
199 if ($can_manage_keys)
200 plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id));
203 plc_table_end("person_keys");
209 plc_table_title('Sites');
212 if (empty( $sites ) ) {
213 plc_warning('This user is not affiliated with a site !!');
216 $columns['Name']="string";
217 $columns['Login_base']="string";
218 $columns['Remove']="string";
219 $table_options = array('notes_area'=>false,'search_area'=>false);
220 plc_table_start ("person_sites",$columns,1,$table_options);
221 foreach( $sites as $site ) {
222 $site_name= $site['name'];
223 $site_id= $site['site_id'];
224 $login_base=$site['login_base'];
225 plc_table_row_start();
226 plc_table_cell (l_site_t($site_id,$site_name));
227 plc_table_cell ($login_base);
228 plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
229 plc_table_row_end ();
231 plc_table_end("person_sites");
234 echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
237 // diplay site select list to add another site for user
238 if ($local_peer && plc_is_admin()) {
240 $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
243 $person_site= arr_diff( $all_sites, $sites );
245 $person_site= $all_sites;
247 // sort_sites( $person_site );
249 echo "<p>Select a site to add this user to: ";
250 echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
252 foreach( $person_site as $site ) {
253 echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
263 echo "<h3>Roles</h3>\n";
265 echo "<thead><tr><th>Role</th>";
267 echo "<th>Remove</th>";
268 echo "</tr></thead><tbody>\n";
270 // construct role array
271 for( $n=0; $n<count($roles); $n++ ) {
272 $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
276 if ( !empty ($roles) ) {
277 foreach( $proles as $role ) {
278 $role_name= $role['name'];
279 $role_id= $role['role_id'];
281 echo "<tr><td>$role_name";
284 if( plc_is_admin()) {
285 echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
286 if ( ! $button_shown ) {
287 $rowspan=count($roles);
288 echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
296 echo "<span class='plc-warning'> This user has no known role !!</span>";
298 echo "</tbody></table>\n";
300 // if admin show roles to add
301 if( plc_is_admin()) {
302 $all_roles= $api->GetRoles();
303 $addable_roles= arr_diff( $all_roles, $proles );
304 ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
305 ##return an empty array and the scrolling roles list is not displayed in this case
306 ##assign to addablerole all the roles
307 if (count($proles)==0)
308 $addable_roles=$all_roles;
310 if( !empty( $addable_roles ) ) {
311 echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
313 foreach( $addable_roles as $arole ) {
314 echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
323 plc_peer_block_end();
326 include 'plc_footer.php';