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_message("action=$action - No role selected");
173 foreach( $role_ids as $role_id) {
174 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
176 plc_redirect (l_person($person_id));
179 case 'add-role-to-person' : {
180 $role_id=$_POST['role_id'];
181 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
182 plc_redirect (l_person($person_id));
185 case 'enable-person' : {
186 $fields = array( "enabled"=>true );
187 $api->UpdatePerson( intval( $person_id ), $fields );
188 plc_redirect (l_person($person_id));
191 case 'disable-person' : {
192 $fields = array( "enabled"=>false );
193 $api->UpdatePerson( intval( $person_id ), $fields );
194 plc_redirect (l_person($person_id));
197 case 'become-person' : {
198 $plc->BecomePerson (intval($person_id));
199 plc_redirect (l_person(intval($person_id)));
202 case 'delete-person' : {
203 $api->DeletePerson( intval( $person_id ) );
204 plc_redirect (l_persons());
207 case 'delete-keys' : {
208 $key_ids=$_POST['key_ids'];
210 drupal_set_message("action=$action - No key selected");
215 foreach( $key_ids as $key_id ) {
216 if ($api->DeleteKey( intval( $key_id )) != 1)
222 drupal_set_message ("Deleted $counter key(s)");
224 drupal_set_error ("Could not delete all selected keys, only $counter were removed");
225 plc_redirect(l_person($person_id));
229 case 'upload-key' : {
230 if ( ! isset( $_FILES['key'] ) ) {
231 drupal_set_message ("action=$action, no key file set");
235 $key_file= $_FILES['key']['tmp_name'];
237 plc_error("Please select a valid SSH key file to upload");
240 $fp = fopen( $key_file, "r" );
243 plc_error("Unable to open key file $key_file");
246 // opened the key file, read the one line of contents
247 // The POST operation always creates a file even if the filename
248 // the user specified was garbage. If there was some problem
249 // with the source file, we'll get a zero length read here.
250 $key = fread($fp, filesize($key_file));
253 $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
256 drupal_set_message ("New key added");
258 drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
260 plc_redirect(l_person($person_id));
263 case 'update-person': {
264 $person_id=$_POST['person_id'];
265 // attempt to update this person
266 $first_name= $_POST['first_name'];
267 $last_name= $_POST['last_name'];
268 $title= $_POST['title'];
269 $email= $_POST['email'];
270 $phone= $_POST['phone'];
272 $bio= str_replace("\r", "", $_POST['bio']);
273 $password1= $_POST['password1'];
274 $password2= $_POST['password2'];
276 if( $password1 != $password2 ) {
277 drupal_set_error ("The passwords do not match");
278 plc_redirect(l_person($person_id));
282 $fields['first_name']= $first_name;
283 $fields['last_name']= $last_name;
284 $fields['title']= $title;
285 $fields['email']= $email;
286 $fields['phone']= $phone;
287 $fields['url']= $url;
288 $fields['bio']= $bio;
290 if ( $password1 != "" )
291 $fields['password']= $password1;
293 if ( $api->UpdatePerson( intval( $person_id ), $fields) == 1 )
294 drupal_set_message("$first_name $last_name updated");
296 drupal_set_error ("Could not update person $person_id" . $api->error());
298 plc_redirect(l_person($person_id));
302 //////////////////////////////////////////////////////////// nodes
303 case 'node-boot-state': {
304 $node_id=intval($_POST['node_id']);
305 $boot_state=$_POST['boot_state'];
306 $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) );
308 drupal_set_message("boot state updated");
309 plc_redirect (l_node($node_id));
311 drupal_set_error("Could not set boot_state '$boot_state'");
316 case 'delete-node': {
317 $node_id=intval($_POST['node_id']);
318 $result=$api->DeleteNode( intval( $node_id ) );
320 drupal_set_message("Node $node_id deleted");
321 plc_redirect (l_nodes());
323 drupal_set_error ("Could not delete node $node_id");
328 case 'update-node': {
329 $node_id=intval($_POST['node_id']);
330 $hostname= $_POST['hostname'];
331 $model= $_POST['model'];
333 $fields= array( "hostname"=>$hostname, "model"=>$model );
334 $api->UpdateNode( $node_id, $fields );
335 $error= $api->error();
337 if( empty( $error ) ) {
338 drupal_set_message("Update node $hostname");
339 plc_redirect(l_node($node_id));
341 drupal_set_error($error);
346 // this code will ensure that at most one PCU gets attached to the node
348 $node_id=intval($_POST['node_id']);
349 $pcu_id=intval($_POST['pcu_id']);
350 $port=intval($_POST['port']);
351 // always start with deleting former PCUs
352 $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
353 $former_pcu_ids = $nodes[0]['pcu_ids'];
354 if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
355 if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1)
356 drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
358 drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
360 // re-attach only if provided pcu_id >=0
362 if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
363 drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
365 drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
367 drupal_set_message ('Detached node from all PCUs');
370 plc_redirect(l_node($node_id));
375 //////////////////////////////////////////////////////////// interfaces
376 case 'delete-interfaces' : {
377 $interface_ids=$_POST['interface_ids'];
378 if ( ! $interface_ids) {
379 drupal_set_message("action=$action - No interface selected");
384 foreach( $interface_ids as $interface_id ) {
385 if ($api->DeleteInterface( intval( $interface_id )) != 1)
391 drupal_set_message ("Deleted $counter interface(s)");
393 drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
394 plc_redirect(l_node($_POST['node_id']));
396 case 'new-interface': {
397 plc_redirect(l_interface_add($_POST['node_id']));
399 case 'add-interface': {
400 $node_id=$_POST['node_id'];
401 foreach ($interface_details as $field) {
402 $interface[$field]= $_POST[$field];
403 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
404 $interface[$field]= intval( $interface[$field] );
407 $interface_id =$api->AddInterface( intval( $node_id ), $interface );
408 if ($interface_id >0 ) {
410 $api->AddInterfaceTag($interface_id,"alias",strval($interface_id));
411 $api->AddInterfaceTag($interface_id,"ifname","eth0");
412 list($id1, $id2) = $api->commit();
413 if ( $id1 > 0 && $id2 > 0 ) {
414 drupal_set_message ("Interface $interface_id added into node $node_id");
416 drupal_set_error ("Could not add interface tags to interface $interface_id");
419 drupal_set_error ("Could not create interface");
421 plc_redirect (l_node($node_id));
424 case 'update-interface': {
425 $interface_id=$_POST['interface_id'];
426 foreach ($interface_details as $field) {
427 $interface[$field]= $_POST[$field];
428 if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
429 if ( intval($interface[$field]) != 0 ) {
430 $interface[$field]= intval( $interface[$field]);
431 } elseif ($field=='bwlimit' ) {
432 $interface[$field] = NULL;
436 $result=$api->UpdateInterface( intval( $interface_id ), $interface );
438 drupal_set_message ("Interface $interface_id updated");
440 drupal_set_error ("Could not update interface");
441 plc_redirect (l_interface($interface_id));
444 //////////////////////////////////////////////////////////// sites
445 case 'delete-site': {
446 $site_id = intval($_POST['site_id']);
447 if ($api->DeleteSite($site_id) ==1)
448 drupal_set_message ("Site $site_id deleted");
450 drupal_set_error("Failed to delete site $site_id");
451 plc_redirect (l_sites());
455 case 'expire-all-slices-in-site': {
457 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
460 //// old code from sites/expire.php
461 $sites = $api->GetSites( array( intval( $site_id )));
463 // xxx why not 'now?'
464 $expiration= strtotime( $_POST['expires'] );
465 // loop through all slices for site
466 foreach ($site['slice_ids'] as $slice_id) {
467 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
469 // update site to not allow slice creation or renewal
470 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
471 plc_redirect (l_site($site_id));
475 case 'update-site': {
476 $site_id=intval($_POST['site_id']);
477 $name= $_POST['name'];
478 $abbreviated_name= $_POST['abbreviated_name'];
480 $latitude= floatval($_POST['latitude']);
481 $longitude= floatval($_POST['longitude']);
482 //$max_slivers= $_POST['max_slivers'];
484 $fields= array( "name" => $name,
485 "abbreviated_name" => $abbreviated_name,
487 "latitude" => floatval( $latitude ),
488 "longitude" => floatval( $longitude ));
490 if ($_POST['login_base'])
491 $fields['login_base'] = $_POST['login_base'];
492 if (isset($_POST['max_slices']))
493 $fields['max_slices'] = intval($_POST['max_slices']);
494 if (isset($_POST['enabled'])) {
495 $fields['enabled'] = (bool)$_POST['enabled'];
498 $retcod=$api->UpdateSite( intval( $site_id ), $fields );
500 drupal_set_message("Site $name updated");
502 drupal_set_error ("Could not update site $site_id");
504 plc_redirect(l_site($site_id));
508 //////////////////////////////////////////////////////////// slices
509 case 'delete-slice': {
510 $slice_id = $_POST['slice_id'];
511 if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
512 drupal_set_message("Slice $slice_id deleted");
513 plc_redirect(l_slices());
515 drupal_set_error("Could not delete slice $slice_id " . $api->error());
520 case 'update-slice': {
521 $slice_id = $_POST['slice_id'];
522 $name = $_POST['name'];
523 $description= $_POST['description'];
526 $fields= array( "description"=>$description, "url"=>$url );
527 $api->UpdateSlice( intval( $slice_id ), $fields );
528 $error= $api->error();
530 if( empty( $error ) ) {
531 drupal_set_message("Update slice $name");
532 plc_redirect(l_slice($slice_id));
534 drupal_set_error($error);
539 case 'renew-slice': {
540 $slice_id = intval ($_POST['slice_id']);
541 $expires = intval ($_POST['expires']);
547 $MAX_FUTURE=$WEEKS*$WEEK;
548 if ( ($expires-$now) > $MAX_FUTURE) {
549 drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
550 plc_redirect(l_slice($slice_id));
552 if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
553 drupal_set_message("Slice renewed");
555 drupal_set_error("Could not update slice $slice_id");
556 plc_redirect(l_slice($slice_id));
560 case 'remove-persons-from-slice': {
561 $slice_id = intval ($_POST['slice_id']);
562 $person_ids = $_POST['person_ids'];
565 $tmp_slices = $api->GetSlices($slice_id, array("name"));
566 if (count($tmp_slices) > 0) {
567 $tmp_slice = $tmp_slices[0];
568 $slice_name = $tmp_slice["name"];
570 $notify_subject = "Removed from slice: " . $slice_name;
571 $notify_body = sprintf("You have been removed from the slice %s.
573 Our support team will be glad to answer any question that you might have.
575 $notify_person_ids = array();
579 foreach( $person_ids as $person_id ) {
580 if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
583 array_push($notify_person_ids, intval($person_id));
588 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
589 drupal_set_message ("Deleted $counter person(s)");
592 drupal_set_error ("Could not delete all selected persons, only $counter were removed");
593 plc_redirect(l_slice($slice_id) . " &show_persons=true");
597 case 'add-persons-in-slice': {
598 $slice_id = intval ($_POST['slice_id']);
599 $person_ids = $_POST['person_ids'];
602 $tmp_slices = $api->GetSlices($slice_id, array("name"));
603 if (count($tmp_slices) > 0) {
604 $tmp_slice = $tmp_slices[0];
605 $slice_name = $tmp_slice["name"];
607 $notify_subject = "Added to slice: " . $slice_name;
608 $notify_body = sprintf("You have been added to the slice %s as a user.
610 You can go to your slice page following the link below:
611 https://%s:%d/db/slices/index.php?id=%d
613 Our support team will be glad to answer any question that you might have.
614 ",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
615 $notify_person_ids = array();
619 foreach ($person_ids as $person_id) {
620 if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
623 array_push($notify_person_ids, intval($person_id));
628 $api->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
629 drupal_set_message ("Added $counter person(s)");
632 drupal_set_error ("Could not add all selected persons, only $counter were added");
633 plc_redirect(l_slice($slice_id) . "&show_persons=true" );
637 case 'remove-nodes-from-slice': {
638 $slice_id = intval ($_POST['slice_id']);
639 $node_ids = array_map("intval",$_POST['node_ids']);
640 $count=count($node_ids);
642 if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1)
643 drupal_set_message ("Removed $count node(s)");
645 drupal_set_error ("Could not remove selected nodes");
646 plc_redirect(l_slice_nodes($slice_id));
650 case 'add-nodes-in-slice': {
651 $slice_id = intval ($_POST['slice_id']);
652 $node_ids = array_map("intval",$_POST['node_ids']);
653 $count=count($node_ids);
654 if ($api->AddSliceToNodes($slice_id,$node_ids) == 1)
655 drupal_set_message ("Added $count node(s)");
657 drupal_set_error ("Could not add all selected nodes");
658 plc_redirect(l_slice_nodes($slice_id));
662 case 'delete-slice-tags': {
663 $slice_id = intval($_POST['slice_id']);
664 $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
667 foreach($slice_tag_ids as $slice_tag_id) {
668 if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
670 drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
675 drupal_set_message ("Deleted $count slice tag(s)");
676 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
680 case 'add-slice-tag': {
681 $slice_id = intval($_POST['slice_id']);
682 $tag_type_id = intval($_POST['tag_type_id']);
683 $value = $_POST['value'];
684 $node_id = intval($_POST['node_id']);
685 $nodegroup_id = intval($_POST['nodegroup_id']);
689 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
690 } elseif ($nodegroup_id) {
691 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
693 $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
696 drupal_set_message ("Added slice tag.");
698 drupal_set_error("Could not add slice tag");
699 if ($_POST['sliver_action'])
700 plc_redirect(l_sliver($node_id,$slice_id));
702 plc_redirect(l_slice($slice_id) . "&show_tags=true" );
706 //////////////////////////////////////////////////////////// tag types
708 case 'update-tag-type': {
710 $tag_type_id= intval( $_POST['tag_type_id'] );
711 $tagname = $_POST['tagname'];
712 $min_role_id= intval( $_POST['min_role_id'] );
713 $description= $_POST['description'];
714 $category= $_POST['category'];
716 // make tag_type_fields dict
717 $tag_type_fields= array( "min_role_id" => $min_role_id,
718 "tagname" => $tagname,
719 "description" => $description,
720 "category" => $category,
723 if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1)
724 drupal_set_message ("Tag type $tagname updated");
726 drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
727 plc_redirect(l_tag($tag_type_id));
731 case 'add-tag-type': {
733 $tagname = $_POST['tagname'];
734 $min_role_id= intval( $_POST['min_role_id'] );
735 $description= $_POST['description'];
736 $category= $_POST['category'];
738 // make tag_type_fields dict
739 $tag_type_fields= array( "min_role_id" => $min_role_id,
740 "tagname" => $tagname,
741 "description" => $description,
742 "category" => $category,
746 $tag_type_id=$api->AddTagType( $tag_type_fields );
747 if ($tag_type_id > 0)
748 drupal_set_message ("tag type $tag_type_id created");
750 drupal_set_error ("Could not create tag type $tagname");
751 plc_redirect( l_tags());
755 case 'delete-tag-types': {
756 $tag_type_ids = $_POST['tag_type_ids'];
757 if ( ! $tag_type_ids) {
758 drupal_set_message("action=$action - No tag selected");
763 foreach ($tag_type_ids as $tag_type_id)
764 if ($api->DeleteTagType(intval($tag_type_id)) != 1)
769 drupal_set_message ("Deleted $counter tag(s)");
771 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
772 plc_redirect (l_tags());
776 //////////////////////////////////////// tags
777 case 'set-tag-on-node':
778 case 'set-tag-on-interface': {
781 if ($action == 'set-tag-on-node') $node_mode=true;
784 $node_id = intval($_POST['node_id']);
786 $interface_id=intval($_POST['interface_id']);
787 $tag_type_id = intval($_POST['tag_type_id']);
788 $value = $_POST['value'];
790 $tag_types=$api->GetTagTypes(array($tag_type_id));
791 if (count ($tag_types) != 1) {
792 drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
795 $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
797 $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
798 if ( count ($tags) == 1) {
801 $tag_id=$tag['node_tag_id'];
802 $result=$api->UpdateNodeTag($tag_id,$value);
804 $tag_id=$tag['interface_tag_id'];
805 $result=$api->UpdateInterfaceTag($tag_id,$value);
808 drupal_set_message ("Updated tag, new value = $value");
810 drupal_set_error ("Could not update tag");
813 $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
815 $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
817 drupal_set_message ("Created tag, new value = $value");
819 drupal_set_error ("Could not create tag");
824 plc_redirect (l_node($node_id));
826 plc_redirect (l_interface($interface_id));
829 case 'delete-node-tags' :
830 case 'delete-interface-tags' : {
833 if ($action == 'delete-node-tags') $node_mode=true;
836 $tag_ids=$_POST['node_tag_ids'];
838 $tag_ids=$_POST['interface_tag_ids'];
841 drupal_set_message("action=$action - No tag selected");
846 foreach( $tag_ids as $tag_id ) {
848 $retcod = $api->DeleteNodeTag( intval( $tag_id ));
850 $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
857 drupal_set_message ("Deleted $counter tag(s)");
859 drupal_set_error ("Could not delete all selected tags, only $counter were removed");
861 plc_redirect(l_node($_POST['node_id']));
863 plc_redirect(l_interface($_POST['interface_id']));
866 //////////////////////////////////////// nodegroups
867 case 'update-nodegroup': {
868 $nodegroup_id = $_POST['nodegroup_id'];
869 $groupname = $_POST['groupname'];
870 $value = $_POST['value'];
873 $fields['groupname']=$groupname;
874 $fields['value']=$value;
875 if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
876 drupal_set_message ('Nodegroup updated');
878 drupal_set_error ("Could not update nodegroup $groupname");
880 plc_redirect(l_nodegroup($nodegroup_id));
884 case 'add-nodegroup': {
885 $groupname=$_POST['groupname'];
886 if ( ! $groupname ) {
887 drupal_set_error ('Empty groupname');
888 plc_redirect (l_nodegroups());
890 $tag_type_id=intval($_POST['tag_type_id']);
891 if ( ! $tag_type_id ) {
892 drupal_set_error ('You must select a tag in the dropdown list');
893 plc_redirect (l_nodegroups());
895 $value=$_POST['value'];
897 drupal_set_message ("Empty value.. let's see ..");
899 if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
900 drupal_set_message ("Nodegroup $groupname created");
902 drupal_set_error ("Could not create nodegroup $groupname");
904 plc_redirect (l_nodegroups());
908 case 'delete-nodegroups': {
909 $nodegroup_ids=$_POST['nodegroup_ids'];
910 if ( ! $nodegroup_ids ) {
911 drupal_set_message("action=delete-nodegroups - No group selected");
912 plc_redirect(l_nodegroups());
916 foreach ($nodegroup_ids as $nodegroup_id)
917 if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
922 drupal_set_message ("Deleted $counter group(s)");
924 drupal_set_error ("Could not delete all selected groups, only $counter were removed");
925 plc_redirect (l_nodegroups());
929 ////////////////////////////////////////
932 plc_debug('GET',$_GET);
933 plc_debug('POST',$_POST);
934 plc_debug('FILES',$_FILES);
939 plc_error ("Unknown action $action in actions.php");