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 ($privileges || $is_my_account)
78 // $tabs['Update'] = array('url'=>'/db/persons/update.php',
79 // 'values'=>array('id'=>$person_id),
80 // 'bubble'=>"Update $first_name $last_name");
83 if ($local_peer && $privileges)
85 $tabs['Disable'] = array ('method'=>'POST',
87 'values'=> array ('person_id'=>$person_id,
88 'action'=>'disable-person'),
89 'bubble'=>"Disable $first_name $last_name",
90 'confirm'=>"Are you sure you want to disable $first_name $last_name");
92 $tabs['Enable'] = array ('method'=>'POST',
94 'values'=> array ('person_id'=>$person_id,
95 'action'=>'enable-person'),
96 'bubble'=>"Enable $first_name $last_name",
97 'confirm'=>"Are you sure you want to enable $first_name $last_name");
100 if (plc_is_admin() && ! $is_my_account)
101 $tabs['Become'] = array('method'=>'POST',
103 'values'=>array('action'=>'become-person',
104 'person_id'=>$person_id),
105 'bubble'=>"Become $first_name $last_name",
106 'confirm'=>"Are you sure you want to su $first_name $last_name");
109 if ($local_peer && $privileges)
110 $tabs['Delete'] = array ('method'=>'POST',
112 'values'=> array ('person_id'=>$person_id,
113 'action'=>'delete-person'),
114 'bubble'=>"Delete $first_name $last_name",
115 'confirm'=>"Are you sure to delete $first_name $last_name");
116 // events for that person
118 $tabs['Events'] = array('url'=>l_events(),
119 'values'=>array('type'=>'Person','person'=>$person_id),
120 'bubble'=>"Events about $first_name $last_name",
121 'image'=>'/planetlab/icons/event.png','height'=>18);
124 $tabs['All Users'] = array ('url'=>l_persons(),
125 'bubble'=>'Back to the Users page');
129 $peers->block_start ($peer_id);
131 if ($local_peer && $privileges && ! $enabled )
132 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
134 $enabled_label="Enabled";
135 if ( ! $enabled ) $enabled_label = plc_warning_html("Disabled");
137 $can_update = $is_my_account || plc_is_admin();
138 $details = new PlcDetails($can_update);
140 $details->line("Enabled",$enabled_label);
142 $details->form_start(l_actions(),array("action"=>"update-person",
143 "person_id"=>$person_id));
144 $details->line("Title",$title,"title");
145 $details->line("First Name",$first_name,"first_name");
146 $details->line("Last Name",$last_name,"last_name");
147 $details->line(href("mailto:$email","Email"),$email,"email");
148 $details->line("URL",$url,"url");
149 $details->line("Phone",$phone,"phone");
150 $details->line("Bio",wordwrap($bio,50,"<br/>"),"bio");
151 // xxx need to check that this is working
153 $save=$details->set_input_type("password");
154 $details->line("Password","","password1");
155 $details->line("Repeat","","password2");
156 $details->set_input_type($save);
158 // xxx need fields to reset password ?
159 $details->line("",$details->submit_html("submit","Update Account"));
160 $details->form_end();
162 $details->line("Peer",$peers->peer_link($peer_id));
165 //////////////////// slices
166 plc_section('Slices');
169 plc_warning ("User has no slice");
171 $headers=array('Slice name'=>'string');
173 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
174 if (count ($slices) <= $reasonable_page) {
175 $table_options['search_area']=false;
176 $table_options['pagesize_area']=false;
178 $table=new PlcTable ("person_slices",$headers,1,$table_options);
181 foreach( $slices as $slice ) {
182 $slice_name= $slice['name'];
183 $slice_id= $slice['slice_id'];
185 $table->cell(l_slice_t($slice_id,$slice_name));
191 // we don't set 'action', but use the submit button name instead
192 $form=new PlcForm(l_actions(), array("person_id"=>$person_id));
195 //////////////////// keys
196 plc_section ("Keys");
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");
204 $headers=array("Type"=>"string",
206 if ($can_manage_keys) $headers['Remove']="none";
207 // table overall options
208 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
209 $table=new PlcTable("person_keys",$headers,"1",$table_options);
212 if ($keys) foreach ($keys as $key) {
213 $key_id=$key['key_id'];
215 $table->cell ($key['key_type']);
216 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
217 if ($can_manage_keys)
218 $table->cell ($form->checkbox_html('key_ids[]',$key_id));
221 // the footer area is used for displaying key-management buttons
222 // add the 'remove keys' button and key upload areas as the table footer
223 if ($can_manage_keys) {
224 $table->tfoot_start();
225 // no need to remove if there's no key
228 $table->cell($form->submit_html ("delete-keys","Remove keys"),
229 $table->columns(),"right");
233 $table->cell($form->label_html("key","Upload new key") . $form->file_html("key",60),
234 $table->columns()-1,"right");
235 $table->cell($form->submit_html("upload-key","Upload key"));
241 //////////////////// sites
242 plc_section('Sites');
245 if (empty( $sites ) ) {
246 plc_warning('This user is not affiliated with a site !!');
248 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
250 $headers['Login_base']="string";
251 $headers['Name']="string";
252 if ($can_manage_sites)
253 $headers['Remove']="string";
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 select_arguments($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
286 $selectors = array_map ("select_arguments",$relevant_sites);
287 $table->cell ($form->select_html("site_id",$selectors,"Choose a site to add").
288 $form->submit_html("add-person-to-site","Add in site"),
289 $table->columns(),"right");
294 //////////////////// roles
295 plc_section("Roles");
296 if (! $roles) plc_warning ("This user has no role !");
298 $can_manage_roles= ($local_peer && plc_is_admin());
299 $table_options=array("search_area"=>false,"notes_area"=>false);
301 $headers=array("Role"=>"none");
302 if ($can_manage_roles) $headers ["Remove"]="none";
304 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
305 $table=new PlcTable("person_roles",$headers,0,$table_options);
308 // construct array of role objs
310 for ($n=0; $n<count($roles); $n++) {
311 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
314 if ($role_objs) foreach ($role_objs as $role_obj) {
316 $table->cell($role_obj['name']);
317 if ($can_manage_roles) $table->cell ($form->checkbox_html('role_ids[]',$role_obj['role_id']));
321 // footers : the remove and add buttons
322 if ($can_manage_roles) {
323 $table->tfoot_start();
326 $table->cell($form->submit_html("remove-roles-from-person","Remove Roles"),
327 $table->columns(),"right");
332 // get list of local roles that the person has not yet
333 // xxx this does not work because GetRoles does not support filters
334 $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
335 function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
336 $selectors=array_map("selector_argument",$relevant_roles);
337 $add_role_left_area=$form->select_html("role_id",$selectors,"Choose a role to add");
338 // add a role : the button
339 $add_role_right_area=$form->submit_html("add-role-to-person","Add role");
340 $table->cell ($add_role_left_area . $add_role_right_area,
341 $table->columns(),"right");
346 //////////////////////////////
348 $peers->block_end($peer_id);
351 include 'plc_footer.php';