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 $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 $site_columns=array( "site_id", "name", "login_base" );
61 $sites= $api->GetSites( $site_ids, $site_columns);
62 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
63 $keys= $api->GetKeys( $key_ids );
65 drupal_set_title("Details for account " . $first_name . " " . $last_name);
66 $local_peer = ! $peer_id;
68 $peers = new Peers ($api);
71 $site_id = $site_ids[0];
72 $is_my_account = plc_my_person_id() == $person_id;
73 $privileges = plc_is_admin () || ( plc_in_site($site_ids[0]) && plc_is_pi());
79 if (plc_is_admin() && ! $is_my_account && $local_peer && $enabled)
80 $tabs['Become'] = array('method'=>'POST',
82 'values'=>array('action'=>'become-person',
83 'person_id'=>$person_id),
84 'bubble'=>"Become $first_name $last_name",
85 'confirm'=>"Are you sure you want to become $first_name $last_name");
87 if ($local_peer && $privileges && ! $is_my_account)
89 $tabs['Disable'] = array ('method'=>'POST',
91 'values'=> array ('person_id'=>$person_id,
92 'action'=>'disable-person'),
93 'bubble'=>"Disable $first_name $last_name",
94 'confirm'=>"Are you sure you want to disable $first_name $last_name");
96 $tabs['Enable'] = array ('method'=>'POST',
98 'values'=> array ('person_id'=>$person_id,
99 'action'=>'enable-person'),
100 'bubble'=>"Enable $first_name $last_name",
101 'confirm'=>"Are you sure you want to enable $first_name $last_name");
104 if ($local_peer && $privileges && $local_peer && ! $is_my_account)
105 $tabs['Delete'] = array ('method'=>'POST',
107 'values'=> array ('person_id'=>$person_id,
108 'action'=>'delete-person'),
109 'bubble'=>"Delete $first_name $last_name",
110 'confirm'=>"Are you sure to delete $first_name $last_name");
111 // events for that person
113 $tabs['Events'] = array('url'=>l_events(),
114 'values'=>array('type'=>'Person','person'=>$person_id),
115 'bubble'=>"Events about $first_name $last_name",
116 'image'=>'/planetlab/icons/event.png','height'=>18);
118 plekit_linetabs($tabs);
120 $peers->block_start ($peer_id);
122 if ($local_peer && $privileges && ! $enabled )
123 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
125 $enabled_label="Yes";
126 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
128 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
130 $toggle = new PlekitToggle ('person',"Details",
131 array('bubble'=>'Display and modify details for that account',
132 'visible'=>get_arg('show_details',true)));
135 $details = new PlekitDetails($can_update);
137 $details->form_start(l_actions(),array("action"=>"update-person",
138 "person_id"=>$person_id));
142 $details->th_td("Title",$title,"title",array('width'=>10));
143 $details->th_td("First Name",$first_name,"first_name");
144 $details->th_td("Last Name",$last_name,"last_name");
145 $details->th_td(href("mailto:$email","Email"),$email,"email",array("width"=>30));
146 $details->th_td("Phone",$phone,"phone");
147 $details->th_td("URL",$url,"url",array('width'=>40));
148 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
150 // xxx need to check that this is working
152 $details->th_td("Password","","password1",array('input_type'=>'password'));
153 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
154 $details->tr_submit("submit","Update Account");
158 $details->th_td("Enabled",$enabled_label);
159 if ( ! $local_peer ) {
160 $details->th_td("Peer",$peers->peer_link($peer_id));
165 $details->form_end();
168 //////////////////// slices
170 $slices_title=count_english_warning($slices,'slice');
171 $toggle=new PlekitToggle ('slices',$slices_title,
172 array('visible'=>get_arg('show_slices',false)));
176 plc_warning ("User has no slice");
178 $headers=array('Slice name'=>'string');
180 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
181 if (count ($slices) <= $reasonable_page) {
182 $table_options['search_area']=false;
183 $table_options['pagesize_area']=false;
185 $table=new PlekitTable ("person_slices",$headers,1,$table_options);
188 foreach( $slices as $slice ) {
189 $slice_name= $slice['name'];
190 $slice_id= $slice['slice_id'];
192 $table->cell(l_slice_t($slice_id,$slice_name));
200 ////////////////////////////////////////
201 // we don't set 'action', but use the submit button name instead
202 $form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
205 //////////////////// keys
207 $keys_title = count_english_warning($keys,'key');
208 $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys',false)));
211 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
212 if ( empty( $key_ids ) ) {
213 plc_warning("This user has no known key");
216 $headers=array("Type"=>"string",
218 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
219 // table overall options
220 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
221 $table=new PlekitTable("person_keys",$headers,"1",$table_options);
224 if ($keys) foreach ($keys as $key) {
225 $key_id=$key['key_id'];
227 $table->cell ($key['key_type']);
228 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
229 if ($can_manage_keys)
230 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
233 // the footer area is used for displaying key-management buttons
234 // add the 'remove keys' button and key upload areas as the table footer
235 if ($can_manage_keys) {
236 $table->tfoot_start();
237 // no need to remove if there's no key
240 $table->cell($form->submit_html ("delete-keys","Remove keys"),
241 array('hfill'=>true,'align'=>'right'));
245 $table->cell($form->label_html("key","Upload new key")
246 . $form->file_html("key","upload",array('size'=>60))
247 . $form->submit_html("upload-key","Upload key"),
248 array('hfill'=>true,'align'=>'right'));
256 //////////////////// sites
258 $sites_title = count_english_warning($sites,'site');
259 $toggle=new PlekitToggle('sites',$sites_title,
260 array('visible'=>get_arg('show_sites',false)));
263 if (empty( $sites ) ) {
264 plc_warning('This user is not affiliated with a site !!');
266 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
268 $headers['Login_base']="string";
269 $headers['Name']="string";
270 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
271 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
272 $table=new PlekitTable ("person_sites",$headers,0,$table_options);
274 foreach( $sites as $site ) {
275 $site_name= $site['name'];
276 $site_id= $site['site_id'];
277 $login_base=$site['login_base'];
279 $table->cell ($login_base);
280 $table->cell (l_site_t($site_id,$site_name));
281 if ($can_manage_sites)
282 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
285 if ($can_manage_sites) {
286 $table->tfoot_start();
290 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
291 array('hfill'=>true,'align'=>'right'));
297 // get list of local sites that the person is not in
298 function get_site_id ($site) { return $site['site_id'];}
299 $person_site_ids=array_map("get_site_id",$sites);
300 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids, '-SORT'=>'name'), $site_columns);
301 // xxx cannot use onchange=submit() - would need to somehow pass action name
302 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
303 $selectors = array_map ("site_selector",$relevant_sites);
304 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
305 $form->submit_html("add-person-to-site","Add in site"),
306 array('hfill'=>true,'align'=>'right'));
312 //////////////////// roles
314 $toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles',false)));
317 if (! $roles) plc_warning ("This user has no role !");
319 $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
320 $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site );
322 $headers=array("Role"=>"string");
323 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
325 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
326 $table=new PlekitTable("person_roles",$headers,0,$table_options);
329 // construct array of role objs
331 for ($n=0; $n<count($roles); $n++) {
332 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
335 if ($role_objs) foreach ($role_objs as $role_obj) {
337 $table->cell($role_obj['name']);
338 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
342 // footers : the remove and add buttons
343 if ($can_manage_roles) {
346 $table->tfoot_start();
349 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
350 array('hfill'=>true,'align'=>'right'));
355 // compute the roles that can be added
358 $exclude_role_ids=array();
360 // all roles except admin and pi
361 $exclude_role_ids=array(10,20);
362 $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
363 $roles_to_add = roles_except ($possible_roles,$role_ids);
364 if ( $roles_to_add ) {
365 $selectors=$form->role_selectors($roles_to_add);
367 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
368 // add a role : the button
369 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
370 $table->cell ($add_role_left_area . $add_role_right_area,
371 array('hfill'=>true,'align'=>'right'));
379 //////////////////////////////
381 $peers->block_end($peer_id);
383 //plekit_linetabs ($tabs,"bottom");
386 include 'plc_footer.php';