4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
14 require_once 'plc_functions.php';
16 $known_actions=array();
17 ////////////////////////////////////////////////////////////
20 // (*) set 'action' to one of the following
21 $known_actions []= "add-person-to-site";
22 // expects: person_id & site_id
23 $known_actions []= "remove-person-from-site";
24 // expects: person_id & site_ids
25 $known_actions []= "remove-roles-from-person";
26 // expects: person_id & role_ids
27 $known_actions []= "add-role-to-person";
28 // expects: role_person_id & id
29 $known_actions []= "enable-person";
31 $known_actions []= "disable-person";
33 $known_actions []= "become-person";
35 $known_actions []= "delete-person";
37 $known_actions []= "delete-keys";
38 // expects: key_ids & person_id (for redirecting to the person's page)
39 $known_actions []= "upload-key";
40 // expects: person_id & $_FILES['key']
42 //////////////////////////////
43 // sometimes we don't set 'action', but use the submit button name instead
44 // so if 'action' not set, see if $_POST has one of the actions as a key
46 $action=$_POST['action'];
48 foreach ($known_actions as $known_action)
49 if ($_POST[$known_action]) {
50 $action=$known_action;
55 $person_id = $_POST['person_id']; // usually needed
58 drupal_set_message ("person_actions.php: action not set");
64 case 'add-person-to-site': {
65 $site_id = $_POST['site_id'];
66 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
67 header( "location: " . l_person($person_id));
71 case 'remove-person-from-sites': {
72 $site_ids = $_POST['site_ids'];
74 drupal_set_message("action=$action - No site selected");
77 foreach ( $site_ids as $site_id ) {
78 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
80 header( "location: " . l_person($person_id));
84 case 'remove-roles-from-person' : {
85 $role_ids=$_POST['role_ids'];
87 drupal_set_message("action=$action - No role selected");
90 foreach( $role_ids as $role_id) {
91 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
93 header( "location: " . l_person($person_id));
97 case 'add-role-to-person' : {
98 $role_id=$_POST['role_id'];
99 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
100 header( "location: " . l_person($person_id));
104 case 'enable-person' : {
105 $fields = array( "enabled"=>true );
106 $api->UpdatePerson( intval( $person_id ), $fields );
107 header( "location: " . l_person($person_id));
111 case 'disable-person' : {
112 $fields = array( "enabled"=>false );
113 $api->UpdatePerson( intval( $person_id ), $fields );
114 header( "location: " . l_person($person_id));
118 case 'become-person' : {
119 $plc->BecomePerson (intval($person_id));
120 header ("location: " . l_persons());
124 case 'delete-person' : {
125 $api->DeletePerson( intval( $person_id ) );
126 header( "location: " . l_persons() );
130 case 'delete-keys' : {
131 $key_ids=$_POST['key_ids'];
133 drupal_set_message("action=$action - No key selected");
136 foreach( $key_ids as $key_id ) {
137 $api->DeleteKey( intval( $key_id ) );
139 header( "location: " . l_person($person_id));
143 case 'upload-key' : {
144 if ( ! isset( $_FILES['key'] ) ) {
145 drupal_set_message ("action=$action, no key file set");
149 $key_file= $_FILES['key']['tmp_name'];
151 plc_error("Please select a valid SSH key file to upload");
154 $fp = fopen( $key_file, "r" );
157 plc_error("Unable to open key file $key_file");
160 // opened the key file, read the one line of contents
161 // The POST operation always creates a file even if the filename
162 // the user specified was garbage. If there was some problem
163 // with the source file, we'll get a zero length read here.
164 $key = fread($fp, filesize($key_file));
167 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
170 $error= $api->error();
172 plc_error("Please verify your SSH file content");
175 header( "location: " . l_person($person_id));
180 plc_debug('GET',$_GET);
181 plc_debug('POST',$_POST);
182 plc_debug('FILES',$_FILES);
187 plc_error ("Unknown action $action in person_actions.php");