reviewed planetlab module, downgrade the "all users" link
[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_person(intval($person_id)));
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    if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
452      drupal_set_message("Slice $slice_id deleted");
453      plc_redirect(l_slices());
454    } else {
455      drupal_set_error("Could not delete slice $slice_id " . $api->error());
456    }
457    break;
458  }
459      
460  case 'update-slice': {
461    $slice_id = $_POST['slice_id'];
462    $name = $_POST['name'];
463    $description= $_POST['description'];
464    $url= $_POST['url'];
465
466    $fields= array( "description"=>$description, "url"=>$url );
467    $api->UpdateSlice( intval( $slice_id ), $fields );
468    $error= $api->error();
469
470    if( empty( $error ) ) {
471      drupal_set_message("Update slice $name");
472      plc_redirect(l_slice($slice_id));
473    } else {
474      drupal_set_error($error);
475    }
476    break;
477  }
478
479  case 'renew-slice': {
480    $slice_id = intval ($_POST['slice_id']);     
481    $expires = intval ($_POST['expires']);
482    // 8 weeks from now
483    // xxx
484    $now=mktime();
485    $WEEK=7*24*3600;
486    $WEEKS=8;
487    $MAX_FUTURE=$WEEKS*$WEEK;
488    if ( ($expires-$now) > $MAX_FUTURE) {
489      drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
490      plc_redirect(l_slice($slice_id));
491    }
492    plc_debug('slice_id',$slice_id);
493    plc_debug('expires',$expires);
494    if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
495      drupal_set_message("Slice renewed");
496    else
497      drupal_set_error("Could not update slice $slice_id");
498    plc_redirect(l_slice($slice_id));
499    break;
500  }
501
502  case 'remove-persons-from-slice': {
503    $slice_id = intval ($_POST['slice_id']);     
504    $person_ids = $_POST['person_ids'];
505    
506    $success=true;
507    $counter=0;
508    foreach( $person_ids as $person_id ) {
509      if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1) 
510        $success=false;
511      else
512        $counter++;
513    }
514    if ($success) 
515      drupal_set_message ("Deleted $counter person(s)");
516    else
517      drupal_set_error ("Could not delete all selected persons, only $counter were removed");
518    plc_redirect(l_slice($slice_id) . " &show_persons=true");
519    break;
520  }
521
522  case 'add-persons-in-slice': {
523    $slice_id = intval ($_POST['slice_id']);     
524    $person_ids = $_POST['person_ids'];
525    
526    $success=true;
527    $counter=0;
528    foreach ($person_ids as $person_id) {
529      if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1) 
530        $success=false;
531      else
532        $counter++;
533    }
534    if ($success) 
535      drupal_set_message ("Added $counter person(s)");
536    else
537      drupal_set_error ("Could not add all selected persons, only $counter were added");
538    plc_redirect(l_slice($slice_id) . "&show_persons=true" );
539    break;
540  }
541
542  case 'remove-nodes-from-slice': {
543    $slice_id = intval ($_POST['slice_id']);     
544    $node_ids = array_map("intval",$_POST['node_ids']);
545    $count=count($node_ids);
546    
547    if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1) 
548      drupal_set_message ("Removed $count node(s)");
549    else
550      drupal_set_error ("Could not remove selected nodes");
551    plc_redirect(l_slice($slice_id) . " &show_nodes=true");
552    break;
553  }
554
555  case 'add-nodes-in-slice': {
556    $slice_id = intval ($_POST['slice_id']);     
557    $node_ids = array_map("intval",$_POST['node_ids']);
558    $count=count($node_ids);
559    if ($api->AddSliceToNodes($slice_id,$node_ids) == 1) 
560      drupal_set_message ("Added $count node(s)");
561    else
562      drupal_set_error ("Could not add all selected nodes");
563    plc_redirect(l_slice($slice_id) . "&show_nodes=true" );
564    break;
565  }
566
567  case 'delete-slice-tags': {
568    $slice_id = intval($_POST['slice_id']);
569    $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
570    $count = 0;
571    $success = true;
572    foreach($slice_tag_ids as $slice_tag_id) {
573      if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
574      else {
575        drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
576        $success = false;
577      }
578    }
579    if ($success)
580      drupal_set_message ("Deleted $count slice tag(s)");
581    plc_redirect(l_slice($slice_id) . "&show_tags=true" );
582    break;
583  }
584   
585  case 'add-slice-tag': {
586    $slice_id = intval($_POST['slice_id']);
587    $tag_type_id = intval($_POST['tag_type_id']);
588    $value = $_POST['value'];
589    $node_id = intval($_POST['node_id']);
590    $nodegroup_id = intval($_POST['nodegroup_id']);
591   
592    $result = null;
593    if ($node_id) {
594      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
595    } elseif ($nodegroup_id) {
596      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
597    } else {
598      $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
599    }
600    if ($result)
601      drupal_set_message ("Added slice tag.");
602    else 
603        drupal_set_error("Could not add slice tag");
604    if ($_POST['sliver_action'])
605        plc_redirect(l_sliver($node_id,$slice_id));
606    else
607        plc_redirect(l_slice($slice_id) . "&show_tags=true" );
608    break;
609  }
610
611 //////////////////////////////////////////////////////////// tag types
612
613  case 'update-tag-type': {
614   // get post vars 
615    $tag_type_id= intval( $_POST['tag_type_id'] );
616    $tagname = $_POST['tagname'];
617    $min_role_id= intval( $_POST['min_role_id'] );
618    $description= $_POST['description'];  
619    $category= $_POST['category'];
620   
621    // make tag_type_fields dict
622    $tag_type_fields= array( "min_role_id" => $min_role_id, 
623                             "tagname" => $tagname, 
624                             "description" => $description,
625                             "category" => $category,
626                             );
627
628    if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1) 
629      drupal_set_message ("Tag type $tagname updated");
630    else 
631      drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
632    plc_redirect(l_tag($tag_type_id));
633  }
634
635  case 'add-tag-type': {
636   // get post vars 
637    $tagname = $_POST['tagname'];
638    $min_role_id= intval( $_POST['min_role_id'] );
639    $description= $_POST['description'];  
640    $category= $_POST['category'];  
641   
642    // make tag_type_fields dict
643    $tag_type_fields= array( "min_role_id" => $min_role_id, 
644                             "tagname" => $tagname, 
645                             "description" => $description,
646                             "category" => $category,
647                             );
648
649   // Add it!
650    $tag_type_id=$api->AddTagType( $tag_type_fields );
651    if ($tag_type_id > 0) 
652      drupal_set_message ("tag type $tag_type_id created");
653    else
654      drupal_set_error ("Could not create tag type $tagname");
655    plc_redirect( l_tags());
656  }
657
658  case 'delete-tag-types': {
659    $tag_type_ids = $_POST['tag_type_ids'];
660    if ( ! $tag_type_ids) {
661      drupal_set_message("action=$action - No tag selected");
662      return;
663    }
664    $success=true;
665    $counter=0;
666    foreach ($tag_type_ids as $tag_type_id) 
667      if ($api->DeleteTagType(intval($tag_type_id)) != 1) 
668        $success=false;
669      else
670        $counter++;
671    if ($success) 
672      drupal_set_message ("Deleted $counter tag(s)");
673    else
674      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
675    plc_redirect (l_tags());
676    break;
677  }
678
679 //////////////////////////////////////// tags   
680  case 'set-tag-on-node': 
681  case 'set-tag-on-interface': {
682    
683    $node_mode = false;
684    if ($action == 'set-tag-on-node') $node_mode=true;
685
686    if ($node_mode)
687      $node_id = intval($_POST['node_id']);
688    else 
689      $interface_id=intval($_POST['interface_id']);
690    $tag_type_id = intval($_POST['tag_type_id']);
691    $value = $_POST['value'];
692
693    $tag_types=$api->GetTagTypes(array($tag_type_id));
694    if (count ($tag_types) != 1) {
695      drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
696    } else {
697      if ($node_mode) 
698        $tags = $api->GetNodeTags (array('node_id'=>$node_id, 'tag_type_id'=> $tag_type_id));
699      else
700        $tags = $api->GetInterfaceTags (array('interface_id'=>$interface_id, 'tag_type_id'=> $tag_type_id));
701      if ( count ($tags) == 1) {
702        $tag=$tags[0];
703        if ($node_mode) {
704          $tag_id=$tag['node_tag_id'];
705          $result=$api->UpdateNodeTag($tag_id,$value);
706        } else {
707          $tag_id=$tag['interface_tag_id'];
708          $result=$api->UpdateInterfaceTag($tag_id,$value);
709        }
710        if ($result == 1) 
711          drupal_set_message ("Updated tag, new value = $value");
712        else
713          drupal_set_error ("Could not update tag");
714      } else {
715        if ($node_mode)
716          $tag_id = $api->AddNodeTag($node_id,$tag_type_id,$value);
717        else
718          $tag_id = $api->AddInterfaceTag($interface_id,$tag_type_id,$value);
719        if ($tag_id) 
720          drupal_set_message ("Created tag, new value = $value");
721        else
722          drupal_set_error ("Could not create tag");
723      }
724    }
725    
726    if ($node_mode)
727      plc_redirect (l_node($node_id));
728    else
729      plc_redirect (l_interface($interface_id));
730  }
731
732  case 'delete-node-tags' : 
733  case 'delete-interface-tags' : {
734
735    $node_mode = false;
736    if ($action == 'delete-node-tags') $node_mode=true;
737
738    if ($node_mode)
739      $tag_ids=$_POST['node_tag_ids'];
740    else
741      $tag_ids=$_POST['interface_tag_ids'];
742
743    if ( ! $tag_ids) {
744      drupal_set_message("action=$action - No tag selected");
745      return;
746    }
747    $success=true;
748    $counter=0;
749    foreach( $tag_ids as $tag_id ) {
750      if ($node_mode)
751        $retcod = $api->DeleteNodeTag( intval( $tag_id ));
752      else
753        $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
754      if ($retcod != 1) 
755        $success=false;
756      else
757        $counter++;
758    }
759    if ($success) 
760      drupal_set_message ("Deleted $counter tag(s)");
761    else
762      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
763    if ($node_mode)
764      plc_redirect(l_node($_POST['node_id']));
765    else
766      plc_redirect(l_interface($_POST['interface_id']));
767  }
768
769
770 ////////////////////////////////////////
771
772  case 'debug': {
773    plc_debug('GET',$_GET);
774    plc_debug('POST',$_POST);
775    plc_debug('FILES',$_FILES);
776    return;
777  }
778
779  default: {
780    plc_error ("Unknown action $action in actions.php");
781    return;
782  }
783
784  }
785
786 ?>