Minor modification to the code segment in common/actions.php , which checks the retur...
[plewww.git] / planetlab / common / actions.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 //print header
11 require_once 'plc_drupal.php';
12
13 // Common functions
14 require_once 'plc_functions.php';
15
16 $known_actions=array();
17 ////////////////////////////////////////////////////////////
18 // interface :
19 // (*) use POST 
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";
31 //      expects:        person_id
32 $known_actions []= "disable-person";
33 //      expects:        person_id
34 $known_actions []= "become-person";
35 //      expects:        person_id
36 $known_actions []= "delete-person";
37 //      expects:        person_id
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]
44
45 //////////////////////////////////////// nodes
46 $known_actions []= "node-boot-state";   
47 //      expects:        node_id boot_state
48 $known_actions []= "delete-node";       
49 //      expects:        node_id
50 $known_actions []= "update-node";       
51 //      expects:        node_id, hostname, model
52
53 //////////////////////////////////////// interfaces
54 $known_actions []= "delete-interfaces"; 
55 //      expects:        interface_ids
56 $known_actions []="add-interface";
57 //      expects:        node_id & interface details
58 $known_actions []="update-interface";
59 //      expects:        interface_id & interface details
60
61 //////////////////////////////////////// sites
62 $known_actions []= "delete-site";       
63 //      expects:        site_id
64 $known_actions []= "expire-all-slices-in-site";
65 //      expects:        slice_ids
66 $known_actions []= "update-site";
67 //      expects:        site_id & name abbreviated_name url latitude longitude [login_base max_slices]
68
69 //////////////////////////////////////// slices
70 $known_actions []= "delete-slice";
71 //      expects:        slice_id
72 $known_actions []= "update-slice";      
73 //      expects:        slice_id, name, description, url
74 $known_actions []= "renew-slice";
75 //      expects:        slice_id & expires
76 $known_actions []= 'remove-persons-from-slice';
77 //      expects:        slice_id & person_ids
78 $known_actions []= 'add-persons-in-slice';
79 //      expects:        slice_id & person_ids
80 $known_actions []= 'remove-nodes-from-slice';
81 //      expects:        slice_id & node_ids
82 $known_actions []= 'add-nodes-in-slice';
83 //      expects:        slice_id & node_ids
84 $known_actions []= 'delete-slice-tags';
85 //      expects:        slice_tag_id
86 $known_actions []= 'add-slice-tag';
87 //      expects:        slice_id & tag_type_id & node_id & nodegroup_id
88
89 //////////////////////////////////////// tag types
90 $known_actions []= "update-tag-type";
91 //      expects:        tag_type_id & name & description & category & min_role_id  
92 $known_actions []= "add-tag-type";
93 //      expects:        tag_type_id & tagname & description & category & min_role_id  
94 $known_actions []= "delete-tag-types";
95 //      expects:        tag_type_ids
96
97 //////////////////////////////////////// tags
98 $known_actions []= "set-tag-on-node";
99 //      expects:        node_id tagname value
100 $known_actions []= "set-tag-on-interface";
101 //      expects:        interface_id tagname value
102 $known_actions []= "delete-node-tags";
103 //      expects:        node_id & node_tag_ids
104 $known_actions []= "delete-interface-tags";
105 //      expects:        interface_id & interface_tag_ids
106
107 ////////////////////////////////////////////////////////////
108 $interface_details= array ('method','type', 'ip', 'gateway', 'network', 
109                            'broadcast', 'netmask', 'dns1', 'dns2', 
110                            'hostname', 'mac', 'bwlimit' );
111
112 //////////////////////////////
113 // sometimes we don't set 'action', but use the submit button name instead
114 // so if 'action' not set, see if $_POST has one of the actions as a key
115 if ($_POST['action']) 
116   $action=$_POST['action'];
117 else 
118   foreach ($known_actions as $known_action) 
119     if ($_POST[$known_action]) {
120       $action=$known_action;
121       break;
122     }
123
124 //uncomment for debugging incoming data
125 //$action='debug';
126
127 $person_id = $_POST['person_id'];       // usually needed
128
129 if ( ! $action ) {
130   drupal_set_message ("actions.php: action not set or not in known_actions");
131   plc_debug('POST',$_POST);
132   return;
133  }
134
135 switch ($action) {
136
137  case 'add-person-to-site': {
138    $site_id = $_POST['site_id'];
139    $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
140    plc_redirect (l_person($person_id));
141  }
142
143  case 'remove-person-from-sites': {
144    $site_ids = $_POST['site_ids'];
145    if ( ! $site_ids) {
146      drupal_set_message("action=$action - No site selected");
147      return;
148    }
149    foreach ( $site_ids as $site_id ) {
150      $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
151    }
152    plc_redirect (l_person($person_id));
153  }
154
155  case 'remove-roles-from-person' : {
156    $role_ids=$_POST['role_ids'];
157    if ( ! $role_ids) {
158      drupal_set_message("action=$action - No role selected");
159      return;
160    }
161    foreach( $role_ids as $role_id)  {
162      $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
163    }
164    plc_redirect (l_person($person_id));
165  }
166      
167  case 'add-role-to-person' : {
168    $role_id=$_POST['role_id'];
169    $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
170    plc_redirect (l_person($person_id));
171  }
172
173  case 'enable-person' : {
174    $fields = array( "enabled"=>true );
175    $api->UpdatePerson( intval( $person_id ), $fields );
176    plc_redirect (l_person($person_id));
177  }
178
179  case 'disable-person' : {
180    $fields = array( "enabled"=>false );
181    $api->UpdatePerson( intval( $person_id ), $fields );
182    plc_redirect (l_person($person_id));
183  }
184
185  case 'become-person' : {
186    $plc->BecomePerson (intval($person_id));
187    plc_redirect (l_persons());
188  }
189
190  case 'delete-person' : {
191   $api->DeletePerson( intval( $person_id ) );
192    plc_redirect (l_persons());
193  }
194
195  case 'delete-keys' : {
196    $key_ids=$_POST['key_ids'];
197    if ( ! $key_ids) {
198      drupal_set_message("action=$action - No key selected");
199      return;
200    }
201    $success=true;
202    $counter=0;
203    foreach( $key_ids as $key_id ) {
204      if ($api->DeleteKey( intval( $key_id )) != 1) 
205        $success=false;
206      else
207        $counter++;
208    }
209    if ($success) 
210      drupal_set_message ("Deleted $counter key(s)");
211    else
212      drupal_set_error ("Could not delete all selected keys, only $counter were removed");
213    plc_redirect(l_person($person_id));
214  }
215
216
217  case 'upload-key' : {
218    if ( ! isset( $_FILES['key'] ) ) {
219      drupal_set_message ("action=$action, no key file set");
220      return;
221    }
222    
223    $key_file= $_FILES['key']['tmp_name'];
224    if ( ! $key_file ) {
225      plc_error("Please select a valid SSH key file to upload");
226      return;
227    } 
228    $fp = fopen( $key_file, "r" );
229    $key = "";
230    if( ! $fp ) {
231      plc_error("Unable to open key file $key_file");
232      return;
233    }
234    // opened the key file, read the one line of contents
235    // The POST operation always creates a file even if the filename
236    // the user specified was garbage.  If there was some problem
237    // with the source file, we'll get a zero length read here.
238    $key = fread($fp, filesize($key_file));
239    fclose($fp);
240    
241    $key_id = $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
242    
243    if ( $key_id >= 1) 
244      drupal_set_message ("New key added");
245    else
246      drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
247    
248    plc_redirect(l_person($person_id));
249  }
250
251  case 'update-person': {
252    $person_id=$_POST['person_id'];
253    // attempt to update this person
254    $first_name= $_POST['first_name'];
255    $last_name= $_POST['last_name'];
256    $title= $_POST['title'];
257    $email= $_POST['email'];
258    $phone= $_POST['phone'];
259    $url= $_POST['url'];
260    $bio= str_replace("\r", "", $_POST['bio']);
261    $password1= $_POST['password1'];
262    $password2= $_POST['password2'];
263
264    if( $password1 != $password2 ) {
265      drupal_set_error ("The passwords do not match");
266      plc_redirect(l_person($person_id));
267   }
268
269    $fields= array();
270    $fields['first_name']= $first_name;
271    $fields['last_name']= $last_name;
272    $fields['title']= $title;
273    $fields['email']= $email;
274    $fields['phone']= $phone;
275    $fields['url']= $url;
276    $fields['bio']= $bio;
277                 
278    if ( $password1 != "" )
279      $fields['password']= $password1;
280     
281     if ( $api->UpdatePerson( intval( $person_id ), $fields) == 1 )
282       drupal_set_message("$first_name $last_name updated");
283     else 
284       drupal_set_error ("Could not update person $person_id" . $api->error());
285
286     plc_redirect(l_person($person_id));
287     break;
288   }
289
290 //////////////////////////////////////////////////////////// nodes
291  case 'node-boot-state': {
292    $node_id=intval($_POST['node_id']);
293    $boot_state=$_POST['boot_state'];
294    $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) );
295    if ($result==1) {
296      drupal_set_message("boot state updated");
297      plc_redirect (l_node($node_id));
298    } else {
299      drupal_set_error("Could not set boot_state '$boot_state'");
300    }
301    break;
302  }
303
304  case 'delete-node': {
305    $node_id=intval($_POST['node_id']);
306    $result=$api->DeleteNode( intval( $node_id ) );
307    if ($api==1) {
308      drupal_set_message("Node $node_id deleted");
309      plc_redirect (l_nodes());
310    } else {
311      drupal_set_error ("Could not delete node $node_id");
312    }
313    break;
314  }
315
316  case 'update-node': {
317    $hostname= $_POST['hostname'];
318    $model= $_POST['model'];
319
320    $fields= array( "hostname"=>$hostname, "model"=>$model );
321    $api->UpdateNode( intval( $node_id ), $fields );
322    $error= $api->error();
323
324    if( empty( $error ) ) {
325      drupal_set_message("Update node $hostname");
326      plc_redirect(l_node($node_id));
327    } else {
328      drupal_set_error($error);
329    }
330    break;
331  }
332
333 //////////////////////////////////////////////////////////// interfaces
334  case 'delete-interfaces' : {
335    $interface_ids=$_POST['interface_ids'];
336    if ( ! $interface_ids) {
337      drupal_set_message("action=$action - No interface selected");
338      return;
339    }
340    $success=true;
341    $counter=0;
342    foreach( $interface_ids as $interface_id ) {
343      if ($api->DeleteInterface( intval( $interface_id )) != 1) 
344        $success=false;
345      else
346        $counter++;
347    }
348    if ($success) 
349      drupal_set_message ("Deleted $counter interface(s)");
350    else
351      drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
352    plc_redirect(l_node($_POST['node_id']));
353  }
354
355  case 'add-interface': {
356    $node_id=$_POST['node_id'];
357    foreach ($interface_details as $field) {
358      $interface[$field]= $_POST[$field];
359      if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
360        $interface[$field]= intval( $interface[$field] );
361      }
362    }
363    $result=$api->AddInterface( intval( $node_id ), $interface );
364    if ($result >0 ) 
365      drupal_set_message ("Interface $result added into node $node_id");
366    else
367      drupal_set_error ("Could not create interface");
368    plc_redirect (l_node($node_id));
369  }
370    
371  case 'update-interface': {
372    $interface_id=$_POST['interface_id'];
373    foreach ($interface_details as $field) {
374      $interface[$field]= $_POST[$field];
375      if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
376        $interface[$field]= intval( $interface[$field] );
377      }
378    }
379    $result=$api->UpdateInterface( intval( $interface_id ), $interface );
380    if ($result == 1 ) 
381      drupal_set_message ("Interface $interface_id updated");
382    else
383      drupal_set_error ("Could not update interface");
384    plc_redirect (l_interface($interface_id));
385  }
386    
387 //////////////////////////////////////////////////////////// sites
388  case 'delete-site': {
389    $site_id = intval($_POST['site_id']);
390    if ($api->DeleteSite($site_id) ==1) 
391      drupal_set_message ("Site $site_id deleted");
392    else
393      drupal_set_error("Failed to delete site $site_id");
394    plc_redirect (l_sites());
395    break;
396  }
397
398  case 'expire-all-slices-in-site': {
399    // xxx todo
400    drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
401    return;
402
403    //// old code from sites/expire.php
404    $sites = $api->GetSites( array( intval( $site_id )));
405    $site=$sites[0];
406    // xxx why not 'now?'
407    $expiration= strtotime( $_POST['expires'] );
408    // loop through all slices for site
409    foreach ($site['slice_ids'] as $slice_id) {
410      $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
411    }
412    // update site to not allow slice creation or renewal
413    $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
414    plc_redirect (l_site($site_id));
415    break;
416  }
417
418  case 'update-site': {
419    $site_id=intval($_POST['site_id']);
420    $name= $_POST['name'];
421    $abbreviated_name= $_POST['abbreviated_name'];
422    $url= $_POST['url'];
423    $latitude= floatval($_POST['latitude']);
424    $longitude= floatval($_POST['longitude']);
425    //$max_slivers= $_POST['max_slivers'];
426    
427    $fields= array( "name" => $name, 
428                    "abbreviated_name" => $abbreviated_name, 
429                    "url" => $url, 
430                    "latitude" => floatval( $latitude ), 
431                    "longitude" => floatval( $longitude ));
432
433    if ($_POST['login_base']) 
434      $fields['login_base'] = $_POST['login_base'];
435    if ($_POST['max_slices']) 
436      $fields['max_slices'] = intval($_POST['max_slices']);
437    
438    $retcod=$api->UpdateSite( intval( $site_id ), $fields );
439    if ($retcod == 1) 
440      drupal_set_message("Site $name updated");
441    else 
442      drupal_set_error ("Could not update site $site_id");
443      
444    plc_redirect(l_site($site_id));
445    break;
446  }
447
448 //////////////////////////////////////////////////////////// slices
449  case 'delete-slice': {
450    $slice_id = $_POST['slice_id'];
451    $api->DeleteSlice( intval( $slice_id ) );
452    $error= $api->error();
453    if( empty( $error ) ) {
454        drupal_set_message("Deleted slice $slice_id");
455    } else {
456        drupal_set_error($error);
457    }
458    break;
459  }
460      
461  case 'update-slice': {
462    $slice_id = $_POST['slice_id'];
463    $name = $_POST['name'];
464    $description= $_POST['description'];
465    $url= $_POST['url'];
466
467    $fields= array( "description"=>$description, "url"=>$url );
468    $api->UpdateSlice( intval( $slice_id ), $fields );
469    $error= $api->error();
470
471    if( empty( $error ) ) {
472      drupal_set_message("Update slice $name");
473      plc_redirect(l_slice($slice_id));
474    } else {
475      drupal_set_error($error);
476    }
477    break;
478  }
479
480  case 'renew-slice': {
481    $slice_id = intval ($_POST['slice_id']);     
482    $expires = intval ($_POST['expires']);
483    // 8 weeks from now
484    // xxx
485    $now=mktime();
486    $WEEK=7*24*3600;
487    $WEEKS=8;
488    $MAX_FUTURE=$WEEKS*$WEEK;
489    if ( ($expires-$now) > $MAX_FUTURE) {
490      drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
491      plc_redirect(l_slice($slice_id));
492    }
493    plc_debug('slice_id',$slice_id);
494    plc_debug('expires',$expires);
495    if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
496      drupal_set_message("Slice renewed");
497    else
498      drupal_set_error("Could not update slice $slice_id");
499    plc_redirect(l_slice($slice_id));
500    break;
501  }
502
503  case 'remove-persons-from-slice': {
504    $slice_id = intval ($_POST['slice_id']);     
505    $person_ids = $_POST['person_ids'];
506    
507    $success=true;
508    $counter=0;
509    foreach( $person_ids as $person_id ) {
510      if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1) 
511        $success=false;
512      else
513        $counter++;
514    }
515    if ($success) 
516      drupal_set_message ("Deleted $counter person(s)");
517    else
518      drupal_set_error ("Could not delete all selected persons, only $counter were removed");
519    plc_redirect(l_slice($slice_id) . " &show_persons=true");
520    break;
521  }
522
523  case 'add-persons-in-slice': {
524    $slice_id = intval ($_POST['slice_id']);     
525    $person_ids = $_POST['person_ids'];
526    
527    $success=true;
528    $counter=0;
529    foreach ($person_ids as $person_id) {
530      if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1) 
531        $success=false;
532      else
533        $counter++;
534    }
535    if ($success) 
536      drupal_set_message ("Added $counter person(s)");
537    else
538      drupal_set_error ("Could not add all selected persons, only $counter were added");
539    plc_redirect(l_slice($slice_id) . "&show_persons=true" );
540    break;
541  }
542
543  case 'remove-nodes-from-slice': {
544    $slice_id = intval ($_POST['slice_id']);     
545    $node_ids = array_map("intval",$_POST['node_ids']);
546    $count=count($node_ids);
547    
548    if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1) 
549      drupal_set_message ("Removed $count node(s)");
550    else
551      drupal_set_error ("Could not remove selected nodes");
552    plc_redirect(l_slice($slice_id) . " &show_nodes=true");
553    break;
554  }
555
556  case 'add-nodes-in-slice': {
557    $slice_id = intval ($_POST['slice_id']);     
558    $node_ids = array_map("intval",$_POST['node_ids']);
559    $count=count($node_ids);
560    if ($api->AddSliceToNodes($slice_id,$node_ids) == 1) 
561      drupal_set_message ("Added $count node(s)");
562    else
563      drupal_set_error ("Could not add all selected nodes");
564    plc_redirect(l_slice($slice_id) . "&show_nodes=true" );
565    break;
566  }
567
568  case 'delete-slice-tags': {
569    $slice_id = intval($_POST['slice_id']);
570    $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
571    $count = 0;
572    $success = true;
573    foreach($slice_tag_ids as $slice_tag_id) {
574      if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
575      else {
576        drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
577        $success = false;
578      }
579    }
580    if ($success)
581      drupal_set_message ("Deleted $count slice tag(s)");
582    plc_redirect(l_slice($slice_id) . "&show_tags=true" );
583    break;
584  }
585   
586  case 'add-slice-tag': {
587    $slice_id = intval($_POST['slice_id']);
588    $tag_type_id = intval($_POST['tag_type_id']);
589    $value = $_POST['value'];
590    $node_id = intval($_POST['node_id']);
591    $nodegroup_id = intval($_POST['nodegroup_id']);
592   
593    $result = null;
594    if ($node_id) {
595      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
596    } elseif ($nodegroup_id) {
597      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
598    } else {
599      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
600    }
601    if ($result)
602      drupal_set_message ("Added slice tag.");
603    else 
604      drupal_set_error("Could not add slice tag");
605    plc_redirect(l_slice($slice_id) . "&show_tags=true" );
606    break;
607  }
608
609 //////////////////////////////////////////////////////////// tag types
610
611  case 'update-tag-type': {
612   // get post vars 
613    $tag_type_id= intval( $_POST['tag_type_id'] );
614    $tagname = $_POST['tagname'];
615    $min_role_id= intval( $_POST['min_role_id'] );
616    $description= $_POST['description'];  
617    $category= $_POST['category'];
618   
619    // make tag_type_fields dict
620    $tag_type_fields= array( "min_role_id" => $min_role_id, 
621                             "tagname" => $tagname, 
622                             "description" => $description,
623                             "category" => $category,
624                             );
625
626    if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1) 
627      drupal_set_message ("Tag type $tagname updated");
628    else 
629      drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
630    plc_redirect(l_tag($tag_type_id));
631  }
632
633  case 'add-tag-type': {
634   // get post vars 
635    $tagname = $_POST['tagname'];
636    $min_role_id= intval( $_POST['min_role_id'] );
637    $description= $_POST['description'];  
638    $category= $_POST['category'];  
639   
640    // make tag_type_fields dict
641    $tag_type_fields= array( "min_role_id" => $min_role_id, 
642                             "tagname" => $tagname, 
643                             "description" => $description,
644                             "category" => $category,
645                             );
646
647   // Add it!
648    $tag_type_id=$api->AddTagType( $tag_type_fields );
649    if ($tag_type_id > 0) 
650      drupal_set_message ("tag type $tag_type_id created");
651    else
652      drupal_set_error ("Could not create tag type $tagname");
653    plc_redirect( l_tags());
654  }
655
656  case 'delete-tag-types': {
657    $tag_type_ids = $_POST['tag_type_ids'];
658    if ( ! $tag_type_ids) {
659      drupal_set_message("action=$action - No tag selected");
660      return;
661    }
662    $success=true;
663    $counter=0;
664    foreach ($tag_type_ids as $tag_type_id) 
665      if ($api->DeleteTagType(intval($tag_type_id)) != 1) 
666        $success=false;
667      else
668        $counter++;
669    if ($success) 
670      drupal_set_message ("Deleted $counter tag(s)");
671    else
672      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
673    plc_redirect (l_tags());
674    break;
675  }
676
677 //////////////////////////////////////// tags   
678  case 'set-tag-on-node': 
679  case 'set-tag-on-interface': {
680    
681    $node_mode = false;
682    if ($action == 'set-tag-on-node') $node_mode=true;
683
684    if ($node_mode)
685      $node_id = intval($_POST['node_id']);
686    else 
687      $interface_id=intval($_POST['interface_id']);
688    $tag_type_id = intval($_POST['tag_type_id']);
689    $value = $_POST['value'];
690
691    $tag_types=$api->GetTagTypes(array($tag_type_id));
692    if (count ($tag_types) != 1) {
693      drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
694    } else {
695      if ($node_mode) 
696        $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
697      else
698        $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
699      if ( count ($tags) == 1) {
700        $tag=$tags[0];
701        if ($node_mode) {
702          $tag_id=$tag['node_tag_id'];
703          $result=$api->UpdateNodeTag($tag_id,$value);
704        } else {
705          $tag_id=$tag['interface_tag_id'];
706          $result=$api->UpdateInterfaceTag($tag_id,$value);
707        }
708        if ($result == 1) 
709          drupal_set_message ("Updated tag, new value = $value");
710        else
711          drupal_set_error ("Could not update tag");
712      } else {
713        if ($node_mode)
714          $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
715        else
716          $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
717        if ($tag_id) 
718          drupal_set_message ("Created tag, new value = $value");
719        else
720          drupal_set_error ("Could not create tag");
721      }
722    }
723    
724    if ($node_mode)
725      plc_redirect (l_node($node_id));
726    else
727      plc_redirect (l_interface($interface_id));
728  }
729
730  case 'delete-node-tags' : 
731  case 'delete-interface-tags' : {
732
733    $node_mode = false;
734    if ($action == 'delete-node-tags') $node_mode=true;
735
736    if ($node_mode)
737      $tag_ids=$_POST['node_tag_ids'];
738    else
739      $tag_ids=$_POST['interface_tag_ids'];
740
741    if ( ! $tag_ids) {
742      drupal_set_message("action=$action - No tag selected");
743      return;
744    }
745    $success=true;
746    $counter=0;
747    foreach( $tag_ids as $tag_id ) {
748      if ($node_mode)
749        $retcod = $api->DeleteNodeTag( intval( $tag_id ));
750      else
751        $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
752      if ($retcod != 1) 
753        $success=false;
754      else
755        $counter++;
756    }
757    if ($success) 
758      drupal_set_message ("Deleted $counter tag(s)");
759    else
760      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
761    if ($node_mode)
762      plc_redirect(l_node($_POST['node_id']));
763    else
764      plc_redirect(l_interface($_POST['interface_id']));
765  }
766
767
768 ////////////////////////////////////////
769
770  case 'debug': {
771    plc_debug('GET',$_GET);
772    plc_debug('POST',$_POST);
773    plc_debug('FILES',$_FILES);
774    return;
775  }
776
777  default: {
778    plc_error ("Unknown action $action in actions.php");
779    return;
780  }
781
782  }
783
784 ?>