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_minitabs.php';
19 require_once 'plc_tables.php';
20 require_once 'plc_details.php';
21 require_once 'plc_forms.php';
23 // --------------------
24 // recognized URL arguments
25 $person_id=intval($_GET['id']);
27 plc_error('Malformed URL - id not set');
32 // Get all columns as we focus on only one entry
33 $persons= $api->GetPersons( array($person_id));
35 if (empty($persons)) {
36 drupal_set_message ("Person " . $person_id . " not found");
42 $enabled= $person['enabled'];
43 $first_name= $person['first_name'];
44 $last_name= $person['last_name'];
45 $email= $person['email'];
47 $phone= $person['phone'];
48 $title= $person['title'];
50 $peer_id=$person['peer_id'];
53 $role_ids= $person['role_ids'];
54 $roles= $person['roles'];
55 $site_ids= $person['site_ids'];
56 $slice_ids= $person['slice_ids'];
57 $key_ids= $person['key_ids'];
59 // gets more data from API calls
60 $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
61 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
62 $keys= $api->GetKeys( $key_ids );
64 drupal_set_title("Details for account " . $first_name . " " . $last_name);
66 $plc_hash=plc_peer_get_hash($api);
68 $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
69 $is_my_account = plc_my_person_id() == $person_id;
70 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
75 if ($privileges || $is_my_account)
76 $tabs['Update'] = array('url'=>'/db/persons/update.php',
77 'values'=>array('id'=>$person_id),
78 'bubble'=>"Update $first_name $last_name");
81 if ($local_peer && $privileges)
83 $tabs['Disable'] = array ('method'=>'POST',
84 'url'=>l_person_actions(),
85 'values'=> array ('person_id'=>$person_id,
86 'action'=>'disable-person'),
87 'bubble'=>"Disable $first_name $last_name",
88 'confirm'=>"Are you sure you want to disable $first_name $last_name");
90 $tabs['Enable'] = array ('method'=>'POST',
91 'url'=>l_person_actions(),
92 'values'=> array ('person_id'=>$person_id,
93 'action'=>'enable-person'),
94 'bubble'=>"Enable $first_name $last_name",
95 'confirm'=>"Are you sure you want to enable $first_name $last_name");
98 if (plc_is_admin() && ! $is_my_account)
99 $tabs['Become'] = array('url'=>l_person_actions(),
100 'values'=>array('action'=>'become-person',
101 'person_id'=>$person_id),
102 'bubble'=>"Become $first_name $last_name",
103 'confirm'=>"Are you sure you want to su $first_name $last_name");
106 if ($local_peer && $privileges)
107 $tabs['Delete'] = array ('method'=>'POST',
108 'url'=>l_person_actions(),
109 'values'=> array ('person_id'=>$person_id,
110 'action'=>'delete-person'),
111 'bubble'=>"Delete $first_name $last_name",
112 'confirm'=>"Are you sure to delete $first_name $last_name");
113 // events for that person
115 $tabs['Events'] = array('url'=>l_events(),
116 'values'=>array('type'=>'Person','person'=>$person_id),
117 'bubble'=>"Events about $first_name $last_name",
118 'image'=>'/planetlab/icons/event.png',
122 $tabs['All Users'] = array ('url'=>l_persons(),
123 'bubble'=>'Back to the Users page');
127 if ($local_peer && $privileges && ! $enabled )
128 drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
130 $enabled_text="Enabled";
131 if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
134 plc_details_line("Enabled",$enabled_text);
135 plc_details_line("First Name",$first_name);
136 plc_details_line("Last Name",$last_name);
137 plc_details_line("Email",href("mailto:$email",$email));
138 plc_details_line("URL",$url);
139 plc_details_line("Phone",$phone);
140 plc_details_line("Title",$title);
141 plc_details_line("Bio",wordwrap($bio,50,"<br/>"));
144 //////////////////// slices
146 plc_table_title('Slices');
148 if( empty( $slices ) ) {
149 drupal_set_message ("User has no slice");
151 $columns=array('Slice name'=>'string');
152 $table_options=array('notes_area'=>false,
154 plc_table_start("person_slices",$columns,1,$table_options);
156 foreach( $slices as $slice ) {
157 $slice_name= $slice['name'];
158 $slice_id= $slice['slice_id'];
159 plc_table_row_start();
160 plc_table_cell(l_slice_t($slice_id,$slice_name));
163 plc_table_end("person_slices");
168 plc_table_title ("Keys");
170 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
171 if ( empty( $key_ids ) ) {
172 plc_warning("This user has no known key");
174 // we don't set 'action', but use the submit button name instead
175 plc_form_start(l_person_actions(),
176 array("person_id"=>$person_id,
181 $columns=array("Type"=>"string",
183 if ($can_manage_keys) $columns['Remove']="none";
184 // table overall options
185 $table_options=array("search_area"=>false,"notes_area"=>false);
186 // add the 'remove site' button and key upload areas as the table footer
187 if ($can_manage_keys) {
188 $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
189 $upload_key_left_area= plc_form_label_text("Upload new key","key") . plc_form_file_text("key",60);
190 $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
191 $table_options['footer']="";
192 if ($keys) $table_options['footer'].="<tr><td colspan=3 style='text-align:right'> $remove_keys_area </td></tr>";
193 $table_options['footer'].="<tr><td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
194 "<td> $upload_key_right_area </td></tr>";
196 plc_table_start("person_keys",$columns,"1",$table_options);
198 if ($keys) foreach ($keys as $key) {
199 $key_id=$key['key_id'];
200 plc_table_row_start($key_id);
201 plc_table_cell ($key['key_type']);
202 plc_table_cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
203 if ($can_manage_keys)
204 plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id));
207 plc_table_end("person_keys");
212 plc_table_title('Sites');
215 if (empty( $sites ) ) {
216 plc_warning('This user is not affiliated with a site !!');
219 $columns['Name']="string";
220 $columns['Login_base']="string";
221 $columns['Remove']="string";
222 $table_options = array('notes_area'=>false,'search_area'=>false);
223 plc_table_start ("person_sites",$columns,1,$table_options);
224 foreach( $sites as $site ) {
225 $site_name= $site['name'];
226 $site_id= $site['site_id'];
227 $login_base=$site['login_base'];
228 plc_table_row_start();
229 plc_table_cell (l_site_t($site_id,$site_name));
230 plc_table_cell ($login_base);
231 plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
232 plc_table_row_end ();
234 plc_table_end("person_sites");
237 echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
240 // diplay site select list to add another site for user
241 if ($local_peer && plc_is_admin()) {
243 $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
246 $person_site= arr_diff( $all_sites, $sites );
248 $person_site= $all_sites;
250 // sort_sites( $person_site );
252 echo "<p>Select a site to add this user to: ";
253 echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
255 foreach( $person_site as $site ) {
256 echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
266 echo "<h3>Roles</h3>\n";
268 echo "<thead><tr><th>Role</th>";
270 echo "<th>Remove</th>";
271 echo "</tr></thead><tbody>\n";
273 // construct role array
274 for( $n=0; $n<count($roles); $n++ ) {
275 $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
279 if ( !empty ($roles) ) {
280 foreach( $proles as $role ) {
281 $role_name= $role['name'];
282 $role_id= $role['role_id'];
284 echo "<tr><td>$role_name";
287 if( plc_is_admin()) {
288 echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
289 if ( ! $button_shown ) {
290 $rowspan=count($roles);
291 echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
299 echo "<span class='plc-warning'> This user has no known role !!</span>";
301 echo "</tbody></table>\n";
303 // if admin show roles to add
304 if( plc_is_admin()) {
305 $all_roles= $api->GetRoles();
306 $addable_roles= arr_diff( $all_roles, $proles );
307 ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
308 ##return an empty array and the scrolling roles list is not displayed in this case
309 ##assign to addablerole all the roles
310 if (count($proles)==0)
311 $addable_roles=$all_roles;
313 if( !empty( $addable_roles ) ) {
314 echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
316 foreach( $addable_roles as $arole ) {
317 echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
326 plc_peer_block_end();
329 include 'plc_footer.php';