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_text="Enabled";
135 if ( ! $enabled ) $enabled_text = plc_warning_text("Disabled");
138 plc_details_line("Enabled",$enabled_text);
139 plc_details_line("First Name",$first_name);
140 plc_details_line("Last Name",$last_name);
141 plc_details_line("Email",href("mailto:$email",$email));
142 plc_details_line("URL",$url);
143 plc_details_line("Phone",$phone);
144 plc_details_line("Title",$title);
145 plc_details_line("Bio",wordwrap($bio,50,"<br/>"));
146 plc_details_line("Peer",$peers->peer_link($peer_id));
149 //////////////////// slices
150 plc_section('Slices');
153 plc_warning ("User has no slice");
155 $headers=array('Slice name'=>'string');
157 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
158 if (count ($slices) <= $reasonable_page) {
159 $table_options['search_area']=false;
160 $table_options['pagesize_area']=false;
162 $table=new PlcTable ("person_slices",$headers,1,$table_options);
165 foreach( $slices as $slice ) {
166 $slice_name= $slice['name'];
167 $slice_id= $slice['slice_id'];
169 $table->cell(l_slice_t($slice_id,$slice_name));
175 // we don't set 'action', but use the submit button name instead
176 plc_form_start(l_actions(), array("person_id"=>$person_id,));
178 //////////////////// keys
179 plc_section ("Keys");
181 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
182 if ( empty( $key_ids ) ) {
183 plc_warning("This user has no known key");
187 $headers=array("Type"=>"string",
189 if ($can_manage_keys) $headers['Remove']="none";
190 // table overall options
191 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
192 $table=new PlcTable("person_keys",$headers,"1",$table_options);
195 if ($keys) foreach ($keys as $key) {
196 $key_id=$key['key_id'];
198 $table->cell ($key['key_type']);
199 $table->cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
200 if ($can_manage_keys)
201 $table->cell (plc_form_checkbox_text('key_ids[]',$key_id));
204 // the footer area is used for displaying key-management buttons
205 // add the 'remove keys' button and key upload areas as the table footer
206 if ($can_manage_keys) {
207 $table->tfoot_start();
208 // no need to remove if there's no key
211 $table->cell(plc_form_submit_text ("delete-keys","Remove keys"),
212 $table->columns(),"right");
216 $table->cell(plc_form_label_text("key","Upload new key") . plc_form_file_text("key",60),
217 $table->columns()-1,"right");
218 $table->cell(plc_form_submit_text("upload-key","Upload key"));
224 //////////////////// sites
225 plc_section('Sites');
228 if (empty( $sites ) ) {
229 plc_warning('This user is not affiliated with a site !!');
231 $can_manage_sites = $local_peer && plc_is_admin() || $is_my_account;
233 $headers['Login_base']="string";
234 $headers['Name']="string";
235 if ($can_manage_sites)
236 $headers['Remove']="string";
237 $table_options = array('notes_area'=>false,'search_area'=>false, 'pagesize_area'=>false);
238 $table=new PlcTable ("person_sites",$headers,0,$table_options);
240 foreach( $sites as $site ) {
241 $site_name= $site['name'];
242 $site_id= $site['site_id'];
243 $login_base=$site['login_base'];
245 $table->cell ($login_base);
246 $table->cell (l_site_t($site_id,$site_name));
247 if ($can_manage_sites)
248 $table->cell (plc_form_checkbox_text('site_ids[]',$site_id));
251 if ($can_manage_sites) {
252 $table->tfoot_start();
256 $table->cell(plc_form_submit_text("remove-person-from-sites","Remove Sites"),
257 $table->columns(),"right");
263 // get list of local sites that the person is not in
264 function get_site_id ($site) { return $site['site_id'];}
265 $person_site_ids=array_map("get_site_id",$sites);
266 $relevant_sites= $api->GetSites( array("peer_id"=>NULL,"~site_id"=>$person_site_ids), $site_columns);
267 // xxx cannot use onchange=submit() - would need to somehow pass action name
268 function select_arguments($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
269 $selectors = array_map ("select_arguments",$relevant_sites);
270 $table->cell (plc_form_select_text("site_id",$selectors,"Choose a site to add").
271 plc_form_submit_text("add-person-to-site","Add in site"),
272 $table->columns(),"right");
277 //////////////////// roles
278 plc_section("Roles");
279 if (! $roles) plc_warning ("This user has no role !");
281 $can_manage_roles= ($local_peer && plc_is_admin());
282 $table_options=array("search_area"=>false,"notes_area"=>false);
284 $headers=array("Role"=>"none");
285 if ($can_manage_roles) $headers ["Remove"]="none";
287 $table_options=array('search_area'=>false,'pagesize_area'=>false,'notes_area'=>false);
288 $table=new PlcTable("person_roles",$headers,0,$table_options);
291 // construct array of role objs
293 for ($n=0; $n<count($roles); $n++) {
294 $role_objs[]= array('role_id'=>$role_ids[$n], 'name'=>$roles[$n]);
297 if ($role_objs) foreach ($role_objs as $role_obj) {
299 $table->cell($role_obj['name']);
300 if ($can_manage_roles) $table->cell (plc_form_checkbox_text('role_ids[]',$role_obj['role_id']));
304 // footers : the remove and add buttons
305 if ($can_manage_roles) {
306 $table->tfoot_start();
309 $table->cell(plc_form_submit_text("remove-roles-from-person","Remove Roles"),
310 $table->columns(),"right");
315 // get list of local roles that the person has not yet
316 // xxx this does not work because GetRoles does not support filters
317 $relevant_roles = $api->GetRoles( array("~role_id"=>$role_ids));
318 function selector_argument ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
319 $selectors=array_map("selector_argument",$relevant_roles);
320 $add_role_left_area=plc_form_select_text("role_id",$selectors,"Choose a role to add");
321 // add a role : the button
322 $add_role_right_area=plc_form_submit_text("add-role-to-person","Add role");
323 $table->cell ($add_role_left_area . $add_role_right_area,
324 $table->columns(),"right");
329 //////////////////////////////
331 $peers->block_end($peer_id);
334 include 'plc_footer.php';