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);
72 $is_my_account = plc_my_person_id() == $person_id;
73 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
76 $tabs []= tab_persons();
79 if ($local_peer && $privileges)
81 $tabs['Disable'] = array ('method'=>'POST',
83 'values'=> array ('person_id'=>$person_id,
84 'action'=>'disable-person'),
85 'bubble'=>"Disable $first_name $last_name",
86 'confirm'=>"Are you sure you want to disable $first_name $last_name");
88 $tabs['Enable'] = array ('method'=>'POST',
90 'values'=> array ('person_id'=>$person_id,
91 'action'=>'enable-person'),
92 'bubble'=>"Enable $first_name $last_name",
93 'confirm'=>"Are you sure you want to enable $first_name $last_name");
96 if (plc_is_admin() && ! $is_my_account && $local_peer)
97 $tabs['Become'] = array('method'=>'POST',
99 'values'=>array('action'=>'become-person',
100 'person_id'=>$person_id),
101 'bubble'=>"Become $first_name $last_name",
102 'confirm'=>"Are you sure you want to su $first_name $last_name");
105 if ($local_peer && $privileges && $local_peer)
106 $tabs['Delete'] = array ('method'=>'POST',
108 'values'=> array ('person_id'=>$person_id,
109 'action'=>'delete-person'),
110 'bubble'=>"Delete $first_name $last_name",
111 'confirm'=>"Are you sure to delete $first_name $last_name");
112 // events for that person
114 $tabs['Events'] = array('url'=>l_events(),
115 'values'=>array('type'=>'Person','person'=>$person_id),
116 'bubble'=>"Events about $first_name $last_name",
117 'image'=>'/planetlab/icons/event.png','height'=>18);
119 plekit_linetabs($tabs);
121 $peers->block_start ($peer_id);
123 if ($local_peer && $privileges && ! $enabled )
124 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
126 $enabled_label="Yes";
127 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
129 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
131 $toggle = new PlekitToggle ('person',"Details",
132 array('bubble'=>'Display and modify details for that account',
133 'visible'=>get_arg('show_details',true)));
136 $details = new PlekitDetails($can_update);
138 $details->form_start(l_actions(),array("action"=>"update-person",
139 "person_id"=>$person_id));
143 $details->th_td("Title",$title,"title",array('width'=>5));
144 $details->th_td("First Name",$first_name,"first_name");
145 $details->th_td("Last Name",$last_name,"last_name");
146 $details->th_td(href("mailto:$email","Email"),$email,"email");
147 $details->th_td("Phone",$phone,"phone");
148 $details->th_td("URL",$url,"url",array('width'=>40));
149 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
151 // xxx need to check that this is working
153 $details->th_td("Password","","password1",array('input_type'=>'password'));
154 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
155 $details->tr_submit("submit","Update Account");
159 $details->th_td("Enabled",$enabled_label);
160 if ( ! $local_peer ) {
161 $details->th_td("Peer",$peers->peer_link($peer_id));
166 $details->form_end();
169 //////////////////// slices
171 $slices_title=count_english_warning($slices,'slice');
172 $toggle=new PlekitToggle ('slices',$slices_title,
173 array('visible'=>get_arg('show_slices',false)));
177 plc_warning ("User has no slice");
179 $headers=array('Slice name'=>'string');
181 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
182 if (count ($slices) <= $reasonable_page) {
183 $table_options['search_area']=false;
184 $table_options['pagesize_area']=false;
186 $table=new PlekitTable ("person_slices",$headers,1,$table_options);
189 foreach( $slices as $slice ) {
190 $slice_name= $slice['name'];
191 $slice_id= $slice['slice_id'];
193 $table->cell(l_slice_t($slice_id,$slice_name));
201 ////////////////////////////////////////
202 // we don't set 'action', but use the submit button name instead
203 $form=new PlekitForm(l_actions(), array("person_id"=>$person_id));
206 //////////////////// keys
208 $keys_title = count_english_warning($keys,'key');
209 $toggle=new PlekitToggle ('keys',$keys_title,array('visible'=>get_arg('show_keys',false)));
212 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
213 if ( empty( $key_ids ) ) {
214 plc_warning("This user has no known key");
217 $headers=array("Type"=>"string",
219 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
220 // table overall options
221 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
222 $table=new PlekitTable("person_keys",$headers,"1",$table_options);
225 if ($keys) foreach ($keys as $key) {
226 $key_id=$key['key_id'];
228 $table->cell ($key['key_type']);
229 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
230 if ($can_manage_keys)
231 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
234 // the footer area is used for displaying key-management buttons
235 // add the 'remove keys' button and key upload areas as the table footer
236 if ($can_manage_keys) {
237 $table->tfoot_start();
238 // no need to remove if there's no key
241 $table->cell($form->submit_html ("delete-keys","Remove keys"),
242 array('hfill'=>true,'align'=>'right'));
246 $table->cell($form->label_html("key","Upload new key")
247 . $form->file_html("key","upload",array('size'=>60))
248 . $form->submit_html("upload-key","Upload key"),
249 array('hfill'=>true,'align'=>'right'));
257 //////////////////// sites
259 $sites_title = count_english_warning($sites,'site');
260 $toggle=new PlekitToggle('sites',$sites_title,
261 array('visible'=>get_arg('show_sites',false)));
264 if (empty( $sites ) ) {
265 plc_warning('This user is not affiliated with a site !!');
267 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
269 $headers['Login_base']="string";
270 $headers['Name']="string";
271 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
272 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
273 $table=new PlekitTable ("person_sites",$headers,0,$table_options);
275 foreach( $sites as $site ) {
276 $site_name= $site['name'];
277 $site_id= $site['site_id'];
278 $login_base=$site['login_base'];
280 $table->cell ($login_base);
281 $table->cell (l_site_t($site_id,$site_name));
282 if ($can_manage_sites)
283 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
286 if ($can_manage_sites) {
287 $table->tfoot_start();
291 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
292 array('hfill'=>true,'align'=>'right'));
298 // get list of local sites that the person is not in
299 function get_site_id ($site) { return $site['site_id'];}
300 $person_site_ids=array_map("get_site_id",$sites);
301 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
302 // xxx cannot use onchange=submit() - would need to somehow pass action name
303 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
304 $selectors = array_map ("site_selector",$relevant_sites);
305 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
306 $form->submit_html("add-person-to-site","Add in site"),
307 array('hfill'=>true,'align'=>'right'));
313 //////////////////// roles
315 $toggle=new PlekitToggle ('roles','Roles',array('visible'=>get_arg('show_roles',false)));
318 if (! $roles) plc_warning ("This user has no role !");
320 $can_manage_roles= ($local_peer && plc_is_admin());
321 $table_options=array("search_area"=>false,"notes_area"=>false);
323 $headers=array("Role"=>"string");
324 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
326 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
327 $table=new PlekitTable("person_roles",$headers,0,$table_options);
330 // construct array of role objs
332 for ($n=0; $n<count($roles); $n++) {
333 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
336 if ($role_objs) foreach ($role_objs as $role_obj) {
338 $table->cell($role_obj['name']);
339 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
343 // footers : the remove and add buttons
344 if ($can_manage_roles) {
345 $table->tfoot_start();
348 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
349 array('hfill'=>true,'align'=>'right'));
354 $selectors=$form->role_selectors_excluding($api,$role_ids);
355 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
356 // add a role : the button
357 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
358 $table->cell ($add_role_left_area . $add_role_right_area,
359 array('hfill'=>true,'align'=>'right'));
366 //////////////////////////////
368 $peers->block_end($peer_id);
370 //plekit_linetabs ($tabs,"bottom");
373 include 'plc_footer.php';