4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
12 include 'plc_header.php';
15 require_once 'plc_functions.php';
16 require_once 'plc_peers.php';
17 require_once 'linetabs.php';
18 require_once 'table.php';
19 require_once 'details.php';
20 require_once 'form.php';
21 require_once 'toggle.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 // we need to mention them explicitly because we want hrn that is a tag..
34 $columns=array('enabled','first_name','last_name','email','url','phone','title','bio','peer_id',
35 'role_ids','roles','site_ids','slice_ids','key_ids','hrn');
36 $persons= $api->GetPersons( array($person_id), $columns);
38 if (empty($persons)) {
39 drupal_set_message ("Person " . $person_id . " not found");
45 $enabled= $person['enabled'];
46 $first_name= $person['first_name'];
47 $last_name= $person['last_name'];
48 $email= $person['email'];
50 $phone= $person['phone'];
51 $title= $person['title'];
53 $peer_id=$person['peer_id'];
56 $role_ids= $person['role_ids'];
57 $roles= $person['roles'];
58 $site_ids= $person['site_ids'];
59 $slice_ids= $person['slice_ids'];
60 $key_ids= $person['key_ids'];
63 // gets more data from API calls
64 $site_columns=array( "site_id", "name", "login_base" );
66 $sites= $api->GetSites( $site_ids, $site_columns);
70 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
71 $keys= $api->GetKeys( $key_ids );
73 drupal_set_title("Details for account " . $first_name . " " . $last_name);
74 $local_peer = ! $peer_id;
76 $peers = new Peers ($api);
79 $site_id = $site_ids[0];
80 $is_my_account = plc_my_person_id() == $person_id;
81 $privileges = plc_is_admin () || ( plc_in_site($site_ids[0]) && plc_is_pi());
87 if (plc_is_admin() && ! $is_my_account && $local_peer && $enabled)
88 $tabs['Become'] = array('method'=>'POST',
90 'values'=>array('action'=>'become-person',
91 'person_id'=>$person_id),
92 'bubble'=>"Become $first_name $last_name",
93 'confirm'=>"Are you sure you want to become $first_name $last_name");
95 if ($local_peer && $privileges && ! $is_my_account)
97 $tabs['Disable'] = array ('method'=>'POST',
99 'values'=> array ('person_id'=>$person_id,
100 'action'=>'disable-person'),
101 'bubble'=>"Disable $first_name $last_name",
102 'confirm'=>"Are you sure you want to disable $first_name $last_name");
104 $tabs['Enable'] = array ('method'=>'POST',
106 'values'=> array ('person_id'=>$person_id,
107 'action'=>'enable-person'),
108 'bubble'=>"Enable $first_name $last_name",
109 'confirm'=>"Are you sure you want to enable $first_name $last_name");
112 if ($local_peer && $privileges && $local_peer && ! $is_my_account)
113 $tabs['Delete'] = array ('method'=>'POST',
115 'values'=> array ('person_id'=>$person_id,
116 'action'=>'delete-person'),
117 'bubble'=>"Delete $first_name $last_name",
118 'confirm'=>"Are you sure to delete $first_name $last_name");
119 // events for that person
121 $tabs['Events'] = array('url'=>l_events(),
122 'values'=>array('type'=>'Person','person'=>$person_id),
123 'bubble'=>"Events about $first_name $last_name",
124 'image'=>'/planetlab/icons/event.png','height'=>18);
126 plekit_linetabs($tabs);
128 $peers->block_start ($peer_id);
130 if ($local_peer && $privileges && ! $enabled )
131 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
133 $enabled_label="Yes";
134 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
136 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
138 $toggle = new PlekitToggle ('person',"Details",
139 array('bubble'=>'Display and modify details for that account',
140 'visible'=>get_arg('show_details')));
143 $details = new PlekitDetails($can_update);
145 $details->form_start(l_actions(),array("action"=>"update-person",
146 "person_id"=>$person_id));
150 $details->th_td("Title",$title,"title",array('width'=>10));
151 $details->th_td("First Name",$first_name,"first_name");
152 $details->th_td("Last Name",$last_name,"last_name");
153 $details->th_td(href("mailto:$email","Email"),$email,"email",array("width"=>30));
154 if ($hrn) $details->th_td("SFA hrn",$hrn);
155 else $details->tr("SFA hrn not set","center");
156 $details->th_td("Phone",$phone,"phone");
157 $details->th_td("URL",$url,"url",array('width'=>40));
158 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
160 // xxx need to check that this is working
162 $details->th_td("Password","","password1",array('input_type'=>'password'));
163 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
164 $details->tr_submit("submit","Update Account");
168 $details->th_td("Enabled",$enabled_label);
169 if ( ! $local_peer ) {
170 $details->th_td("Peer",$peers->peer_link($peer_id));
175 $details->form_end();
178 //////////////////// slices
180 $slices_title=count_english_warning($slices,'slice');
181 $toggle=new PlekitToggle ('slices',$slices_title,
182 array('visible'=>get_arg('show_slices')));
186 plc_warning ("User has no slice");
188 $headers=array('Slice name'=>'string');
190 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
191 if (count ($slices) <= $reasonable_page) {
192 $table_options['search_area']=false;
193 $table_options['pagesize_area']=false;
195 $table=new PlekitTable ("person_slices",$headers,1,$table_options);
198 foreach( $slices as $slice ) {
199 $slice_name= $slice['name'];
200 $slice_id= $slice['slice_id'];
202 $table->cell(l_slice_t($slice_id,$slice_name));
210 ////////////////////////////////////////
211 // we don't set 'action', but use the submit button name instead
212 $form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
215 //////////////////// keys
217 $keys_title = count_english_warning($keys,'key');
218 $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys')));
221 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
222 if ( empty( $key_ids ) ) {
223 plc_warning("This user has no known key");
226 $headers=array("Type"=>"string",
228 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
229 // table overall options
230 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
231 $table=new PlekitTable("person_keys",$headers,"1",$table_options);
234 if ($keys) foreach ($keys as $key) {
235 $key_id=$key['key_id'];
237 $table->cell ($key['key_type']);
238 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
239 if ($can_manage_keys)
240 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
243 // the footer area is used for displaying key-management buttons
244 // add the 'remove keys' button and key upload areas as the table footer
245 if ($can_manage_keys) {
246 $table->tfoot_start();
247 // no need to remove if there's no key
250 $table->cell($form->submit_html ("delete-keys","Remove keys"),
251 array('hfill'=>true,'align'=>'right'));
255 $table->cell($form->label_html("key","Upload new key")
256 . $form->file_html("key","upload",array('size'=>60))
257 . $form->submit_html("upload-key","Upload key"),
258 array('hfill'=>true,'align'=>'right'));
266 //////////////////// sites
268 $sites_title = count_english_warning($sites,'site');
269 $toggle=new PlekitToggle('sites',$sites_title,
270 array('visible'=>get_arg('show_sites')));
273 if (empty( $sites ) ) {
274 plc_warning('This user is not affiliated with a site !!');
276 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
278 $headers['Login_base']="string";
279 $headers['Name']="string";
280 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
281 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
282 $table=new PlekitTable ("person_sites",$headers,0,$table_options);
284 foreach( $sites as $site ) {
285 $site_name= $site['name'];
286 $site_id= $site['site_id'];
287 $login_base=$site['login_base'];
289 $table->cell ($login_base);
290 $table->cell (l_site_t($site_id,$site_name));
291 if ($can_manage_sites)
292 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
295 if ($can_manage_sites) {
296 $table->tfoot_start();
300 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
301 array('hfill'=>true,'align'=>'right'));
307 // NOTE: only admins can add users to different sites.
309 // get list of local sites that the person is not in
310 function get_site_id ($site) { return $site['site_id'];}
311 $person_site_ids=array_map("get_site_id",$sites);
312 if ($person_site_ids) {
313 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids, '-SORT'=>'name'), $site_columns);
315 $relevant_sites= $api->GetSites( array("peer_id"=>NULL, '-SORT'=>'name'), $site_columns);
317 // xxx cannot use onchange=submit() - would need to somehow pass action name
318 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
319 $selectors = array_map ("site_selector",$relevant_sites);
320 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
321 $form->submit_html("add-person-to-site","Add in site"),
322 array('hfill'=>true,'align'=>'right'));
329 //////////////////// roles
331 $toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles')));
334 if (! $roles) plc_warning ("This user has no role !");
336 $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
337 $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site );
339 $headers=array("Role"=>"string");
340 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
342 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
343 $table=new PlekitTable("person_roles",$headers,0,$table_options);
346 // construct array of role objs
348 for ($n=0; $n<count($roles); $n++) {
349 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
352 if ($role_objs) foreach ($role_objs as $role_obj) {
354 $table->cell($role_obj['name']);
355 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
359 // footers : the remove and add buttons
360 if ($can_manage_roles) {
363 $table->tfoot_start();
366 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
367 array('hfill'=>true,'align'=>'right'));
372 // compute the roles that can be added
374 // all roles, except 'node' that does not make sense for a person
375 $exclude_role_ids=array(50);
377 // all roles except admin and pi, and node to avoid confusing people
378 $exclude_role_ids=array(10,20,50);
379 $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
380 $roles_to_add = roles_except ($possible_roles,$role_ids);
381 if ( $roles_to_add ) {
382 $selectors=$form->role_selectors($roles_to_add);
384 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
385 // add a role : the button
386 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
387 $table->cell ($add_role_left_area . $add_role_right_area,
388 array('hfill'=>true,'align'=>'right'));
396 //////////////////////////////////////////////////////////// Tags
399 $tags=$api->GetPersonTags (array('person_id'=>$person_id));
400 function get_tagname ($tag) { return $tag['tagname'];}
401 // xxx looks like tech-only see an error here,
402 // might be that GetPersonTags is not accessible or something
403 $tagnames = array_map ("get_tagname",$tags);
405 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
406 array('bubble'=>'Inspect and set tags on that person',
407 'visible'=>get_arg('show_tags')));
410 $headers=array("Name"=>"string",
413 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
415 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
416 $table=new PlekitTable("person_tags",$headers,0,$table_options);
418 if ($tags) foreach ($tags as $tag) {
420 $table->cell(l_tag_obj($tag));
421 $table->cell($tag['value']);
422 // the remove checkbox
423 if (plc_is_admin()) $table->cell ($form->checkbox_html('person_tag_ids[]',$tag['person_tag_id']));
428 $table->tfoot_start();
432 $table->cell($form->submit_html("delete-person-tags","Remove Tags"),
433 // use the whole columns and right adjust
434 array('hfill'=>true,'align'=>'right'));
439 // get list of tag names in the person/* category
440 $all_tags= $api->GetTagTypes( array ("category"=>"person*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
441 // xxx cannot use onchange=submit() - would need to somehow pass action name
442 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
443 $selector=array_map("tag_selector",$all_tags);
444 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
445 $table->cell($form->text_html("value","",array('width'=>8)));
446 $table->cell($form->submit_html("set-tag-on-person","Set Tag"),array('columns'=>2,'align'=>'left'));
455 //////////////////////////////
457 $peers->block_end($peer_id);
459 //plekit_linetabs ($tabs,"bottom");
462 include 'plc_footer.php';