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']
41 $known_actions []= "update-tag-type";
42 // expects: tag_type_id & name & description & category & min_role_id
43 $known_actions []= "add-tag-type";
44 // expects: tag_type_id & name & description & category & min_role_id
46 //////////////////////////////
47 // sometimes we don't set 'action', but use the submit button name instead
48 // so if 'action' not set, see if $_POST has one of the actions as a key
50 $action=$_POST['action'];
52 foreach ($known_actions as $known_action)
53 if ($_POST[$known_action]) {
54 $action=$known_action;
59 $person_id = $_POST['person_id']; // usually needed
62 drupal_set_message ("actions.php: action not set");
63 plc_debug('POST',$_POST);
69 case 'add-person-to-site': {
70 $site_id = $_POST['site_id'];
71 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
72 header( "location: " . l_person($person_id));
76 case 'remove-person-from-sites': {
77 $site_ids = $_POST['site_ids'];
79 drupal_set_message("action=$action - No site selected");
82 foreach ( $site_ids as $site_id ) {
83 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
85 header( "location: " . l_person($person_id));
89 case 'remove-roles-from-person' : {
90 $role_ids=$_POST['role_ids'];
92 drupal_set_message("action=$action - No role selected");
95 foreach( $role_ids as $role_id) {
96 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
98 header( "location: " . l_person($person_id));
102 case 'add-role-to-person' : {
103 $role_id=$_POST['role_id'];
104 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
105 header( "location: " . l_person($person_id));
109 case 'enable-person' : {
110 $fields = array( "enabled"=>true );
111 $api->UpdatePerson( intval( $person_id ), $fields );
112 header( "location: " . l_person($person_id));
116 case 'disable-person' : {
117 $fields = array( "enabled"=>false );
118 $api->UpdatePerson( intval( $person_id ), $fields );
119 header( "location: " . l_person($person_id));
123 case 'become-person' : {
124 $plc->BecomePerson (intval($person_id));
125 header ("location: " . l_persons());
129 case 'delete-person' : {
130 $api->DeletePerson( intval( $person_id ) );
131 header( "location: " . l_persons() );
135 case 'delete-keys' : {
136 $key_ids=$_POST['key_ids'];
138 drupal_set_message("action=$action - No key selected");
141 foreach( $key_ids as $key_id ) {
142 $api->DeleteKey( intval( $key_id ) );
144 header( "location: " . l_person($person_id));
148 case 'upload-key' : {
149 if ( ! isset( $_FILES['key'] ) ) {
150 drupal_set_message ("action=$action, no key file set");
154 $key_file= $_FILES['key']['tmp_name'];
156 plc_error("Please select a valid SSH key file to upload");
159 $fp = fopen( $key_file, "r" );
162 plc_error("Unable to open key file $key_file");
165 // opened the key file, read the one line of contents
166 // The POST operation always creates a file even if the filename
167 // the user specified was garbage. If there was some problem
168 // with the source file, we'll get a zero length read here.
169 $key = fread($fp, filesize($key_file));
172 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
175 $error= $api->error();
177 plc_error("Please verify your SSH file content");
180 header( "location: " . l_person($person_id));
184 case 'update-tag-type': {
186 $tag_type_id= intval( $_POST['tag_type_id'] );
187 $name = $_POST['name'];
188 $min_role_id= intval( $_POST['min_role_id'] );
189 $description= $_POST['description'];
190 $category= $_POST['category'];
192 // make tag_type_fields dict
193 $tag_type_fields= array( "min_role_id" => $min_role_id,
195 "description" => $description,
196 "category" => $category,
200 $api->UpdateTagType( $tag_type_id, $tag_type_fields );
202 header( "location: " . l_tag($tag_type_id));
206 case 'add-tag-type': {
208 $name = $_POST['name'];
209 $min_role_id= intval( $_POST['min_role_id'] );
210 $description= $_POST['description'];
211 $category= $_POST['category'];
213 // make tag_type_fields dict
214 $tag_type_fields= array( "min_role_id" => $min_role_id,
216 "description" => $description,
217 "category" => $category,
221 $id=$api->AddTagType( $tag_type_fields );
222 drupal_set_message ("tag type $id created");
224 header( "location: " . l_tag($id));
229 plc_debug('GET',$_GET);
230 plc_debug('POST',$_POST);
231 plc_debug('FILES',$_FILES);
236 plc_error ("Unknown action $action in actions.php");