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 'plc_minitabs.php';
20 require_once 'plc_tables.php';
21 require_once 'plc_details.php';
22 require_once 'plc_forms.php';
24 // --------------------
25 // recognized URL arguments
26 $person_id=intval($_GET['id']);
28 plc_error('Malformed URL - id not set');
33 // Get all columns as we focus on only one entry
34 $persons= $api->GetPersons( array($person_id));
36 if (empty($persons)) {
37 drupal_set_message ("Person " . $person_id . " not found");
43 $enabled= $person['enabled'];
44 $first_name= $person['first_name'];
45 $last_name= $person['last_name'];
46 $email= $person['email'];
48 $phone= $person['phone'];
49 $title= $person['title'];
51 $peer_id=$person['peer_id'];
54 $role_ids= $person['role_ids'];
55 $roles= $person['roles'];
56 $site_ids= $person['site_ids'];
57 $slice_ids= $person['slice_ids'];
58 $key_ids= $person['key_ids'];
60 // gets more data from API calls
61 $site_columns=array( "site_id", "name", "login_base" );
62 $sites= $api->GetSites( $site_ids, $site_columns);
63 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
64 $keys= $api->GetKeys( $key_ids );
66 drupal_set_title("Details for account " . $first_name . " " . $last_name);
67 $local_peer = ! $peer_id;
69 $peers = new Peers ($api);
71 $is_my_account = plc_my_person_id() == $person_id;
72 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
77 if ($local_peer && $privileges)
79 $tabs['Disable'] = array ('method'=>'POST',
81 'values'=> array ('person_id'=>$person_id,
82 'action'=>'disable-person'),
83 'bubble'=>"Disable $first_name $last_name",
84 'confirm'=>"Are you sure you want to disable $first_name $last_name");
86 $tabs['Enable'] = array ('method'=>'POST',
88 'values'=> array ('person_id'=>$person_id,
89 'action'=>'enable-person'),
90 'bubble'=>"Enable $first_name $last_name",
91 'confirm'=>"Are you sure you want to enable $first_name $last_name");
94 if (plc_is_admin() && ! $is_my_account)
95 $tabs['Become'] = array('method'=>'POST',
97 'values'=>array('action'=>'become-person',
98 'person_id'=>$person_id),
99 'bubble'=>"Become $first_name $last_name",
100 'confirm'=>"Are you sure you want to su $first_name $last_name");
103 if ($local_peer && $privileges)
104 $tabs['Delete'] = array ('method'=>'POST',
106 'values'=> array ('person_id'=>$person_id,
107 'action'=>'delete-person'),
108 'bubble'=>"Delete $first_name $last_name",
109 'confirm'=>"Are you sure to delete $first_name $last_name");
110 // events for that person
112 $tabs['Events'] = array('url'=>l_events(),
113 'values'=>array('type'=>'Person','person'=>$person_id),
114 'bubble'=>"Events about $first_name $last_name",
115 'image'=>'/planetlab/icons/event.png','height'=>18);
118 $tabs['All Users'] = array ('url'=>l_persons(),
119 'bubble'=>'Back to the Users page');
123 $peers->block_start ($peer_id);
125 if ($local_peer && $privileges && ! $enabled )
126 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
128 $enabled_label="Yes";
129 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
131 $can_update = (plc_is_admin() && $local_peer) || $is_my_account;
132 $details = new PlcDetails($can_update);
134 $details->form_start(l_actions(),array("action"=>"update-person",
135 "person_id"=>$person_id));
139 $details->th_td("Title",$title,"title",array('width'=>5));
140 $details->th_td("First Name",$first_name,"first_name");
141 $details->th_td("Last Name",$last_name,"last_name");
142 $details->th_td(href("mailto:$email","Email"),$email,"email");
143 $details->th_td("Phone",$phone,"phone");
144 $details->th_td("URL",$url,"url",array('width'=>40));
145 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
147 // xxx need to check that this is working
149 $details->th_td("Password","","password1",array('input_type'=>'password'));
150 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
151 $details->tr_submit("submit","Update Account");
155 $details->th_td("Enabled",$enabled_label);
156 if ( ! $local_peer ) {
157 $details->th_td("Peer",$peers->peer_link($peer_id));
162 $details->form_end();
164 //////////////////// slices
165 plc_section('Slices');
168 plc_warning ("User has no slice");
170 $headers=array('Slice name'=>'string');
172 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
173 if (count ($slices) <= $reasonable_page) {
174 $table_options['search_area']=false;
175 $table_options['pagesize_area']=false;
177 $table=new PlcTable ("person_slices",$headers,1,$table_options);
180 foreach( $slices as $slice ) {
181 $slice_name= $slice['name'];
182 $slice_id= $slice['slice_id'];
184 $table->cell(l_slice_t($slice_id,$slice_name));
190 // we don't set 'action', but use the submit button name instead
191 $form=new PlcForm(l_actions(), array("person_id"=>$person_id));
194 //////////////////// keys
195 plc_section ("Keys");
197 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
198 if ( empty( $key_ids ) ) {
199 plc_warning("This user has no known key");
202 $headers=array("Type"=>"string",
204 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
205 // table overall options
206 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
207 $table=new PlcTable("person_keys",$headers,"1",$table_options);
210 if ($keys) foreach ($keys as $key) {
211 $key_id=$key['key_id'];
213 $table->cell ($key['key_type']);
214 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
215 if ($can_manage_keys)
216 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
219 // the footer area is used for displaying key-management buttons
220 // add the 'remove keys' button and key upload areas as the table footer
221 if ($can_manage_keys) {
222 $table->tfoot_start();
223 // no need to remove if there's no key
226 $table->cell($form->submit_html ("delete-keys","Remove keys"),
227 $table->columns(),"right");
231 $table->cell($form->label_html("key","Upload new key")
232 . $form->file_html("key",60)
233 . $form->submit_html("upload-key","Upload key"),
234 $table->columns(),"right");
240 //////////////////// sites
241 plc_section('Sites');
243 if (empty( $sites ) ) {
244 plc_warning('This user is not affiliated with a site !!');
246 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
248 $headers['Login_base']="string";
249 $headers['Name']="string";
250 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
251 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
252 $table=new PlcTable ("person_sites",$headers,0,$table_options);
254 foreach( $sites as $site ) {
255 $site_name= $site['name'];
256 $site_id= $site['site_id'];
257 $login_base=$site['login_base'];
259 $table->cell ($login_base);
260 $table->cell (l_site_t($site_id,$site_name));
261 if ($can_manage_sites)
262 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
265 if ($can_manage_sites) {
266 $table->tfoot_start();
270 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
271 $table->columns(),"right");
277 // get list of local sites that the person is not in
278 function get_site_id ($site) { return $site['site_id'];}
279 $person_site_ids=array_map("get_site_id",$sites);
280 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
281 // xxx cannot use onchange=submit() - would need to somehow pass action name
282 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
283 $selectors = array_map ("site_selector",$relevant_sites);
284 $table->cell ($form->select_html("site_id",$selectors,"Choose a site to add").
285 $form->submit_html("add-person-to-site","Add in site"),
286 $table->columns(),"right");
291 //////////////////// roles
292 plc_section("Roles");
293 if (! $roles) plc_warning ("This user has no role !");
295 $can_manage_roles= ($local_peer && plc_is_admin());
296 $table_options=array("search_area"=>false,"notes_area"=>false);
298 $headers=array("Role"=>"string");
299 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
301 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
302 $table=new PlcTable("person_roles",$headers,0,$table_options);
305 // construct array of role objs
307 for ($n=0; $n<count($roles); $n++) {
308 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
311 if ($role_objs) foreach ($role_objs as $role_obj) {
313 $table->cell($role_obj['name']);
314 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
318 // footers : the remove and add buttons
319 if ($can_manage_roles) {
320 $table->tfoot_start();
323 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
324 $table->columns(),"right");
329 $selectors=$form->role_selectors_excluding($api,$role_ids);
330 $add_role_left_area=$form->select_html("role_id",$selectors,"Choose role");
331 // add a role : the button
332 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
333 $table->cell ($add_role_left_area . $add_role_right_area,
334 $table->columns(),"right");
339 //////////////////////////////
341 $peers->block_end($peer_id);
344 include 'plc_footer.php';