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());
75 $tabs []= tab_persons();
78 if ($local_peer && $privileges)
80 $tabs['Disable'] = array ('method'=>'POST',
82 'values'=> array ('person_id'=>$person_id,
83 'action'=>'disable-person'),
84 'bubble'=>"Disable $first_name $last_name",
85 'confirm'=>"Are you sure you want to disable $first_name $last_name");
87 $tabs['Enable'] = array ('method'=>'POST',
89 'values'=> array ('person_id'=>$person_id,
90 'action'=>'enable-person'),
91 'bubble'=>"Enable $first_name $last_name",
92 'confirm'=>"Are you sure you want to enable $first_name $last_name");
95 if (plc_is_admin() && ! $is_my_account)
96 $tabs['Become'] = array('method'=>'POST',
98 'values'=>array('action'=>'become-person',
99 'person_id'=>$person_id),
100 'bubble'=>"Become $first_name $last_name",
101 'confirm'=>"Are you sure you want to su $first_name $last_name");
104 if ($local_peer && $privileges)
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);
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;
129 $details = new PlcDetails($can_update);
131 $details->form_start(l_actions(),array("action"=>"update-person",
132 "person_id"=>$person_id));
136 $details->th_td("Title",$title,"title",array('width'=>5));
137 $details->th_td("First Name",$first_name,"first_name");
138 $details->th_td("Last Name",$last_name,"last_name");
139 $details->th_td(href("mailto:$email","Email"),$email,"email");
140 $details->th_td("Phone",$phone,"phone");
141 $details->th_td("URL",$url,"url",array('width'=>40));
142 $details->th_td("Bio",$bio,"bio",array('input_type'=>'textarea','height'=>4));
144 // xxx need to check that this is working
146 $details->th_td("Password","","password1",array('input_type'=>'password'));
147 $details->th_td("Repeat","","password2",array('input_type'=>'password'));
148 $details->tr_submit("submit","Update Account");
152 $details->th_td("Enabled",$enabled_label);
153 if ( ! $local_peer ) {
154 $details->th_td("Peer",$peers->peer_link($peer_id));
159 $details->form_end();
161 //////////////////// slices
162 plc_section('Slices');
165 plc_warning ("User has no slice");
167 $headers=array('Slice name'=>'string');
169 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
170 if (count ($slices) <= $reasonable_page) {
171 $table_options['search_area']=false;
172 $table_options['pagesize_area']=false;
174 $table=new PlcTable ("person_slices",$headers,1,$table_options);
177 foreach( $slices as $slice ) {
178 $slice_name= $slice['name'];
179 $slice_id= $slice['slice_id'];
181 $table->cell(l_slice_t($slice_id,$slice_name));
187 // we don't set 'action', but use the submit button name instead
188 $form=new PlcForm(l_actions(), array("person_id"=>$person_id));
191 //////////////////// keys
192 plc_section ("Keys");
194 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
195 if ( empty( $key_ids ) ) {
196 plc_warning("This user has no known key");
199 $headers=array("Type"=>"string",
201 if ($can_manage_keys) $headers[plc_delete_icon()]="none";
202 // table overall options
203 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
204 $table=new PlcTable("person_keys",$headers,"1",$table_options);
207 if ($keys) foreach ($keys as $key) {
208 $key_id=$key['key_id'];
210 $table->cell ($key['key_type']);
211 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
212 if ($can_manage_keys)
213 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
216 // the footer area is used for displaying key-management buttons
217 // add the 'remove keys' button and key upload areas as the table footer
218 if ($can_manage_keys) {
219 $table->tfoot_start();
220 // no need to remove if there's no key
223 $table->cell($form->submit_html ("delete-keys","Remove keys"),
224 $table->columns(),"right");
228 $table->cell($form->label_html("key","Upload new key")
229 . $form->file_html("key","upload",array('size'=>60))
230 . $form->submit_html("upload-key","Upload key"),
231 $table->columns(),"right");
237 //////////////////// sites
238 plc_section('Sites');
240 if (empty( $sites ) ) {
241 plc_warning('This user is not affiliated with a site !!');
243 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
245 $headers['Login_base']="string";
246 $headers['Name']="string";
247 if ($can_manage_sites) $headers[plc_delete_icon()]="none";
248 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
249 $table=new PlcTable ("person_sites",$headers,0,$table_options);
251 foreach( $sites as $site ) {
252 $site_name= $site['name'];
253 $site_id= $site['site_id'];
254 $login_base=$site['login_base'];
256 $table->cell ($login_base);
257 $table->cell (l_site_t($site_id,$site_name));
258 if ($can_manage_sites)
259 $table->cell ($form->checkbox_html('site_ids[]',$site_id));
262 if ($can_manage_sites) {
263 $table->tfoot_start();
267 $table->cell($form->submit_html("remove-person-from-sites","Remove Sites"),
268 $table->columns(),"right");
274 // get list of local sites that the person is not in
275 function get_site_id ($site) { return $site['site_id'];}
276 $person_site_ids=array_map("get_site_id",$sites);
277 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
278 // xxx cannot use onchange=submit() - would need to somehow pass action name
279 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
280 $selectors = array_map ("site_selector",$relevant_sites);
281 $table->cell ($form->select_html("site_id",$selectors,array('label'=>"Choose a site to add")).
282 $form->submit_html("add-person-to-site","Add in site"),
283 $table->columns(),"right");
288 //////////////////// roles
289 plc_section("Roles");
290 if (! $roles) plc_warning ("This user has no role !");
292 $can_manage_roles= ($local_peer && plc_is_admin());
293 $table_options=array("search_area"=>false,"notes_area"=>false);
295 $headers=array("Role"=>"string");
296 if ($can_manage_roles) $headers [plc_delete_icon()]="none";
298 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
299 $table=new PlcTable("person_roles",$headers,0,$table_options);
302 // construct array of role objs
304 for ($n=0; $n<count($roles); $n++) {
305 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
308 if ($role_objs) foreach ($role_objs as $role_obj) {
310 $table->cell($role_obj['name']);
311 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
315 // footers : the remove and add buttons
316 if ($can_manage_roles) {
317 $table->tfoot_start();
320 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
321 $table->columns(),"right");
326 $selectors=$form->role_selectors_excluding($api,$role_ids);
327 $add_role_left_area=$form->select_html("role_id",$selectors,array('label'=>"Choose role"));
328 // add a role : the button
329 $add_role_right_area=$form->submit_html("add-role-to-person",array('label'=>"Add role"));
330 $table->cell ($add_role_left_area . $add_role_right_area,
331 $table->columns(),"right");
336 //////////////////////////////
338 $peers->block_end($peer_id);
341 include 'plc_footer.php';