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 //////////////////////////////////////// persons
22 $known_actions []= "add-person-to-site";
23 // expects: person_id & site_id
24 $known_actions []= "remove-person-from-sites";
25 // expects: person_id & site_ids
26 $known_actions []= "remove-roles-from-person";
27 // expects: person_id & role_ids
28 $known_actions []= "add-role-to-person";
29 // expects: role_person_id & id
30 $known_actions []= "enable-person";
32 $known_actions []= "disable-person";
34 $known_actions []= "become-person";
36 $known_actions []= "delete-person";
38 $known_actions []= "delete-keys";
39 // expects: key_ids & person_id (for redirecting to the person's page)
40 $known_actions []= "upload-key";
41 // expects: person_id & $_FILES['key']
42 $known_actions []= "update-person";
43 // expects: person_id & first_name last_name title email phone url bio + [password1 password2]
45 //////////////////////////////////////// nodes
46 $known_actions []= "node-boot-state";
47 // expects: node_id boot_state
48 $known_actions []= "delete-node";
50 $known_actions []= "update-node";
51 // expects: node_id, hostname, model
52 $known_actions []= "attach-pcu";
53 // expects: node_id, pcu_id, port (pcu_id <0 means detach)
55 //////////////////////////////////////// interfaces
56 $known_actions []= "delete-interfaces";
57 // expects: interface_ids
58 $known_actions []="add-interface";
59 // expects: node_id & interface details
60 $known_actions []="new-interface";
62 $known_actions []="update-interface";
63 // expects: interface_id & interface details
65 //////////////////////////////////////// sites
66 $known_actions []= "delete-site";
68 $known_actions []= "expire-all-slices-in-site";
70 $known_actions []= "update-site";
71 // expects: site_id & name abbreviated_name url latitude longitude [login_base max_slices]
73 //////////////////////////////////////// slices
74 $known_actions []= "delete-slice";
76 $known_actions []= "update-slice";
77 // expects: slice_id, name, description, url
78 $known_actions []= "renew-slice";
79 // expects: slice_id & expires
80 $known_actions []= 'remove-persons-from-slice';
81 // expects: slice_id & person_ids
82 $known_actions []= 'add-persons-in-slice';
83 // expects: slice_id & person_ids
84 $known_actions []= 'remove-nodes-from-slice';
85 // expects: slice_id & node_ids
86 $known_actions []= 'add-nodes-in-slice';
87 // expects: slice_id & node_ids
88 $known_actions []= 'delete-slice-tags';
89 // expects: slice_tag_id
90 $known_actions []= 'add-slice-tag';
91 // expects: slice_id & tag_type_id & node_id & nodegroup_id
93 //////////////////////////////////////// tag types
94 $known_actions []= "update-tag-type";
95 // expects: tag_type_id & name & description & category & min_role_id
96 $known_actions []= "add-tag-type";
97 // expects: tag_type_id & tagname & description & category & min_role_id
98 $known_actions []= "delete-tag-types";
99 // expects: tag_type_ids
101 //////////////////////////////////////// tags
102 $known_actions []= "set-tag-on-node";
103 // expects: node_id tagname value
104 $known_actions []= "set-tag-on-interface";
105 // expects: interface_id tagname value
106 $known_actions []= "delete-node-tags";
107 // expects: node_id & node_tag_ids
108 $known_actions []= "delete-interface-tags";
109 // expects: interface_id & interface_tag_ids
111 //////////////////////////////////////// nodegroups
112 $known_actions []= "update-nodegroup";
113 // expects nodegroup_id groupname value
114 $known_actions []= "add-nodegroup";
115 // expects groupname, tag_type_id, value
116 $known_actions []= 'delete-nodegroups';
117 // expects nodegroup_ids
119 ////////////////////////////////////////////////////////////
120 $interface_details= array ('method','type', 'ip', 'gateway', 'network',
121 'broadcast', 'netmask', 'dns1', 'dns2',
122 'hostname', 'mac', 'bwlimit' );
124 //////////////////////////////
125 // sometimes we don't set 'action', but use the submit button name instead
126 // so if 'action' not set, see if $_POST has one of the actions as a key
127 if ($_POST['action'])
128 $action=$_POST['action'];
130 foreach ($known_actions as $known_action)
131 if ($_POST[$known_action]) {
132 $action=$known_action;
136 //uncomment for debugging incoming data
139 $person_id = $_POST['person_id']; // usually needed
142 drupal_set_message ("actions.php: action not set or not in known_actions");
143 plc_debug('POST',$_POST);
149 case 'add-person-to-site': {
150 $site_id = $_POST['site_id'];
151 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
152 plc_redirect (l_person($person_id));
155 case 'remove-person-from-sites': {
156 $site_ids = $_POST['site_ids'];
158 drupal_set_message("action=$action - No site selected");
161 foreach ( $site_ids as $site_id ) {
162 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
164 plc_redirect (l_person($person_id));
167 case 'remove-roles-from-person' : {
168 $role_ids=$_POST['role_ids'];
170 drupal_set_error("You have not selected role(s) to remove");
172 foreach( $role_ids as $role_id)
173 if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 )
174 drupal_set_error ("Could not remove role $role_id from person $person_id");
176 plc_redirect (l_person_roles($person_id));
179 case 'add-role-to-person' : {
180 $role_id=$_POST['role_id'];
182 drupal_set_error ("You have not selected a role to add");
183 } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
184 drupal_set_error("Could not add role $role_id to person $person_id");
186 plc_redirect (l_person_roles($person_id));
189 case 'enable-person' : {
190 $fields = array( "enabled"=>true );
191 $api->UpdatePerson( intval( $person_id ), $fields );
192 plc_redirect (l_person($person_id));
195 case 'disable-person' : {
196 $fields = array( "enabled"=>false );
197 $api->UpdatePerson( intval( $person_id ), $fields );
198 plc_redirect (l_person($person_id));
201 case 'become-person' : {
202 $plc->BecomePerson (intval($person_id));
203 plc_redirect (l_person(intval($person_id)));
206 case 'delete-person' : {
207 $api->DeletePerson( intval( $person_id ) );
208 plc_redirect (l_persons());
211 case 'delete-keys' : {
212 $key_ids=$_POST['key_ids'];
214 drupal_set_message("action=$action - No key selected");
219 foreach( $key_ids as $key_id ) {
220 if ($api->DeleteKey( intval( $key_id )) != 1)
226 drupal_set_message ("Deleted $counter key(s)");
228 drupal_set_error ("Could not delete all selected keys, only $counter were removed");
229 plc_redirect(l_person($person_id));
233 case 'upload-key' : {
234 if ( ! isset( $_FILES['key'] ) ) {
235 drupal_set_message ("action=$action, no key file set");
239 $key_file= $_FILES['key']['tmp_name'];
241 plc_error("Please select a valid SSH key file to upload");
244 $fp = fopen( $key_file, "r" );
247 plc_error("Unable to open key file $key_file");
250 // opened the key file, read the one line of contents
251 // The POST operation always creates a file even if the filename
252 // the user specified was garbage. If there was some problem
253 // with the source file, we'll get a zero length read here.
254 $key = fread($fp, filesize($key_file));
257 $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
260 drupal_set_message ("New key added");
262 drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
264 plc_redirect(l_person($person_id));
267 case 'update-person': {
268 $person_id=$_POST['person_id'];
269 // attempt to update this person
270 $first_name= $_POST['first_name'];
271 $last_name= $_POST['last_name'];
272 $title= $_POST['title'];
273 $email= $_POST['email'];
274 $phone= $_POST['phone'];
276 $bio= str_replace("\r", "", $_POST['bio']);
277 $password1= $_POST['password1'];
278 $password2= $_POST['password2'];
280 if( $password1 != $password2 ) {
281 drupal_set_error ("The passwords do not match");
282 plc_redirect(l_person($person_id));
286 $fields['first_name']= $first_name;
287 $fields['last_name']= $last_name;
288 $fields['title']= $title;
289 $fields['email']= $email;
290 $fields['phone']= $phone;
291 $fields['url']= $url;
292 $fields['bio']= $bio;
294 if ( $password1 != "" )
295 $fields['password']= $password1;
297 if ( $api->UpdatePerson( intval( $person_id ), $fields) == 1 )
298 drupal_set_message("$first_name $last_name updated");
300 drupal_set_error ("Could not update person $person_id" . $api->error());
302 plc_redirect(l_person($person_id));
306 //////////////////////////////////////////////////////////// nodes
307 case 'node-boot-state': {
308 $node_id=intval($_POST['node_id']);
309 $boot_state=$_POST['boot_state'];
310 $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) );
312 drupal_set_message("boot state updated");
313 plc_redirect (l_node($node_id));
315 drupal_set_error("Could not set boot_state '$boot_state'");
320 case 'delete-node': {
321 $node_id=intval($_POST['node_id']);
322 $result=$api->DeleteNode( intval( $node_id ) );
324 drupal_set_message("Node $node_id deleted");
325 plc_redirect (l_nodes());
327 drupal_set_error ("Could not delete node $node_id");
332 case 'update-node': {
333 $node_id=intval($_POST['node_id']);
334 $hostname= $_POST['hostname'];
335 $model= $_POST['model'];
337 $fields= array( "hostname"=>$hostname, "model"=>$model );
338 $api->UpdateNode( $node_id, $fields );
339 $error= $api->error();
341 if( empty( $error ) ) {
342 drupal_set_message("Update node $hostname");
343 plc_redirect(l_node($node_id));
345 drupal_set_error($error);
350 // this code will ensure that at most one PCU gets attached to the node
352 $node_id=intval($_POST['node_id']);
353 $pcu_id=intval($_POST['pcu_id']);
354 $port=intval($_POST['port']);
355 // always start with deleting former PCUs
356 $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
357 $former_pcu_ids = $nodes[0]['pcu_ids'];
358 if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
359 if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1)
360 drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
362 drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
364 // re-attach only if provided pcu_id >=0
366 if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
367 drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
369 drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
371 drupal_set_message ('Detached node from all PCUs');
374 plc_redirect(l_node($node_id));
379 //////////////////////////////////////////////////////////// interfaces
380 case 'delete-interfaces' : {
381 $interface_ids=$_POST['interface_ids'];
382 if ( ! $interface_ids) {
383 drupal_set_message("action=$action - No interface selected");
388 foreach( $interface_ids as $interface_id ) {
389 if ($api->DeleteInterface( intval( $interface_id )) != 1)
395 drupal_set_message ("Deleted $counter interface(s)");
397 drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
398 plc_redirect(l_node($_POST['node_id']));
401 case 'new-interface': {
402 plc_redirect(l_interface_add($_POST['node_id']));
405 case 'add-interface': {
406 $node_id=intval($_POST['node_id']);
407 foreach ($interface_details as $field) {
408 $interface[$field]= $_POST[$field];
409 // these must be integers
410 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
411 if ( empty ($interface[$field]) )
412 unset ($interface[$field]);
414 $interface[$field]= intval( $interface[$field] );
417 $interface_id =$api->AddInterface( $node_id , $interface );
418 if ($interface_id <= 0 ) {
419 drupal_set_error ("Could not create interface");
420 drupal_set_error ($api->error());
422 $ip=$interface['ip'];
423 drupal_set_message ("Interface $ip added into node $node_id");
424 if ($_POST['is-virtual']) {
425 $ifname=$_POST['ifname'];
426 if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0)
427 drupal_set_error ("Could not set tag 'ifname'=$ifname");
429 drupal_set_message ("Set tag 'ifname'=$ifname");
430 $alias=$_POST['alias'];
431 // deafult to interface_id
432 if ( ! $alias ) $alias=strval($interface_id);
433 if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0)
434 drupal_set_error ("Could not set tag 'alias'=$alias");
436 drupal_set_message ("Set tag 'alias'=$alias");
439 plc_redirect (l_node_interfaces($node_id));
442 case 'update-interface': {
443 $interface_id=$_POST['interface_id'];
444 foreach ($interface_details as $field) {
445 $interface[$field]= $_POST[$field];
446 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
447 if ( intval($interface[$field]) != 0 ) {
448 $interface[$field]= intval( $interface[$field]);
449 } elseif ($field=='bwlimit' ) {
450 $interface[$field] = NULL;
454 $result=$api->UpdateInterface( intval( $interface_id ), $interface );
456 drupal_set_message ("Interface $interface_id updated");
458 drupal_set_error ("Could not update interface: " . $api->error());
459 plc_redirect (l_interface($interface_id));
462 //////////////////////////////////////////////////////////// sites
463 case 'delete-site': {
464 $site_id = intval($_POST['site_id']);
465 if ($api->DeleteSite($site_id) ==1)
466 drupal_set_message ("Site $site_id deleted");
468 drupal_set_error("Failed to delete site $site_id");
469 plc_redirect (l_sites());
473 case 'expire-all-slices-in-site': {
475 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
478 //// old code from sites/expire.php
479 $sites = $api->GetSites( array( intval( $site_id )));
481 // xxx why not 'now?'
482 $expiration= strtotime( $_POST['expires'] );
483 // loop through all slices for site
484 foreach ($site['slice_ids'] as $slice_id) {
485 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
487 // update site to not allow slice creation or renewal
488 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
489 plc_redirect (l_site($site_id));
493 case 'update-site': {
494 $site_id=intval($_POST['site_id']);
495 $name= $_POST['name'];
496 $abbreviated_name= $_POST['abbreviated_name'];
498 $latitude= floatval($_POST['latitude']);
499 $longitude= floatval($_POST['longitude']);
500 //$max_slivers= $_POST['max_slivers'];
502 $fields= array( "name" => $name,
503 "abbreviated_name" => $abbreviated_name,
505 "latitude" => floatval( $latitude ),
506 "longitude" => floatval( $longitude ));
508 if ($_POST['login_base'])
509 $fields['login_base'] = $_POST['login_base'];
510 if (isset($_POST['max_slices']))
511 $fields['max_slices'] = intval($_POST['max_slices']);
512 if (isset($_POST['enabled'])) {
513 $fields['enabled'] = (bool)$_POST['enabled'];
516 $retcod=$api->UpdateSite( intval( $site_id ), $fields );
518 drupal_set_message("Site $name updated");
520 drupal_set_error ("Could not update site $site_id");
522 plc_redirect(l_site($site_id));
526 //////////////////////////////////////////////////////////// slices
527 case 'delete-slice': {
528 $slice_id = $_POST['slice_id'];
529 if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
530 drupal_set_message("Slice $slice_id deleted");
531 plc_redirect(l_slices());
533 drupal_set_error("Could not delete slice $slice_id " . $api->error());
538 case 'update-slice': {
539 $slice_id = $_POST['slice_id'];
540 $name = $_POST['name'];
541 $description= $_POST['description'];
544 $fields= array( "description"=>$description, "url"=>$url );
545 $api->UpdateSlice( intval( $slice_id ), $fields );
546 $error= $api->error();
548 if( empty( $error ) ) {
549 drupal_set_message("Update slice $name");
550 plc_redirect(l_slice($slice_id));
552 drupal_set_error($error);
557 case 'renew-slice': {
558 $slice_id = intval ($_POST['slice_id']);
559 $expires = intval ($_POST['expires']);
565 $MAX_FUTURE=$WEEKS*$WEEK;
566 if ( ($expires-$now) > $MAX_FUTURE) {
567 drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
568 plc_redirect(l_slice($slice_id));
570 if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
571 drupal_set_message("Slice renewed");
573 drupal_set_error("Could not update slice $slice_id");
574 plc_redirect(l_slice($slice_id));
578 case 'remove-persons-from-slice': {
579 $slice_id = intval ($_POST['slice_id']);
580 $person_ids = $_POST['person_ids'];
583 $tmp_slices = $api->GetSlices($slice_id, array("name"));
584 if (count($tmp_slices) > 0) {
585 $tmp_slice = $tmp_slices[0];
586 $slice_name = $tmp_slice["name"];
588 $notify_subject = "Removed from slice: " . $slice_name;
589 $notify_body = sprintf("You have been removed from the slice %s.
591 Our support team will be glad to answer any question that you might have.
593 $notify_person_ids = array();
597 foreach( $person_ids as $person_id ) {
598 if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
601 array_push($notify_person_ids, intval($person_id));
606 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
607 drupal_set_message ("Deleted $counter person(s)");
610 drupal_set_error ("Could not delete all selected persons, only $counter were removed");
611 plc_redirect(l_slice($slice_id) . " &show_persons=true");
615 case 'add-persons-in-slice': {
616 $slice_id = intval ($_POST['slice_id']);
617 $person_ids = $_POST['person_ids'];
620 $tmp_slices = $api->GetSlices($slice_id, array("name"));
621 if (count($tmp_slices) > 0) {
622 $tmp_slice = $tmp_slices[0];
623 $slice_name = $tmp_slice["name"];
625 $notify_subject = "Added to slice: " . $slice_name;
626 $notify_body = sprintf("You have been added to the slice %s as a user.
628 You can go to your slice page following the link below:
629 https://%s:%d/db/slices/index.php?id=%d
631 Our support team will be glad to answer any question that you might have.
632 ",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
633 $notify_person_ids = array();
637 foreach ($person_ids as $person_id) {
638 if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
641 array_push($notify_person_ids, intval($person_id));
646 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
647 drupal_set_message ("Added $counter person(s)");
650 drupal_set_error ("Could not add all selected persons, only $counter were added");
651 plc_redirect(l_slice($slice_id) . "&show_persons=true" );
655 case 'remove-nodes-from-slice': {
656 $slice_id = intval ($_POST['slice_id']);
657 $node_ids = array_map("intval",$_POST['node_ids']);
658 $count=count($node_ids);
660 if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1)
661 drupal_set_message ("Removed $count node(s)");
663 drupal_set_error ("Could not remove selected nodes");
664 plc_redirect(l_slice_nodes($slice_id));
668 case 'add-nodes-in-slice': {
669 $slice_id = intval ($_POST['slice_id']);
670 $node_ids = array_map("intval",$_POST['node_ids']);
671 $count=count($node_ids);
672 if ($api->AddSliceToNodes($slice_id,$node_ids) == 1)
673 drupal_set_message ("Added $count node(s)");
675 drupal_set_error ("Could not add all selected nodes");
676 plc_redirect(l_slice_nodes($slice_id));
680 case 'delete-slice-tags': {
681 $slice_id = intval($_POST['slice_id']);
682 $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
685 foreach($slice_tag_ids as $slice_tag_id) {
686 if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
688 drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
693 drupal_set_message ("Deleted $count slice tag(s)");
694 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
698 case 'add-slice-tag': {
699 $slice_id = intval($_POST['slice_id']);
700 $tag_type_id = intval($_POST['tag_type_id']);
701 $value = $_POST['value'];
702 $node_id = intval($_POST['node_id']);
703 $nodegroup_id = intval($_POST['nodegroup_id']);
707 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
708 } elseif ($nodegroup_id) {
709 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
711 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
714 drupal_set_message ("Added slice tag.");
716 drupal_set_error("Could not add slice tag");
717 if ($_POST['sliver_action'])
718 plc_redirect(l_sliver($node_id,$slice_id));
720 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
724 //////////////////////////////////////////////////////////// tag types
726 case 'update-tag-type': {
728 $tag_type_id= intval( $_POST['tag_type_id'] );
729 $tagname = $_POST['tagname'];
730 $min_role_id= intval( $_POST['min_role_id'] );
731 $description= $_POST['description'];
732 $category= $_POST['category'];
734 // make tag_type_fields dict
735 $tag_type_fields= array( "min_role_id" => $min_role_id,
736 "tagname" => $tagname,
737 "description" => $description,
738 "category" => $category,
741 if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1)
742 drupal_set_message ("Tag type $tagname updated");
744 drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
745 plc_redirect(l_tag($tag_type_id));
749 case 'add-tag-type': {
751 $tagname = $_POST['tagname'];
752 $min_role_id= intval( $_POST['min_role_id'] );
753 $description= $_POST['description'];
754 $category= $_POST['category'];
756 // make tag_type_fields dict
757 $tag_type_fields= array( "min_role_id" => $min_role_id,
758 "tagname" => $tagname,
759 "description" => $description,
760 "category" => $category,
764 $tag_type_id=$api->AddTagType( $tag_type_fields );
765 if ($tag_type_id > 0)
766 drupal_set_message ("tag type $tag_type_id created");
768 drupal_set_error ("Could not create tag type $tagname");
769 plc_redirect( l_tags());
773 case 'delete-tag-types': {
774 $tag_type_ids = $_POST['tag_type_ids'];
775 if ( ! $tag_type_ids) {
776 drupal_set_message("action=$action - No tag selected");
781 foreach ($tag_type_ids as $tag_type_id)
782 if ($api->DeleteTagType(intval($tag_type_id)) != 1)
787 drupal_set_message ("Deleted $counter tag(s)");
789 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
790 plc_redirect (l_tags());
794 //////////////////////////////////////// tags
795 case 'set-tag-on-node':
796 case 'set-tag-on-interface': {
799 if ($action == 'set-tag-on-node') $node_mode=true;
802 $node_id = intval($_POST['node_id']);
804 $interface_id=intval($_POST['interface_id']);
805 $tag_type_id = intval($_POST['tag_type_id']);
806 $value = $_POST['value'];
808 $tag_types=$api->GetTagTypes(array($tag_type_id));
809 if (count ($tag_types) != 1) {
810 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
813 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
815 $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
816 if ( count ($tags) == 1) {
819 $tag_id=$tag['node_tag_id'];
820 $result=$api->UpdateNodeTag($tag_id,$value);
822 $tag_id=$tag['interface_tag_id'];
823 $result=$api->UpdateInterfaceTag($tag_id,$value);
826 drupal_set_message ("Updated tag, new value = $value");
828 drupal_set_error ("Could not update tag");
831 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
833 $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
835 drupal_set_message ("Created tag, new value = $value");
837 drupal_set_error ("Could not create tag");
842 plc_redirect (l_node_tags($node_id));
844 plc_redirect (l_interface_tags($interface_id));
847 case 'delete-node-tags' :
848 case 'delete-interface-tags' : {
851 if ($action == 'delete-node-tags') $node_mode=true;
854 $tag_ids=$_POST['node_tag_ids'];
856 $tag_ids=$_POST['interface_tag_ids'];
859 drupal_set_message("action=$action - No tag selected");
864 foreach( $tag_ids as $tag_id ) {
866 $retcod = $api->DeleteNodeTag( intval( $tag_id ));
868 $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
875 drupal_set_message ("Deleted $counter tag(s)");
877 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
879 plc_redirect(l_node_tags($_POST['node_id']));
881 plc_redirect(l_interface_tags($_POST['interface_id']));
884 //////////////////////////////////////// nodegroups
885 case 'update-nodegroup': {
886 $nodegroup_id = $_POST['nodegroup_id'];
887 $groupname = $_POST['groupname'];
888 $value = $_POST['value'];
891 $fields['groupname']=$groupname;
892 $fields['value']=$value;
893 if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
894 drupal_set_message ('Nodegroup updated');
896 drupal_set_error ("Could not update nodegroup $groupname");
898 plc_redirect(l_nodegroup($nodegroup_id));
902 case 'add-nodegroup': {
903 $groupname=$_POST['groupname'];
904 if ( ! $groupname ) {
905 drupal_set_error ('Empty groupname');
906 plc_redirect (l_nodegroups());
908 $tag_type_id=intval($_POST['tag_type_id']);
909 if ( ! $tag_type_id ) {
910 drupal_set_error ('You must select a tag in the dropdown list');
911 plc_redirect (l_nodegroups());
913 $value=$_POST['value'];
915 drupal_set_message ("Empty value.. let's see ..");
917 if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
918 drupal_set_message ("Nodegroup $groupname created");
920 drupal_set_error ("Could not create nodegroup $groupname");
922 plc_redirect (l_nodegroups());
926 case 'delete-nodegroups': {
927 $nodegroup_ids=$_POST['nodegroup_ids'];
928 if ( ! $nodegroup_ids ) {
929 drupal_set_message("action=delete-nodegroups - No group selected");
930 plc_redirect(l_nodegroups());
934 foreach ($nodegroup_ids as $nodegroup_id)
935 if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
940 drupal_set_message ("Deleted $counter group(s)");
942 drupal_set_error ("Could not delete all selected groups, only $counter were removed");
943 plc_redirect (l_nodegroups());
947 ////////////////////////////////////////
950 plc_debug('GET',$_GET);
951 plc_debug('POST',$_POST);
952 plc_debug('FILES',$_FILES);
957 plc_error ("Unknown action $action in actions.php");