3 // $Id: index.php 11645 2009-01-21 23:09:49Z thierry $
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 require_once 'plc_minitabs.php';
15 require_once 'plc_tables.php';
19 require_once 'plc_functions.php';
20 require_once 'plc_minitabs.php';
21 require_once 'plc_tables.php';
22 require_once 'plc_details.php';
24 // --------------------
25 // recognized URL arguments
26 $person_id=intval($_GET['id']);
27 if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; }
30 // Get all columns as we focus on only one entry
31 $persons= $api->GetPersons( array($person_id));
33 if (empty($persons)) {
34 drupal_set_message ("Person " . $person_id . " not found");
39 $first_name= $person['first_name'];
40 $last_name= $person['last_name'];
41 $title= $person['title'];
43 $phone= $person['phone'];
44 $email= $person['email'];
45 $enabled= $person['enabled'];
46 $peer_id=$person['peer_id'];
49 $role_ids= $person['role_ids'];
50 $roles= $person['roles'];
51 $site_ids= $person['site_ids'];
52 $slice_ids= $person['slice_ids'];
53 $key_ids= $person['key_ids'];
55 // gets more data from API calls
56 $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
57 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
58 $keys= $api->GetKeys( $key_ids );
60 drupal_set_title("Details for account " . $first_name . " " . $last_name);
62 $plc_hash=plc_peer_get_hash($api);
64 $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
65 $is_my_account = plc_my_person_id() == $person_id;
66 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
70 if ($local_peer && $privileges) {
72 $tabs['Events'] = array('url'=>l_event("Person","person",$person_id),
73 'bubble'=>'Related events',
74 'image'=>'/planetlab/icons/event.png',
77 $tabs['Disable'] = array ('method'=>'POST',
78 'url'=>'/db/persons/person_actions.php',
79 'values'=> array ('person_id'=>$person_id,
81 'bubble'=>"Disable $first_name");
83 $tabs['Enable'] = array ('method'=>'POST',
84 'url'=>'/db/persons/person_actions.php',
85 'values'=> array ('person_id'=>$person_id,
87 'bubble'=>"Enable $first_name");
88 $tabs['Delete'] = array ('method'=>'POST',
89 'url'=>'/db/persons/person_actions.php',
90 'values'=> array ('person_id'=>$person_id,
92 'bubble'=>"Delete $first_name",
93 'confirm'=>"Are you sure to delete $first_name $last_name");
96 if ($privileges || $is_my_account)
97 $tabs['Update'] = array('url'=>'/db/persons/update.php',
98 'values'=>array('id'=>$person_id),
99 'bubble'=>"Update $first_name");
101 $tabs['Persons'] = array ('url'=>l_persons());
106 plc_details_line("First Name",$first_name);
107 plc_details_line("Last Name",$last_name);
108 plc_details_line("Title",$title);
109 plc_details_line("Email",href("mailto:$email",$email));
110 plc_details_line("Phone",$phone);
111 plc_details_line("URL",$url);
118 $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
119 plc_table_title('Keys');
120 if ( empty( $key_ids ) ) {
121 echo "<span class='plc-warning'> This user has no known key</span>";
123 echo "<p><table border=0 width=450>\n";
124 echo "<thead><tr><th>Type</th><th>Key</th>";
125 if ( $can_manage_keys )
126 echo "<th>Remove</th>";
127 echo "</tr></thead><tbody>\n";
129 foreach( $keys as $key ) {
130 $key_type= $key['key_type'];
131 $key_id= $key['key_id'];
132 $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
133 echo "<tr><td>$key_type</td><td>$key_text";
135 if ( $can_manage_keys )
136 echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
141 echo "</tbody></table>\n";
142 if ($can_manage_keys)
143 echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
146 if( $can_manage_keys ){
147 echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
148 <input type='submit' name='Upload' value='Upload'>\n
153 plc_table_title('Sites');
156 if (empty( $sites ) ) {
157 plc_warning('This user is not affiliated with a site !!');
160 $columns['Name']="string";
161 $columns['Login_base']="string";
162 $columns['Remove']="string";
163 $table_options = array('notes_area'=>false,'search_area'=>false);
164 plc_table_start ("person_slices",$columns,1,$table_options);
165 foreach( $sites as $site ) {
166 $site_name= $site['name'];
167 $site_id= $site['site_id'];
168 $login_base=$site['login_base'];
169 plc_table_row_start();
170 plc_table_cell (l_site_t($site_id,$site_name));
171 plc_table_cell ($login_base);
172 plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
173 plc_table_row_end ();
175 plc_table_end($table_options);
178 echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
181 // diplay site select list to add another site for user
182 if ($local_peer && plc_is_admin()) {
184 $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
187 $person_site= arr_diff( $all_sites, $sites );
189 $person_site= $all_sites;
191 // sort_sites( $person_site );
193 echo "<p>Select a site to add this user to: ";
194 echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
196 foreach( $person_site as $site ) {
197 echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
207 echo "<h3>Roles</h3>\n";
209 echo "<thead><tr><th>Role</th>";
211 echo "<th>Remove</th>";
212 echo "</tr></thead><tbody>\n";
214 // construct role array
215 for( $n=0; $n<count($roles); $n++ ) {
216 $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
220 if ( !empty ($roles) ) {
221 foreach( $proles as $role ) {
222 $role_name= $role['name'];
223 $role_id= $role['role_id'];
225 echo "<tr><td>$role_name";
228 if( plc_is_admin()) {
229 echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
230 if ( ! $button_shown ) {
231 $rowspan=count($roles);
232 echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
240 echo "<span class='plc-warning'> This user has no known role !!</span>";
242 echo "</tbody></table>\n";
244 // if admin show roles to add
245 if( plc_is_admin()) {
246 $all_roles= $api->GetRoles();
247 $addable_roles= arr_diff( $all_roles, $proles );
248 ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
249 ##return an empty array and the scrolling roles list is not displayed in this case
250 ##assign to addablerole all the roles
251 if (count($proles)==0)
252 $addable_roles=$all_roles;
254 if( !empty( $addable_roles ) ) {
255 echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
257 foreach( $addable_roles as $arole ) {
258 echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
270 plc_table_title('Slices');
272 if( empty( $slices ) ) {
273 drupal_set_message ("User has no slice");
275 $columns=array('Slice name'=>'string');
276 $table_options=array();
277 plc_table_start("person_slices",$columns,1,$table_options);
279 foreach( $slices as $slice ) {
280 $slice_name= $slice['name'];
281 $slice_id= $slice['slice_id'];
282 plc_table_row_start();
283 plc_table_cell(l_slice_t($slice_id,$slice_name));
286 plc_table_end($table_options);
289 plc_peer_block_end();
294 include 'plc_footer.php';