require_once 'plc_minitabs.php';
require_once 'plc_tables.php';
require_once 'plc_details.php';
+require_once 'plc_forms.php';
// --------------------
// recognized URL arguments
$person_id=intval($_GET['id']);
-if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; }
+if ( ! $person_id ) {
+ plc_error('Malformed URL - id not set');
+ return;
+ }
////////////////////
// Get all columns as we focus on only one entry
if (empty($persons)) {
drupal_set_message ("Person " . $person_id . " not found");
- } else {
- $person=$persons[0];
-
- // vars from api
- $first_name= $person['first_name'];
- $last_name= $person['last_name'];
- $title= $person['title'];
- $url= $person['url'];
- $phone= $person['phone'];
- $email= $person['email'];
- $enabled= $person['enabled'];
- $peer_id=$person['peer_id'];
-
- // arrays from api
- $role_ids= $person['role_ids'];
- $roles= $person['roles'];
- $site_ids= $person['site_ids'];
- $slice_ids= $person['slice_ids'];
- $key_ids= $person['key_ids'];
-
- // gets more data from API calls
- $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
- $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
- $keys= $api->GetKeys( $key_ids );
+ return;
+ }
+$person=$persons[0];
- drupal_set_title("Details for account " . $first_name . " " . $last_name);
+// vars from api
+$enabled= $person['enabled'];
+$first_name= $person['first_name'];
+$last_name= $person['last_name'];
+$email= $person['email'];
+$url= $person['url'];
+$phone= $person['phone'];
+$title= $person['title'];
+$bio= $person['bio'];
+$peer_id=$person['peer_id'];
- $plc_hash=plc_peer_get_hash($api);
+// arrays from api
+$role_ids= $person['role_ids'];
+$roles= $person['roles'];
+$site_ids= $person['site_ids'];
+$slice_ids= $person['slice_ids'];
+$key_ids= $person['key_ids'];
- $local_peer = plc_peer_block_start ($peer_hash,$peer_id);
- $is_my_account = plc_my_person_id() == $person_id;
- $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
+// gets more data from API calls
+$sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) );
+$slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) );
+$keys= $api->GetKeys( $key_ids );
- $tabs=array();
+drupal_set_title("Details for account " . $first_name . " " . $last_name);
- if ($local_peer && $privileges) {
- if (plc_is_admin())
- $tabs['Events'] = array('url'=>l_events(),
- 'values'=>array('type'=>'Person','person'=>$person_id),
- 'bubble'=>'Related events',
- 'image'=>'/planetlab/icons/event.png',
- 'height'=>18);
- if ($enabled)
- $tabs['Disable'] = array ('method'=>'POST',
- 'url'=>'/db/persons/person_actions.php',
- 'values'=> array ('person_id'=>$person_id,
- 'action'=>'disable'),
- 'bubble'=>"Disable $first_name",
- 'confirm'=>"Are you sure you want to disable $first_name $last_name");
- else
- $tabs['Enable'] = array ('method'=>'POST',
- 'url'=>'/db/persons/person_actions.php',
- 'values'=> array ('person_id'=>$person_id,
- 'action'=>'enable'),
- 'bubble'=>"Enable $first_name");
- $tabs['Delete'] = array ('method'=>'POST',
- 'url'=>'/db/persons/person_actions.php',
- 'values'=> array ('person_id'=>$person_id,
- 'action'=>'delete'),
- 'bubble'=>"Delete $first_name",
- 'confirm'=>"Are you sure to delete $first_name $last_name");
- }
+$plc_hash=plc_peer_get_hash($api);
- if ($privileges || $is_my_account)
- $tabs['Update'] = array('url'=>'/db/persons/update.php',
- 'values'=>array('id'=>$person_id),
- 'bubble'=>"Update $first_name");
+$local_peer = plc_peer_block_start ($peer_hash,$peer_id);
+$is_my_account = plc_my_person_id() == $person_id;
+$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
- $tabs['All Users'] = array ('url'=>l_persons());
+$tabs=array();
- plc_tabs($tabs);
-
- if ($privileges && ! $enabled )
- drupal_set_message ("$first_name $last_name is not enabled yet, please use the 'Enable' button below");
+// update
+if ($privileges || $is_my_account)
+ $tabs['Update'] = array('url'=>'/db/persons/update.php',
+ 'values'=>array('id'=>$person_id),
+ 'bubble'=>"Update $first_name $last_name");
+
+// enable / disable
+if ($local_peer && $privileges)
+ if ($enabled)
+ $tabs['Disable'] = array ('method'=>'POST',
+ 'url'=>l_person_actions(),
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'disable-person'),
+ 'bubble'=>"Disable $first_name $last_name",
+ 'confirm'=>"Are you sure you want to disable $first_name $last_name");
+ else
+ $tabs['Enable'] = array ('method'=>'POST',
+ 'url'=>l_person_actions(),
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'enable-person'),
+ 'bubble'=>"Enable $first_name $last_name",
+ 'confirm'=>"Are you sure you want to enable $first_name $last_name");
- $enabled_text="Enabled";
- if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
+// become
+if (plc_is_admin() && ! $is_my_account)
+ $tabs['Become'] = array('url'=>l_person_actions(),
+ 'values'=>array('action'=>'become-person',
+ 'person_id'=>$person_id),
+ 'bubble'=>"Become $first_name $last_name",
+ 'confirm'=>"Are you sure you want to su $first_name $last_name");
+
+// delete
+if ($local_peer && $privileges)
+ $tabs['Delete'] = array ('method'=>'POST',
+ 'url'=>l_person_actions(),
+ 'values'=> array ('person_id'=>$person_id,
+ 'action'=>'delete-person'),
+ 'bubble'=>"Delete $first_name $last_name",
+ 'confirm'=>"Are you sure to delete $first_name $last_name");
+// events for that person
+if ( $privileges)
+ $tabs['Events'] = array('url'=>l_events(),
+ 'values'=>array('type'=>'Person','person'=>$person_id),
+ 'bubble'=>"Events about $first_name $last_name",
+ 'image'=>'/planetlab/icons/event.png',
+ 'height'=>18);
- plc_details_start();
- plc_details_line("Enabled",$enabled_text);
- plc_details_line("First Name",$first_name);
- plc_details_line("Last Name",$last_name);
- plc_details_line("Title",$title);
- plc_details_line("Email",href("mailto:$email",$email));
- plc_details_line("Phone",$phone);
- plc_details_line("URL",$url);
- plc_details_end();
+// Back button
+$tabs['All Users'] = array ('url'=>l_persons(),
+ 'bubble'=>'Back to the Users page');
-
- echo "<hr />\n";
-
- // keys
- $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
- plc_table_title('Keys');
- if ( empty( $key_ids ) ) {
- echo "<span class='plc-warning'> This user has no known key</span>";
- } else {
- echo "<p><table border=0 width=450>\n";
- echo "<thead><tr><th>Type</th><th>Key</th>";
- if ( $can_manage_keys )
- echo "<th>Remove</th>";
- echo "</tr></thead><tbody>\n";
+plc_tabs($tabs);
- foreach( $keys as $key ) {
- $key_type= $key['key_type'];
- $key_id= $key['key_id'];
- $key_text= wordwrap( $key['key'], 70, "<br />\n", 1 );
- echo "<tr><td>$key_type</td><td>$key_text";
-
- if ( $can_manage_keys )
- echo "</td><td><input type=checkbox name='rem_key[]' value='$key_id'>";
-
- echo "</td></tr>\n";
- }
-
- echo "</tbody></table>\n";
- if ($can_manage_keys)
- echo "<p><input type=submit name='Remove_keys' value='Remove keys'><br />\n";
+if ($local_peer && $privileges && ! $enabled )
+ drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below");
+
+$enabled_text="Enabled";
+if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled");
+
+plc_details_start();
+plc_details_line("Enabled",$enabled_text);
+plc_details_line("First Name",$first_name);
+plc_details_line("Last Name",$last_name);
+plc_details_line("Email",href("mailto:$email",$email));
+plc_details_line("URL",$url);
+plc_details_line("Phone",$phone);
+plc_details_line("Title",$title);
+plc_details_line("Bio",wordwrap($bio,50,"<br/>"));
+plc_details_end();
+
+//////////////////// slices
+echo "<hr />\n";
+plc_table_title('Slices');
+
+if( empty( $slices ) ) {
+ drupal_set_message ("User has no slice");
+ } else {
+ $columns=array('Slice name'=>'string');
+ plc_table_start("person_slices",$columns,1,$table_options);
+
+ foreach( $slices as $slice ) {
+ $slice_name= $slice['name'];
+ $slice_id= $slice['slice_id'];
+ plc_table_row_start();
+ plc_table_cell(l_slice_t($slice_id,$slice_name));
+ plc_table_row_end();
}
+ plc_table_end("person_slices");
+ }
+
+////////// keys
+echo "<hr />\n";
+plc_table_title ("Keys");
- if( $can_manage_keys ){
- echo "<br /> Upload new key: <input type='file' name='key' size=30>\n
- <input type='submit' name='Upload' value='Upload'>\n
- <br /><hr />\n";
+$can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) );
+if ( empty( $key_ids ) ) {
+ plc_warning("This user has no known key");
+ } else {
+ // we don't set 'action', but use the submit button name instead
+ plc_form_start(l_person_actions(),
+ array("person_id"=>$person_id));
+
+ // the headers
+ $columns=array("Type"=>"string",
+ "Key"=>"string");
+ if ($can_manage_keys) $columns['Remove']="none";
+ // table overall options
+ $table_options=array("search_area"=>false,"notes_area"=>false);
+ // add the 'remove site' button and key upload areas as the table footer
+ if ($can_manage_keys) {
+ $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys");
+ $upload_key_left_area= plc_form_label_text("Upload new key","key") . plc_form_file_text("key",60);
+ $upload_key_right_area=plc_form_submit_text("upload-key","Upload key");
+ $table_options['footer']="";
+ $table_options['footer'].="<tr><td colspan=3 style='text-align:right'> $remove_keys_area </td></tr>";
+ $table_options['footer'].="<tr><td colspan=2 style='text-align:right'> $upload_key_left_area </td>".
+ "<td> $upload_key_right_area </td></tr>";
+ }
+ plc_table_start("person_keys",$columns,"1",$table_options);
+
+ foreach( $keys as $key ) {
+ $key_id=$key['key_id'];
+ plc_table_row_start($key_id);
+ plc_table_cell ($key['key_type']);
+ plc_table_cell(wordwrap( $key['key'], 60, "<br />\n", 1 ));
+ if ($can_manage_keys)
+ plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id));
+ plc_table_row_end();
}
+ plc_table_end("person_keys");
+ plc_form_end();
+ }
- // sites
- plc_table_title('Sites');
+// sites
+echo "<hr />\n";
+plc_table_title('Sites');
- // sites
- if (empty( $sites ) ) {
- plc_warning('This user is not affiliated with a site !!');
- } else {
- $columns=array();
- $columns['Name']="string";
- $columns['Login_base']="string";
- $columns['Remove']="string";
- $table_options = array('notes_area'=>false,'search_area'=>false);
- plc_table_start ("person_slices",$columns,1,$table_options);
- foreach( $sites as $site ) {
- $site_name= $site['name'];
- $site_id= $site['site_id'];
- $login_base=$site['login_base'];
- plc_table_row_start();
- plc_table_cell (l_site_t($site_id,$site_name));
- plc_table_cell ($login_base);
- plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
- plc_table_row_end ();
- }
- plc_table_end($table_options);
+// sites
+if (empty( $sites ) ) {
+ plc_warning('This user is not affiliated with a site !!');
+ } else {
+ $columns=array();
+ $columns['Name']="string";
+ $columns['Login_base']="string";
+ $columns['Remove']="string";
+ $table_options = array('notes_area'=>false,'search_area'=>false);
+ plc_table_start ("person_sites",$columns,1,$table_options);
+ foreach( $sites as $site ) {
+ $site_name= $site['name'];
+ $site_id= $site['site_id'];
+ $login_base=$site['login_base'];
+ plc_table_row_start();
+ plc_table_cell (l_site_t($site_id,$site_name));
+ plc_table_cell ($login_base);
+ plc_table_cell ("<input id=" . $login_base . " type=checkbox name='rem_site[]' value=" . $site_id . ">");
+ plc_table_row_end ();
}
+ plc_table_end("person_sites");
+ }
- echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
+echo "<input type=submit name='Remove_Sites' value='Remove Sites'>\n";
- // diplay site select list to add another site for user
- if ($local_peer && plc_is_admin()) {
- // get site info
- $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
+// diplay site select list to add another site for user
+if ($local_peer && plc_is_admin()) {
+ // get site info
+ $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) );
- if( $sites )
- $person_site= arr_diff( $all_sites, $sites );
- else
- $person_site= $all_sites;
+ if( $sites )
+ $person_site= arr_diff( $all_sites, $sites );
+ else
+ $person_site= $all_sites;
- // sort_sites( $person_site );
+ // sort_sites( $person_site );
- echo "<p>Select a site to add this user to: ";
- echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
+ echo "<p>Select a site to add this user to: ";
+ echo "<select name='site_add' onChange='submit()'>\n<option value=''>Choose a site to add:</option>\n";
- foreach( $person_site as $site ) {
- echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
+ foreach( $person_site as $site ) {
+ echo "<option value=". $site['site_id'] .">". $site['name'] ."</option>\n";
- }
+ }
- echo "</select>";
+ echo "</select>";
- }
- echo "<hr />\n";
+ }
+echo "<hr />\n";
- // roles
- echo "<h3>Roles</h3>\n";
- echo "<p><table>\n";
- echo "<thead><tr><th>Role</th>";
- if( plc_is_admin())
- echo "<th>Remove</th>";
- echo "</tr></thead><tbody>\n";
+// roles
+echo "<h3>Roles</h3>\n";
+echo "<p><table>\n";
+echo "<thead><tr><th>Role</th>";
+if( plc_is_admin())
+ echo "<th>Remove</th>";
+echo "</tr></thead><tbody>\n";
- // construct role array
- for( $n=0; $n<count($roles); $n++ ) {
- $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
- }
+// construct role array
+for( $n=0; $n<count($roles); $n++ ) {
+ $proles[]= array( 'role_id'=>$role_ids[$n], 'name'=>$roles[$n] );
+ }
- $button_shown=0;
- if ( !empty ($roles) ) {
- foreach( $proles as $role ) {
- $role_name= $role['name'];
- $role_id= $role['role_id'];
+$button_shown=0;
+if ( !empty ($roles) ) {
+ foreach( $proles as $role ) {
+ $role_name= $role['name'];
+ $role_id= $role['role_id'];
- echo "<tr><td>$role_name";
+ echo "<tr><td>$role_name";
- if( plc_is_admin()) {
- echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
- if ( ! $button_shown ) {
- $rowspan=count($roles);
- echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
- $button_shown=1;
- }
+ if( plc_is_admin()) {
+ echo "</td><td><input type=checkbox name='rem_role[]' value='$role_id'>";
+ if ( ! $button_shown ) {
+ $rowspan=count($roles);
+ echo "</td><td rowspan=$rowspan valign=center><input type=submit name='Remove_Roles' value='Remove Roles'></td></tr>\n";
+ $button_shown=1;
}
-
- echo "</td></tr>\n";
}
- } else {
- echo "<span class='plc-warning'> This user has no known role !!</span>";
+
+ echo "</td></tr>\n";
}
- echo "</tbody></table>\n";
+ } else {
+ echo "<span class='plc-warning'> This user has no known role !!</span>";
+ }
+echo "</tbody></table>\n";
- // if admin show roles to add
- if( plc_is_admin()) {
- $all_roles= $api->GetRoles();
- $addable_roles= arr_diff( $all_roles, $proles );
- ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
- ##return an empty array and the scrolling roles list is not displayed in this case
- ##assign to addablerole all the roles
- if (count($proles)==0)
- $addable_roles=$all_roles;
+// if admin show roles to add
+if( plc_is_admin()) {
+ $all_roles= $api->GetRoles();
+ $addable_roles= arr_diff( $all_roles, $proles );
+ ##when the proles array is empty strangely the method arr_diff($all_roles, $proles )
+ ##return an empty array and the scrolling roles list is not displayed in this case
+ ##assign to addablerole all the roles
+ if (count($proles)==0)
+ $addable_roles=$all_roles;
- if( !empty( $addable_roles ) ) {
- echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
+ if( !empty( $addable_roles ) ) {
+ echo "<p>Add role: <select name='add_role' onChange='submit()'>\n<option value=''>Choose a Role to add:</option>\n";
- foreach( $addable_roles as $arole ) {
- echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
+ foreach( $addable_roles as $arole ) {
+ echo "<option value=". $arole['role_id'] .">". $arole['name'] ."</option>\n";
- }
+ }
- echo "</select>\n";
+ echo "</select>\n";
- }
}
+ }
- echo "<hr />\n";
+plc_peer_block_end();
- // slices
- plc_table_title('Slices');
-
- if( empty( $slices ) ) {
- drupal_set_message ("User has no slice");
- } else {
- $columns=array('Slice name'=>'string');
- $table_options=array();
- plc_table_start("person_slices",$columns,1,$table_options);
-
- foreach( $slices as $slice ) {
- $slice_name= $slice['name'];
- $slice_id= $slice['slice_id'];
- plc_table_row_start();
- plc_table_cell(l_slice_t($slice_id,$slice_name));
- plc_table_row_end();
- }
- plc_table_end($table_options);
- }
-
- plc_peer_block_end();
-
- }
-
// Print footer
include 'plc_footer.php';
//print header
require_once 'plc_drupal.php';
-//set default
-drupal_set_title('Persons');
-include 'plc_header.php';
// Common functions
require_once 'plc_functions.php';
-require_once 'plc_sorts.php';
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
+$known_actions=array();
+////////////////////////////////////////////////////////////
+// interface :
+// (*) use POST
+// (*) set 'action' to one of the following
+$known_actions []= "add-person-to-site";
+// expects: person_id & site_id
+$known_actions []= "remove-person-from-site";
+// expects: person_id & site_ids
+$known_actions []= "remove-roles-from-person";
+// expects: person_id & role_ids
+$known_actions []= "add-role-to-person";
+// expects: role_person_id & id
+$known_actions []= "enable-person";
+// expects: person_id
+$known_actions []= "disable-person";
+// expects: person_id
+$known_actions []= "become-person";
+// expects: person_id
+$known_actions []= "delete-person";
+// expects: person_id
+$known_actions []= "delete-keys";
+// expects: key_ids & person_id (for redirecting to the person's page)
+$known_actions []= "upload-key";
+// expects: person_id & $_FILES['key']
//////////////////////////////
-// get person id
-if( $_POST['person_id'] )
- $person_id= $_POST['person_id'];
-
-
-//////////////////// add in site
-if( $_POST['site_add'] ) {
- $site_id= $_POST['site_add'];
-
- $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
- header( "location: index.php?id=$person_id" );
- exit();
-
-}
-
-//////////////////// remove from sites
-if ( $_POST['Remove_Sites']){
- if( $_POST['rem_site'] ) {
- foreach( $_POST['rem_site'] as $site_id ) {
- $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
- }
- header( "location: index.php?id=$person_id" );
- exit();
- }else{
- echo "<h3><span class='plc-warning'>Please select one or more Sites to remove.<br /></h3> </span>\n";
- echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
- return;
- }
-}
-
-//////////////////// remove roles
-// remove role
-if ( $_POST['Remove_Roles']){
- if($_POST['rem_role']) {
- $rem_ids= $_POST['rem_role'];
- foreach( $rem_ids as $role_id ) {
- $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+// sometimes we don't set 'action', but use the submit button name instead
+// so if 'action' not set, see if $_POST has one of the actions as a key
+if ($_POST['action'])
+ $action=$_POST['action']
+else
+ foreach ($known_actions as $known_action)
+ if ($_POST[$known_action]) {
+ $action=$known_action;
+ break;
}
- header( "location: index.php?id=$person_id" );
- exit();
- }else{
- echo "<h3><span class='plc-warning'>Please select one or more Roles to remove.<br /></h3> </span>\n";
- echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
- }
-}
-
-//////////////////// add roles
-if( $_POST['add_role'] ) {
- $role_id= $_POST['add_role'];
-
- $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
-
- header( "location: index.php?id=$person_id" );
- exit();
-}
-//////////////////// enable
-// enable person
-if ( $_GET['enab_id'] ) {
- $per_id= $_GET['enab_id'];
+//
+$person_id = $_POST['person_id']; // usually needed
- $fields= array( "enabled"=>true );
-
- $api->UpdatePerson( intval( $per_id ), $fields );
-
- header( "location: index.php?id=$per_id" );
- exit();
-
-}
-
-//////////////////// disable person
-if( $_GET['dis_id'] ) {
- $per_id= $_GET['dis_id'];
-
- $fields= array( "enabled"=>false );
+if ( ! $action ) {
+ drupal_set_message ("person_actions.php: action not set");
+ return;
+ }
- $api->UpdatePerson( intval( $per_id ), $fields );
+switch ($action) {
- header( "location: index.php?id=$per_id" );
- exit();
-
-}
+ case 'add-person-to-site': {
+ $site_id = $_POST['site_id'];
+ $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
+ header( "location: " . l_person($person_id));
+ exit();
+ }
-// if action exists figure out what to do
-if( $_POST['action'] ) {
+ case 'remove-person-from-sites': {
+ $site_ids = $_POST['site_ids'];
+ if ( ! $site_ids) {
+ drupal_set_message("action=$action - No site selected");
+ return;
+ }
+ foreach ( $site_ids as $site_id ) {
+ $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
+ }
+ header( "location: " . l_person($person_id));
+ exit();
+ }
- // depending on action, run function
- switch( $_POST['action'] ) {
- case "delete":
- header( "location: person_actions.php?del_id=$person_id" );
- exit();
- break;
- case "disable":
- header( "location: person_actions.php?dis_id=$person_id" );
- exit();
- break;
- case "enable":
- header( "location: person_actions.php?enab_id=$person_id" );
- exit();
- break;
- case "su":
- plc_debug('plc',$plc);
- $plc->BecomePerson (intval($person_id));
- header ( "location: index.php" );
- break;
- }
+ case 'remove-roles-from-person' : {
+ $role_ids=$_POST['role_ids'];
+ if ( ! $role_ids) {
+ drupal_set_message("action=$action - No role selected");
+ return;
+ }
+ foreach( $role_ids as $role_id) {
+ $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+ }
+ header( "location: " . l_person($person_id));
+ exit();
+ }
+
+ case 'add-role-to-person' : {
+ $role_id=$_POST['role_id'];
+ $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
+ header( "location: " . l_person($person_id));
+ exit();
+ }
-}
+ case 'enable-person' : {
+ $fields = array( "enabled"=>true );
+ $api->UpdatePerson( intval( $person_id ), $fields );
+ header( "location: " . l_person($person_id));
+ exit();
+ }
-//////////////////// delete person
-if( $_GET['per_id'] ) {
- $per_id= $_GET['per_id'];
+ case 'disable-person' : {
+ $fields = array( "enabled"=>false );
+ $api->UpdatePerson( intval( $person_id ), $fields );
+ header( "location: " . l_person($person_id));
+ exit();
+ }
- $api->DeletePerson( intval( $per_id ) );
+ case 'become-person' : {
+ $plc->BecomePerson (intval($person_id));
+ header ("location: " . l_persons());
+ exit();
+ }
- header( "location: index.php" );
+ case 'delete-person' : {
+ $api->DeletePerson( intval( $person_id ) );
+ header( "location: " . l_persons() );
exit();
}
-//delete a key
-if ( $_POST['Remove_keys'] ){
- if( $_POST['rem_key'] ) {
- $key_ids= $_POST['rem_key'];
-
- foreach( $key_ids AS $key_id ) {
- $api->DeleteKey( intval( $key_id ) );
- }
- header( "location: index.php?id=$person_id" );
- exit();
- }else{
- echo "<h3><span class='plc-warning'>Please select one or more keys to remove.<br /></h3> </span>\n";
- echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
- }
+ case 'delete-keys' : {
+ $key_ids=$_POST['key_ids'];
+ if ( ! $key_ids) {
+ drupal_set_message("action=$action - No key selected");
+ return;
+ }
+ foreach( $key_ids as $key_id ) {
+ $api->DeleteKey( intval( $key_id ) );
+ }
+ header( "location: " . l_person($person_id));
+ exit();
}
-// upload a key if the user submitted one
-if ( $_POST['Upload']){
- if( isset( $_FILES['key'] ) ) {
- $key_file= $_FILES['key']['tmp_name'];
- if( $key_file ){
- $fp = fopen( $key_file, "r" );
- $key = "";
- if( $fp ) {
- // opened the key file, read the one line of contents
- // The POST operation always creates a file even if the filename
- // the user specified was garbage. If there was some problem
- // with the source file, we'll get a zero length read here.
- $key = fread($fp, filesize($key_file));
- fclose($fp);
-
- $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
-
- if (!$key_id){
- $error= $api->error();
- echo "<h3><span class='plc-warning'> Please verify your SSH file content.<br /></h3> </span>\n";
- print '<br /><div class="messages error">' . $error . '</div>';
- echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
- }
- else{
- header( "location: index.php?id=$person_id" );
- exit();
- }
- }else {
- $error= "Unable to open key file.";
- print '<div class="messages error">' . $error . '</div>';
- }
- }else{
- echo "<h3><span class='plc-warning'>Please select a valid SSH key file to upload.<br /></h3> </span>\n";
- echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
- }
- }
+ case 'upload-key' : {
+ if ( ! isset( $_FILES['key'] ) ) {
+ drupal_set_message ("action=$action, no key file set");
+ return;
+ }
+
+ $key_file= $_FILES['key']['tmp_name'];
+ if ( ! $key_file ) {
+ plc_error("Please select a valid SSH key file to upload");
+ return;
+ }
+ $fp = fopen( $key_file, "r" );
+ $key = "";
+ if( ! $fp ) {
+ plc_error("Unable to open key file $key_file");
+ return;
+ }
+ // opened the key file, read the one line of contents
+ // The POST operation always creates a file even if the filename
+ // the user specified was garbage. If there was some problem
+ // with the source file, we'll get a zero length read here.
+ $key = fread($fp, filesize($key_file));
+ fclose($fp);
+
+ $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
+
+ if ( ! $key_id ) {
+ $error= $api->error();
+ plc_error("$error");
+ plc_error("Please verify your SSH file content");
+ return;
+ }
+ header( "location: " . l_person($person_id));
+ exit();
}
-// delete person confimation
-if( $_GET['del_id'] ) {
- $person_id= $_GET['del_id'];
-
- // get person info from API
- $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) );
-
- // start form
- echo "<form action='person_actions.php?per_id=$person_id' method=post>\n";
-
- // show delete confirmation
- echo "<h2>Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."</h2>\n";
- echo "<p>Are you sure you want to delete this user?\n";
-
- echo "<table><tbody>\n";
- echo "<tr><th>Email: </th><td> ". $person_info[0]['email'] ."</td></tr>\n";
- echo "<tr><th>Roles: </th><td> ";
-
- foreach( $person_info[0]['roles'] as $role ) {
- echo "$role<br />\n";
- }
-
- echo "</td></tr>\n";
-
- echo "</tbody></table>\n";
- echo "<p><input type=submit value='Delete User' name='delete'>\n";
- echo "</form>\n";
-
-
-}
+ case 'debug': {
+ plc_debug('GET',$_GET);
+ plc_debug('POST',$_POST);
+ plc_debug('FILES',$_FILES);
+ return;
+ }
-// Print footer
-include 'plc_footer.php';
+ default: {
+ plc_error ("Unknown action $action in person_actions.php");
+ return;
+ }
+ }
?>