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)
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)
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);
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;
130 $details = new PlcDetails($can_update);
132 $details->form_start(l_actions(),array("action"=>"update-person",
133 "person_id"=>$person_id));
137 $details->th_td("Title",$title,"title",array('width'=>5));
138 $details->th_td("First Name",$first_name,"first_name");
139 $details->th_td("Last Name",$last_name,"last_name");
140 $details->th_td(href("mailto:$email","Email"),$email,"email");
141 $details->th_td("Phone",$phone,"phone");
142 $details->th_td("URL",$url,"url",array('width'=>40));
143 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
145 // xxx need to check that this is working
147 $details->th_td("Password","","password1",array('input_type'=>'password'));
148 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
149 $details->tr_submit("submit","Update Account");
153 $details->th_td("Enabled",$enabled_label);
154 if ( ! $local_peer ) {
155 $details->th_td("Peer",$peers->peer_link($peer_id));
160 $details->form_end();
162 //////////////////// slices
163 $toggle=new PlcToggle ('slices','Slices',array('trigger-tagname'=>'h2'));
167 plc_warning ("User has no slice");
169 $headers=array('Slice name'=>'string');
171 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
172 if (count ($slices) <= $reasonable_page) {
173 $table_options['search_area']=false;
174 $table_options['pagesize_area']=false;
176 $table=new PlcTable ("person_slices",$headers,1,$table_options);
179 foreach( $slices as $slice ) {
180 $slice_name= $slice['name'];
181 $slice_id= $slice['slice_id'];
183 $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 $toggle=new PlcToggle ('keys',"Keys",array('trigger-tagname'=>'h2'));
198 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
199 if ( empty( $key_ids ) ) {
200 plc_warning("This user has no known key");
203 $headers=array("Type"=>"string",
205 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
206 // table overall options
207 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
208 $table=new PlcTable("person_keys",$headers,"1",$table_options);
211 if ($keys) foreach ($keys as $key) {
212 $key_id=$key['key_id'];
214 $table->cell ($key['key_type']);
215 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
216 if ($can_manage_keys)
217 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
220 // the footer area is used for displaying key-management buttons
221 // add the 'remove keys' button and key upload areas as the table footer
222 if ($can_manage_keys) {
223 $table->tfoot_start();
224 // no need to remove if there's no key
227 $table->cell($form->submit_html ("delete-keys","Remove keys"),
228 $table->columns(),"right");
232 $table->cell($form->label_html("key","Upload new key")
233 . $form->file_html("key","upload",array('size'=>60))
234 . $form->submit_html("upload-key","Upload key"),
235 $table->columns(),"right");
242 //////////////////// sites
243 $toggle=new PlcToggle('sites','Sites',array('trigger-tagname'=>'h2'));
246 if (empty( $sites ) ) {
247 plc_warning('This user is not affiliated with a site !!');
249 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
251 $headers['Login_base']="string";
252 $headers['Name']="string";
253 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
254 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
255 $table=new PlcTable ("person_sites",$headers,0,$table_options);
257 foreach( $sites as $site ) {
258 $site_name= $site['name'];
259 $site_id= $site['site_id'];
260 $login_base=$site['login_base'];
262 $table->cell ($login_base);
263 $table->cell (l_site_t($site_id,$site_name));
264 if ($can_manage_sites)
265 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
268 if ($can_manage_sites) {
269 $table->tfoot_start();
273 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
274 $table->columns(),"right");
280 // get list of local sites that the person is not in
281 function get_site_id ($site) { return $site['site_id'];}
282 $person_site_ids=array_map("get_site_id",$sites);
283 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
284 // xxx cannot use onchange=submit() - would need to somehow pass action name
285 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
286 $selectors = array_map ("site_selector",$relevant_sites);
287 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
288 $form->submit_html("add-person-to-site","Add in site"),
289 $table->columns(),"right");
295 //////////////////// roles
296 $toggle=new PlcToggle ('roles','Roles',array('trigger-tagname'=>'h2'));
299 if (! $roles) plc_warning ("This user has no role !");
301 $can_manage_roles= ($local_peer && plc_is_admin());
302 $table_options=array("search_area"=>false,"notes_area"=>false);
304 $headers=array("Role"=>"string");
305 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
307 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
308 $table=new PlcTable("person_roles",$headers,0,$table_options);
311 // construct array of role objs
313 for ($n=0; $n<count($roles); $n++) {
314 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
317 if ($role_objs) foreach ($role_objs as $role_obj) {
319 $table->cell($role_obj['name']);
320 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
324 // footers : the remove and add buttons
325 if ($can_manage_roles) {
326 $table->tfoot_start();
329 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
330 $table->columns(),"right");
335 $selectors=$form->role_selectors_excluding($api,$role_ids);
336 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
337 // add a role : the button
338 $add_role_right_area=$form->submit_html("add-role-to-person",array('label'=>"Add role"));
339 $table->cell ($add_role_left_area . $add_role_right_area,
340 $table->columns(),"right");
346 //////////////////////////////
348 $peers->block_end($peer_id);
350 //plc_tabs ($tabs,"bottom");
353 include 'plc_footer.php';