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" );
65 $sites= $api->GetSites( $site_ids, $site_columns);
66 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
67 $keys= $api->GetKeys( $key_ids );
69 drupal_set_title("Details for account " . $first_name . " " . $last_name);
70 $local_peer = ! $peer_id;
72 $peers = new Peers ($api);
75 $site_id = $site_ids[0];
76 $is_my_account = plc_my_person_id() == $person_id;
77 $privileges = plc_is_admin () || ( plc_in_site($site_ids[0]) && plc_is_pi());
83 if (plc_is_admin() && ! $is_my_account && $local_peer && $enabled)
84 $tabs['Become'] = array('method'=>'POST',
86 'values'=>array('action'=>'become-person',
87 'person_id'=>$person_id),
88 'bubble'=>"Become $first_name $last_name",
89 'confirm'=>"Are you sure you want to become $first_name $last_name");
91 if ($local_peer && $privileges && ! $is_my_account)
93 $tabs['Disable'] = array ('method'=>'POST',
95 'values'=> array ('person_id'=>$person_id,
96 'action'=>'disable-person'),
97 'bubble'=>"Disable $first_name $last_name",
98 'confirm'=>"Are you sure you want to disable $first_name $last_name");
100 $tabs['Enable'] = array ('method'=>'POST',
102 'values'=> array ('person_id'=>$person_id,
103 'action'=>'enable-person'),
104 'bubble'=>"Enable $first_name $last_name",
105 'confirm'=>"Are you sure you want to enable $first_name $last_name");
108 if ($local_peer && $privileges && $local_peer && ! $is_my_account)
109 $tabs['Delete'] = array ('method'=>'POST',
111 'values'=> array ('person_id'=>$person_id,
112 'action'=>'delete-person'),
113 'bubble'=>"Delete $first_name $last_name",
114 'confirm'=>"Are you sure to delete $first_name $last_name");
115 // events for that person
117 $tabs['Events'] = array('url'=>l_events(),
118 'values'=>array('type'=>'Person','person'=>$person_id),
119 'bubble'=>"Events about $first_name $last_name",
120 'image'=>'/planetlab/icons/event.png','height'=>18);
122 plekit_linetabs($tabs);
124 $peers->block_start ($peer_id);
126 if ($local_peer && $privileges && ! $enabled )
127 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
129 $enabled_label="Yes";
130 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
132 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
134 $toggle = new PlekitToggle ('person',"Details",
135 array('bubble'=>'Display and modify details for that account',
136 'visible'=>get_arg('show_details')));
139 $details = new PlekitDetails($can_update);
141 $details->form_start(l_actions(),array("action"=>"update-person",
142 "person_id"=>$person_id));
146 $details->th_td("Title",$title,"title",array('width'=>10));
147 $details->th_td("First Name",$first_name,"first_name");
148 $details->th_td("Last Name",$last_name,"last_name");
149 $details->th_td(href("mailto:$email","Email"),$email,"email",array("width"=>30));
150 if ($hrn) $details->th_td("SFA hrn",$hrn);
151 else $details->tr("SFA hrn not set","center");
152 $details->th_td("Phone",$phone,"phone");
153 $details->th_td("URL",$url,"url",array('width'=>40));
154 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
156 // xxx need to check that this is working
158 $details->th_td("Password","","password1",array('input_type'=>'password'));
159 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
160 $details->tr_submit("submit","Update Account");
164 $details->th_td("Enabled",$enabled_label);
165 if ( ! $local_peer ) {
166 $details->th_td("Peer",$peers->peer_link($peer_id));
171 $details->form_end();
174 //////////////////// slices
176 $slices_title=count_english_warning($slices,'slice');
177 $toggle=new PlekitToggle ('slices',$slices_title,
178 array('visible'=>get_arg('show_slices')));
182 plc_warning ("User has no slice");
184 $headers=array('Slice name'=>'string');
186 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
187 if (count ($slices) <= $reasonable_page) {
188 $table_options['search_area']=false;
189 $table_options['pagesize_area']=false;
191 $table=new PlekitTable ("person_slices",$headers,1,$table_options);
194 foreach( $slices as $slice ) {
195 $slice_name= $slice['name'];
196 $slice_id= $slice['slice_id'];
198 $table->cell(l_slice_t($slice_id,$slice_name));
206 ////////////////////////////////////////
207 // we don't set 'action', but use the submit button name instead
208 $form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
211 //////////////////// keys
213 $keys_title = count_english_warning($keys,'key');
214 $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys')));
217 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
218 if ( empty( $key_ids ) ) {
219 plc_warning("This user has no known key");
222 $headers=array("Type"=>"string",
224 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
225 // table overall options
226 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
227 $table=new PlekitTable("person_keys",$headers,"1",$table_options);
230 if ($keys) foreach ($keys as $key) {
231 $key_id=$key['key_id'];
233 $table->cell ($key['key_type']);
234 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
235 if ($can_manage_keys)
236 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
239 // the footer area is used for displaying key-management buttons
240 // add the 'remove keys' button and key upload areas as the table footer
241 if ($can_manage_keys) {
242 $table->tfoot_start();
243 // no need to remove if there's no key
246 $table->cell($form->submit_html ("delete-keys","Remove keys"),
247 array('hfill'=>true,'align'=>'right'));
251 $table->cell($form->label_html("key","Upload new key")
252 . $form->file_html("key","upload",array('size'=>60))
253 . $form->submit_html("upload-key","Upload key"),
254 array('hfill'=>true,'align'=>'right'));
262 //////////////////// sites
264 $sites_title = count_english_warning($sites,'site');
265 $toggle=new PlekitToggle('sites',$sites_title,
266 array('visible'=>get_arg('show_sites')));
269 if (empty( $sites ) ) {
270 plc_warning('This user is not affiliated with a site !!');
272 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
274 $headers['Login_base']="string";
275 $headers['Name']="string";
276 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
277 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
278 $table=new PlekitTable ("person_sites",$headers,0,$table_options);
280 foreach( $sites as $site ) {
281 $site_name= $site['name'];
282 $site_id= $site['site_id'];
283 $login_base=$site['login_base'];
285 $table->cell ($login_base);
286 $table->cell (l_site_t($site_id,$site_name));
287 if ($can_manage_sites)
288 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
291 if ($can_manage_sites) {
292 $table->tfoot_start();
296 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
297 array('hfill'=>true,'align'=>'right'));
303 // NOTE: only admins can add users to different sites.
305 // get list of local sites that the person is not in
306 function get_site_id ($site) { return $site['site_id'];}
307 $person_site_ids=array_map("get_site_id",$sites);
308 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids, '-SORT'=>'name'), $site_columns);
309 // xxx cannot use onchange=submit() - would need to somehow pass action name
310 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
311 $selectors = array_map ("site_selector",$relevant_sites);
312 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
313 $form->submit_html("add-person-to-site","Add in site"),
314 array('hfill'=>true,'align'=>'right'));
321 //////////////////// roles
323 $toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles')));
326 if (! $roles) plc_warning ("This user has no role !");
328 $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
329 $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site );
331 $headers=array("Role"=>"string");
332 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
334 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
335 $table=new PlekitTable("person_roles",$headers,0,$table_options);
338 // construct array of role objs
340 for ($n=0; $n<count($roles); $n++) {
341 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
344 if ($role_objs) foreach ($role_objs as $role_obj) {
346 $table->cell($role_obj['name']);
347 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
351 // footers : the remove and add buttons
352 if ($can_manage_roles) {
355 $table->tfoot_start();
358 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
359 array('hfill'=>true,'align'=>'right'));
364 // compute the roles that can be added
366 // all roles, except 'node' that does not make sense for a person
367 $exclude_role_ids=array(50);
369 // all roles except admin and pi, and node to avoid confusing people
370 $exclude_role_ids=array(10,20,50);
371 $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
372 $roles_to_add = roles_except ($possible_roles,$role_ids);
373 if ( $roles_to_add ) {
374 $selectors=$form->role_selectors($roles_to_add);
376 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
377 // add a role : the button
378 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
379 $table->cell ($add_role_left_area . $add_role_right_area,
380 array('hfill'=>true,'align'=>'right'));
388 //////////////////////////////////////////////////////////// Tags
391 $tags=$api->GetPersonTags (array('person_id'=>$person_id));
392 function get_tagname ($tag) { return $tag['tagname'];}
393 // xxx looks like tech-only see an error here,
394 // might be that GetPersonTags is not accessible or something
395 $tagnames = array_map ("get_tagname",$tags);
397 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
398 array('bubble'=>'Inspect and set tags on that person',
399 'visible'=>get_arg('show_tags')));
402 $headers=array("Name"=>"string",
405 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
407 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
408 $table=new PlekitTable("person_tags",$headers,0,$table_options);
410 if ($tags) foreach ($tags as $tag) {
412 $table->cell(l_tag_obj($tag));
413 $table->cell($tag['value']);
414 // the remove checkbox
415 if (plc_is_admin()) $table->cell ($form->checkbox_html('person_tag_ids[]',$tag['person_tag_id']));
420 $table->tfoot_start();
424 $table->cell($form->submit_html("delete-person-tags","Remove Tags"),
425 // use the whole columns and right adjust
426 array('hfill'=>true,'align'=>'right'));
431 // get list of tag names in the person/* category
432 $all_tags= $api->GetTagTypes( array ("category"=>"person*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
433 // xxx cannot use onchange=submit() - would need to somehow pass action name
434 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
435 $selector=array_map("tag_selector",$all_tags);
436 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
437 $table->cell($form->text_html("value","",array('width'=>8)));
438 $table->cell($form->submit_html("set-tag-on-person","Set Tag"),array('columns'=>2,'align'=>'left'));
447 //////////////////////////////
449 $peers->block_end($peer_id);
451 //plekit_linetabs ($tabs,"bottom");
454 include 'plc_footer.php';