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 plc_redirect (l_person($person_id));
83 case 'remove-person-from-sites': {
84 $site_ids = $_POST['site_ids'];
86 drupal_set_message("action=$action - No site selected");
89 foreach ( $site_ids as $site_id ) {
90 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
92 plc_redirect (l_person($person_id));
95 case 'remove-roles-from-person' : {
96 $role_ids=$_POST['role_ids'];
98 drupal_set_message("action=$action - No role selected");
101 foreach( $role_ids as $role_id) {
102 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
104 plc_redirect (l_person($person_id));
107 case 'add-role-to-person' : {
108 $role_id=$_POST['role_id'];
109 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
110 plc_redirect (l_person($person_id));
113 case 'enable-person' : {
114 $fields = array( "enabled"=>true );
115 $api->UpdatePerson( intval( $person_id ), $fields );
116 plc_redirect (l_person($person_id));
119 case 'disable-person' : {
120 $fields = array( "enabled"=>false );
121 $api->UpdatePerson( intval( $person_id ), $fields );
122 plc_redirect (l_person($person_id));
125 case 'become-person' : {
126 $plc->BecomePerson (intval($person_id));
127 plc_redirect (l_persons());
130 case 'delete-person' : {
131 $api->DeletePerson( intval( $person_id ) );
132 plc_redirect (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 plc_redirect(l_person($person_id));
147 case 'upload-key' : {
148 if ( ! isset( $_FILES['key'] ) ) {
149 drupal_set_message ("action=$action, no key file set");
153 $key_file= $_FILES['key']['tmp_name'];
155 plc_error("Please select a valid SSH key file to upload");
158 $fp = fopen( $key_file, "r" );
161 plc_error("Unable to open key file $key_file");
164 // opened the key file, read the one line of contents
165 // The POST operation always creates a file even if the filename
166 // the user specified was garbage. If there was some problem
167 // with the source file, we'll get a zero length read here.
168 $key = fread($fp, filesize($key_file));
171 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
174 $error= $api->error();
176 plc_error("Please verify your SSH file content");
179 plc_redirect(l_person($person_id));
182 case 'update-tag-type': {
184 $tag_type_id= intval( $_POST['tag_type_id'] );
185 $name = $_POST['name'];
186 $min_role_id= intval( $_POST['min_role_id'] );
187 $description= $_POST['description'];
188 $category= $_POST['category'];
190 // make tag_type_fields dict
191 $tag_type_fields= array( "min_role_id" => $min_role_id,
193 "description" => $description,
194 "category" => $category,
198 $api->UpdateTagType( $tag_type_id, $tag_type_fields );
200 plc_redirect(l_tag($tag_type_id));
203 case 'add-tag-type': {
205 $name = $_POST['name'];
206 $min_role_id= intval( $_POST['min_role_id'] );
207 $description= $_POST['description'];
208 $category= $_POST['category'];
210 // make tag_type_fields dict
211 $tag_type_fields= array( "min_role_id" => $min_role_id,
213 "description" => $description,
214 "category" => $category,
218 $id=$api->AddTagType( $tag_type_fields );
219 drupal_set_message ("tag type $id created");
221 plc_redirect( l_tag($id));
224 case 'delete-site': {
225 $site_id = intval($_POST['site_id']);
226 if ($api->DeleteSite($site_id) ==1)
227 drupal_set_message ("Site $site_id deleted");
229 drupal_set_error("Failed to delete site $site_id");
230 plc_redirect (l_sites());
233 case 'expire-all-slices-in-site': {
235 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
238 //// old code from sites/expire.php
239 $sites = $api->GetSites( array( intval( $site_id )));
241 // xxx why not 'now?'
242 $expiration= strtotime( $_POST['expires'] );
243 // loop through all slices for site
244 foreach ($site['slice_ids'] as $slice_id) {
245 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
247 // update site to not allow slice creation or renewal
248 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
249 plc_redirect (l_site($site_id));
252 case 'set-tag-on-node': {
254 $node_id = intval($_POST['node_id']);
255 $tag_type_id = intval($_POST['tag_type_id']);
256 $value = $_POST['value'];
258 $tag_types=$api->GetTagTypes(array($tag_type_id));
259 if (count ($tag_types) != 1) {
260 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
262 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
263 if ( count ($tags) == 1) {
265 $tag_id=$tag['node_tag_id'];
266 $result=$api->UpdateNodeTag($tag_id,$value);
268 drupal_set_message ("Updated tag, new value = $value");
270 drupal_set_error ("Could not update tag");
272 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
274 drupal_set_message ("Created tag, new value = $value");
276 drupal_set_error ("Could not create tag");
280 plc_redirect (l_node($node_id));
285 plc_debug('GET',$_GET);
286 plc_debug('POST',$_POST);
287 plc_debug('FILES',$_FILES);
292 plc_error ("Unknown action $action in actions.php");