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_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'details.php';
22 require_once 'form.php';
23 require_once 'toggle.php';
25 // --------------------
26 // recognized URL arguments
27 $person_id=intval($_GET['id']);
29 plc_error('Malformed URL - id not set');
34 // Get all columns as we focus on only one entry
35 $persons= $api->GetPersons( array($person_id));
37 if (empty($persons)) {
38 drupal_set_message ("Person " . $person_id . " not found");
44 $enabled= $person['enabled'];
45 $first_name= $person['first_name'];
46 $last_name= $person['last_name'];
47 $email= $person['email'];
49 $phone= $person['phone'];
50 $title= $person['title'];
52 $peer_id=$person['peer_id'];
55 $role_ids= $person['role_ids'];
56 $roles= $person['roles'];
57 $site_ids= $person['site_ids'];
58 $slice_ids= $person['slice_ids'];
59 $key_ids= $person['key_ids'];
61 // gets more data from API calls
62 $site_columns=array( "site_id", "name", "login_base" );
63 $sites= $api->GetSites( $site_ids, $site_columns);
64 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
65 $keys= $api->GetKeys( $key_ids );
67 drupal_set_title("Details for account " . $first_name . " " . $last_name);
68 $local_peer = ! $peer_id;
70 $peers = new Peers ($api);
73 $site_id = $site_ids[0];
74 $is_my_account = plc_my_person_id() == $person_id;
75 $privileges = plc_is_admin () || ( plc_in_site($site_ids[0]) && plc_is_pi());
81 if (plc_is_admin() && ! $is_my_account && $local_peer)
82 $tabs['Become'] = array('method'=>'POST',
84 'values'=>array('action'=>'become-person',
85 'person_id'=>$person_id),
86 'bubble'=>"Become $first_name $last_name",
87 'confirm'=>"Are you sure you want to become $first_name $last_name");
89 if ($local_peer && $privileges)
91 $tabs['Disable'] = array ('method'=>'POST',
93 'values'=> array ('person_id'=>$person_id,
94 'action'=>'disable-person'),
95 'bubble'=>"Disable $first_name $last_name",
96 'confirm'=>"Are you sure you want to disable $first_name $last_name");
98 $tabs['Enable'] = array ('method'=>'POST',
100 'values'=> array ('person_id'=>$person_id,
101 'action'=>'enable-person'),
102 'bubble'=>"Enable $first_name $last_name",
103 'confirm'=>"Are you sure you want to enable $first_name $last_name");
106 if ($local_peer && $privileges && $local_peer)
107 $tabs['Delete'] = array ('method'=>'POST',
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','height'=>18);
120 plekit_linetabs($tabs);
122 $peers->block_start ($peer_id);
124 if ($local_peer && $privileges && ! $enabled )
125 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
127 $enabled_label="Yes";
128 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
130 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
132 $toggle = new PlekitToggle ('person',"Details",
133 array('bubble'=>'Display and modify details for that account',
134 'visible'=>get_arg('show_details',true)));
137 $details = new PlekitDetails($can_update);
139 $details->form_start(l_actions(),array("action"=>"update-person",
140 "person_id"=>$person_id));
144 $details->th_td("Title",$title,"title",array('width'=>10));
145 $details->th_td("First Name",$first_name,"first_name");
146 $details->th_td("Last Name",$last_name,"last_name");
147 $details->th_td(href("mailto:$email","Email"),$email,"email",array("width"=>30));
148 $details->th_td("Phone",$phone,"phone");
149 $details->th_td("URL",$url,"url",array('width'=>40));
150 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
152 // xxx need to check that this is working
154 $details->th_td("Password","","password1",array('input_type'=>'password'));
155 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
156 $details->tr_submit("submit","Update Account");
160 $details->th_td("Enabled",$enabled_label);
161 if ( ! $local_peer ) {
162 $details->th_td("Peer",$peers->peer_link($peer_id));
167 $details->form_end();
170 //////////////////// slices
172 $slices_title=count_english_warning($slices,'slice');
173 $toggle=new PlekitToggle ('slices',$slices_title,
174 array('visible'=>get_arg('show_slices',false)));
178 plc_warning ("User has no slice");
180 $headers=array('Slice name'=>'string');
182 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
183 if (count ($slices) <= $reasonable_page) {
184 $table_options['search_area']=false;
185 $table_options['pagesize_area']=false;
187 $table=new PlekitTable ("person_slices",$headers,1,$table_options);
190 foreach( $slices as $slice ) {
191 $slice_name= $slice['name'];
192 $slice_id= $slice['slice_id'];
194 $table->cell(l_slice_t($slice_id,$slice_name));
202 ////////////////////////////////////////
203 // we don't set 'action', but use the submit button name instead
204 $form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
207 //////////////////// keys
209 $keys_title = count_english_warning($keys,'key');
210 $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys',false)));
213 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
214 if ( empty( $key_ids ) ) {
215 plc_warning("This user has no known key");
218 $headers=array("Type"=>"string",
220 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
221 // table overall options
222 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
223 $table=new PlekitTable("person_keys",$headers,"1",$table_options);
226 if ($keys) foreach ($keys as $key) {
227 $key_id=$key['key_id'];
229 $table->cell ($key['key_type']);
230 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
231 if ($can_manage_keys)
232 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
235 // the footer area is used for displaying key-management buttons
236 // add the 'remove keys' button and key upload areas as the table footer
237 if ($can_manage_keys) {
238 $table->tfoot_start();
239 // no need to remove if there's no key
242 $table->cell($form->submit_html ("delete-keys","Remove keys"),
243 array('hfill'=>true,'align'=>'right'));
247 $table->cell($form->label_html("key","Upload new key")
248 . $form->file_html("key","upload",array('size'=>60))
249 . $form->submit_html("upload-key","Upload key"),
250 array('hfill'=>true,'align'=>'right'));
258 //////////////////// sites
260 $sites_title = count_english_warning($sites,'site');
261 $toggle=new PlekitToggle('sites',$sites_title,
262 array('visible'=>get_arg('show_sites',false)));
265 if (empty( $sites ) ) {
266 plc_warning('This user is not affiliated with a site !!');
268 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
270 $headers['Login_base']="string";
271 $headers['Name']="string";
272 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
273 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
274 $table=new PlekitTable ("person_sites",$headers,0,$table_options);
276 foreach( $sites as $site ) {
277 $site_name= $site['name'];
278 $site_id= $site['site_id'];
279 $login_base=$site['login_base'];
281 $table->cell ($login_base);
282 $table->cell (l_site_t($site_id,$site_name));
283 if ($can_manage_sites)
284 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
287 if ($can_manage_sites) {
288 $table->tfoot_start();
292 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
293 array('hfill'=>true,'align'=>'right'));
299 // get list of local sites that the person is not in
300 function get_site_id ($site) { return $site['site_id'];}
301 $person_site_ids=array_map("get_site_id",$sites);
302 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids, '-SORT'=>'name'), $site_columns);
303 // xxx cannot use onchange=submit() - would need to somehow pass action name
304 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
305 $selectors = array_map ("site_selector",$relevant_sites);
306 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
307 $form->submit_html("add-person-to-site","Add in site"),
308 array('hfill'=>true,'align'=>'right'));
314 //////////////////// roles
316 $toggle=new PlekitToggle ('roles',count_english($roles,"role"),array('visible'=>get_arg('show_roles',false)));
319 if (! $roles) plc_warning ("This user has no role !");
321 $is_pi_of_the_site = ( plc_in_site($site_ids[0]) && plc_is_pi() );
322 $can_manage_roles= ( ($local_peer && plc_is_admin()) || $is_pi_of_the_site );
323 $table_options=array("search_area"=>false,"notes_area"=>false);
325 $headers=array("Role"=>"string");
326 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
328 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
329 $table=new PlekitTable("person_roles",$headers,0,$table_options);
332 // construct array of role objs
334 for ($n=0; $n<count($roles); $n++) {
335 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
338 if ($role_objs) foreach ($role_objs as $role_obj) {
340 $table->cell($role_obj['name']);
341 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
345 // footers : the remove and add buttons
346 if ($can_manage_roles) {
349 $table->tfoot_start();
352 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
353 array('hfill'=>true,'align'=>'right'));
358 // compute the roles that can be added
361 $exclude_role_ids=array();
363 // all roles except admin and pi
364 $exclude_role_ids=array(10,20);
365 $possible_roles = roles_except($api->GetRoles(),$exclude_role_ids);
366 $roles_to_add = roles_except ($possible_roles,$role_ids);
367 if ( $roles_to_add ) {
368 $selectors=$form->role_selectors($roles_to_add);
370 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
371 // add a role : the button
372 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
373 $table->cell ($add_role_left_area . $add_role_right_area,
374 array('hfill'=>true,'align'=>'right'));
382 //////////////////////////////
384 $peers->block_end($peer_id);
386 //plekit_linetabs ($tabs,"bottom");
389 include 'plc_footer.php';