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-sites";
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");
59 plc_debug('POST',$_POST);
65 case 'add-person-to-site': {
66 $site_id = $_POST['site_id'];
67 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
68 header( "location: " . l_person($person_id));
72 case 'remove-person-from-sites': {
73 $site_ids = $_POST['site_ids'];
75 drupal_set_message("action=$action - No site selected");
78 foreach ( $site_ids as $site_id ) {
79 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
81 header( "location: " . l_person($person_id));
85 case 'remove-roles-from-person' : {
86 $role_ids=$_POST['role_ids'];
88 drupal_set_message("action=$action - No role selected");
91 foreach( $role_ids as $role_id) {
92 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
94 header( "location: " . l_person($person_id));
98 case 'add-role-to-person' : {
99 $role_id=$_POST['role_id'];
100 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
101 header( "location: " . l_person($person_id));
105 case 'enable-person' : {
106 $fields = array( "enabled"=>true );
107 $api->UpdatePerson( intval( $person_id ), $fields );
108 header( "location: " . l_person($person_id));
112 case 'disable-person' : {
113 $fields = array( "enabled"=>false );
114 $api->UpdatePerson( intval( $person_id ), $fields );
115 header( "location: " . l_person($person_id));
119 case 'become-person' : {
120 $plc->BecomePerson (intval($person_id));
121 header ("location: " . l_persons());
125 case 'delete-person' : {
126 $api->DeletePerson( intval( $person_id ) );
127 header( "location: " . l_persons() );
131 case 'delete-keys' : {
132 $key_ids=$_POST['key_ids'];
134 drupal_set_message("action=$action - No key selected");
137 foreach( $key_ids as $key_id ) {
138 $api->DeleteKey( intval( $key_id ) );
140 header( "location: " . l_person($person_id));
144 case 'upload-key' : {
145 if ( ! isset( $_FILES['key'] ) ) {
146 drupal_set_message ("action=$action, no key file set");
150 $key_file= $_FILES['key']['tmp_name'];
152 plc_error("Please select a valid SSH key file to upload");
155 $fp = fopen( $key_file, "r" );
158 plc_error("Unable to open key file $key_file");
161 // opened the key file, read the one line of contents
162 // The POST operation always creates a file even if the filename
163 // the user specified was garbage. If there was some problem
164 // with the source file, we'll get a zero length read here.
165 $key = fread($fp, filesize($key_file));
168 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
171 $error= $api->error();
173 plc_error("Please verify your SSH file content");
176 header( "location: " . l_person($person_id));
181 plc_debug('GET',$_GET);
182 plc_debug('POST',$_POST);
183 plc_debug('FILES',$_FILES);
188 plc_error ("Unknown action $action in person_actions.php");