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
45 $known_actions []= "delete-site";
47 $known_actions []= "expire-all-slices-in-site";
49 $known_actions []= "set-tag-on-node";
50 // expects: node_id tagname value
52 //////////////////////////////
53 // sometimes we don't set 'action', but use the submit button name instead
54 // so if 'action' not set, see if $_POST has one of the actions as a key
56 $action=$_POST['action'];
58 foreach ($known_actions as $known_action)
59 if ($_POST[$known_action]) {
60 $action=$known_action;
67 $person_id = $_POST['person_id']; // usually needed
70 drupal_set_message ("actions.php: action not set");
71 plc_debug('POST',$_POST);
77 case 'add-person-to-site': {
78 $site_id = $_POST['site_id'];
79 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
80 header( "location: " . l_person($person_id));
84 case 'remove-person-from-sites': {
85 $site_ids = $_POST['site_ids'];
87 drupal_set_message("action=$action - No site selected");
90 foreach ( $site_ids as $site_id ) {
91 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
93 header( "location: " . l_person($person_id));
97 case 'remove-roles-from-person' : {
98 $role_ids=$_POST['role_ids'];
100 drupal_set_message("action=$action - No role selected");
103 foreach( $role_ids as $role_id) {
104 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
106 header( "location: " . l_person($person_id));
110 case 'add-role-to-person' : {
111 $role_id=$_POST['role_id'];
112 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
113 header( "location: " . l_person($person_id));
117 case 'enable-person' : {
118 $fields = array( "enabled"=>true );
119 $api->UpdatePerson( intval( $person_id ), $fields );
120 header( "location: " . l_person($person_id));
124 case 'disable-person' : {
125 $fields = array( "enabled"=>false );
126 $api->UpdatePerson( intval( $person_id ), $fields );
127 header( "location: " . l_person($person_id));
131 case 'become-person' : {
132 $plc->BecomePerson (intval($person_id));
133 header ("location: " . l_persons());
137 case 'delete-person' : {
138 $api->DeletePerson( intval( $person_id ) );
139 header( "location: " . l_persons() );
143 case 'delete-keys' : {
144 $key_ids=$_POST['key_ids'];
146 drupal_set_message("action=$action - No key selected");
149 foreach( $key_ids as $key_id ) {
150 $api->DeleteKey( intval( $key_id ) );
152 header( "location: " . l_person($person_id));
156 case 'upload-key' : {
157 if ( ! isset( $_FILES['key'] ) ) {
158 drupal_set_message ("action=$action, no key file set");
162 $key_file= $_FILES['key']['tmp_name'];
164 plc_error("Please select a valid SSH key file to upload");
167 $fp = fopen( $key_file, "r" );
170 plc_error("Unable to open key file $key_file");
173 // opened the key file, read the one line of contents
174 // The POST operation always creates a file even if the filename
175 // the user specified was garbage. If there was some problem
176 // with the source file, we'll get a zero length read here.
177 $key = fread($fp, filesize($key_file));
180 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
183 $error= $api->error();
185 plc_error("Please verify your SSH file content");
188 header( "location: " . l_person($person_id));
192 case 'update-tag-type': {
194 $tag_type_id= intval( $_POST['tag_type_id'] );
195 $name = $_POST['name'];
196 $min_role_id= intval( $_POST['min_role_id'] );
197 $description= $_POST['description'];
198 $category= $_POST['category'];
200 // make tag_type_fields dict
201 $tag_type_fields= array( "min_role_id" => $min_role_id,
203 "description" => $description,
204 "category" => $category,
208 $api->UpdateTagType( $tag_type_id, $tag_type_fields );
210 header( "location: " . l_tag($tag_type_id));
214 case 'add-tag-type': {
216 $name = $_POST['name'];
217 $min_role_id= intval( $_POST['min_role_id'] );
218 $description= $_POST['description'];
219 $category= $_POST['category'];
221 // make tag_type_fields dict
222 $tag_type_fields= array( "min_role_id" => $min_role_id,
224 "description" => $description,
225 "category" => $category,
229 $id=$api->AddTagType( $tag_type_fields );
230 drupal_set_message ("tag type $id created");
232 header( "location: " . l_tag($id));
236 case 'delete-site': {
237 $site_id = intval($_POST['site_id']);
238 if ($api->DeleteSite($site_id) ==1)
239 drupal_set_message ("Site $site_id deleted");
241 drupal_set_error("Failed to delete site $site_id");
242 header ("location: " . l_sites());
246 case 'expire-all-slices-in-site': {
248 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
251 //// old code from sites/expire.php
252 $sites = $api->GetSites( array( intval( $site_id )));
254 // xxx why not 'now?'
255 $expiration= strtotime( $_POST['expires'] );
256 // loop through all slices for site
257 foreach ($site['slice_ids'] as $slice_id) {
258 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
260 // update site to not allow slice creation or renewal
261 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
262 header ("location: " . l_site($site_id));
266 case 'set-tag-on-node': {
268 $node_id = intval($_POST['node_id']);
269 $tag_type_id = intval($_POST['tag_type_id']);
270 $value = $_POST['value'];
272 $tag_types=$api->GetTagTypes(array($tag_type_id));
273 if (count ($tag_types) != 1) {
274 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
276 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
277 if ( count ($tags) == 1) {
279 $tag_id=$tag['node_tag_id'];
280 $result=$api->UpdateNodeTag($tag_id,$value);
282 drupal_set_message ("Updated tag, new value = $value");
284 drupal_set_error ("Could not update tag");
286 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
288 drupal_set_message ("Created tag, new value = $value");
290 drupal_set_error ("Could not create tag");
294 header ("location: " . l_node($node_id));
300 plc_debug('GET',$_GET);
301 plc_debug('POST',$_POST);
302 plc_debug('FILES',$_FILES);
307 plc_error ("Unknown action $action in actions.php");