admins can change nodes to reservable/regular in the node page
[plewww.git] / planetlab / common / actions.php
index 0f7623e..8c4beab 100644 (file)
@@ -5,7 +5,8 @@ require_once 'plc_login.php';
 
 // Get session and API handles
 require_once 'plc_session.php';
-global $plc, $api;
+require_once 'plc_api.php';
+global $plc, $api, $adm;
 
 //print header
 require_once 'plc_drupal.php';
@@ -48,13 +49,19 @@ $known_actions []= "node-boot-state";
 $known_actions []= "delete-node";      
 //     expects:        node_id
 $known_actions []= "update-node";      
-//     expects:        node_id, hostname, model
+//     expects:        node_id, hostname, model, node_type
+$known_actions []= "attach-pcu";
+//     expects:        node_id, pcu_id, port (pcu_id <0 means detach)
+$known_actions []= "reboot-node-with-pcu";
+//     expects:        node_id
 
 //////////////////////////////////////// interfaces
 $known_actions []= "delete-interfaces";        
 //     expects:        interface_ids
 $known_actions []="add-interface";
 //     expects:        node_id & interface details
+$known_actions []="new-interface";
+//     expects:        node_id 
 $known_actions []="update-interface";
 //     expects:        interface_id & interface details
 
@@ -81,6 +88,9 @@ $known_actions []= 'remove-nodes-from-slice';
 //     expects:        slice_id & node_ids
 $known_actions []= 'add-nodes-in-slice';
 //     expects:        slice_id & node_ids
+$known_actions []= 'update-initscripts';
+//     expects:        slice_id & name & previous-initscript & previous-initscript-code 
+//                     & initscript & initscript-code
 $known_actions []= 'delete-slice-tags';
 //      expects:        slice_tag_id
 $known_actions []= 'add-slice-tag';
@@ -93,6 +103,10 @@ $known_actions []= "add-tag-type";
 //     expects:        tag_type_id & tagname & description & category & min_role_id  
 $known_actions []= "delete-tag-types";
 //     expects:        tag_type_ids
+$known_actions []= "remove-roles-from-tag-type";
+//     expects:        tag_type_id & role_ids
+$known_actions []= "add-role-to-tag-type";
+//     expects:        tag_type_id_id & id
 
 //////////////////////////////////////// tags
 $known_actions []= "set-tag-on-node";
@@ -104,6 +118,20 @@ $known_actions []= "delete-node-tags";
 $known_actions []= "delete-interface-tags";
 //     expects:        interface_id & interface_tag_ids
 
+//////////////////////////////////////// nodegroups
+$known_actions []= "update-nodegroup";
+//     expects nodegroup_id groupname value
+$known_actions []= "add-nodegroup";
+//     expects groupname, tag_type_id, value
+$known_actions []= 'delete-nodegroups';
+//     expects nodegroup_ids
+
+//////////////////////////////////////// leases
+$known_actions []= "manage-leases";
+//     expects as 'actions' a list of 'action' of the form
+//      either [ 'add-leases', [nodenames], slicename, t_from, t_until ]
+//      or     [ 'delete-leases', lease_id ]
+
 ////////////////////////////////////////////////////////////
 $interface_details= array ('method','type', 'ip', 'gateway', 'network', 
                           'broadcast', 'netmask', 'dns1', 'dns2', 
@@ -155,19 +183,23 @@ switch ($action) {
  case 'remove-roles-from-person' : {
    $role_ids=$_POST['role_ids'];
    if ( ! $role_ids) {
-     drupal_set_message("action=$action - No role selected");
-     return;
-   }
-   foreach( $role_ids as $role_id)  {
-     $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
+     drupal_set_error("You have not selected role(s) to remove");
+   } else {
+     foreach( $role_ids as $role_id)  
+       if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 ) 
+        drupal_set_error ("Could not remove role $role_id from person $person_id");
    }
-   plc_redirect (l_person($person_id));
+   plc_redirect (l_person_roles($person_id));
  }
      
  case 'add-role-to-person' : {
    $role_id=$_POST['role_id'];
-   $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
-   plc_redirect (l_person($person_id));
+   if ( ! $role_id) {
+     drupal_set_error ("You have not selected a role to add");
+   } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
+     drupal_set_error("Could not add role $role_id to person $person_id");
+   }
+   plc_redirect (l_person_roles($person_id));
  }
 
  case 'enable-person' : {
@@ -184,7 +216,7 @@ switch ($action) {
 
  case 'become-person' : {
    $plc->BecomePerson (intval($person_id));
-   plc_redirect (l_persons());
+   plc_redirect (l_person(intval($person_id)));
  }
 
  case 'delete-person' : {
@@ -314,11 +346,13 @@ switch ($action) {
  }
 
  case 'update-node': {
+   $node_id=intval($_POST['node_id']);
    $hostname= $_POST['hostname'];
    $model= $_POST['model'];
+   $node_type= $_POST['node_type'];
 
-   $fields= array( "hostname"=>$hostname, "model"=>$model );
-   $api->UpdateNode( intval( $node_id ), $fields );
+   $fields= array( "hostname"=>$hostname, "model"=>$model, "node_type"=>$node_type );
+   $api->UpdateNode( $node_id, $fields );
    $error= $api->error();
 
    if( empty( $error ) ) {
@@ -330,6 +364,53 @@ switch ($action) {
    break;
  }
 
+ // this code will ensure that at most one PCU gets attached to the node
+ case 'attach-pcu': {
+   $node_id=intval($_POST['node_id']);
+   $pcu_id=intval($_POST['pcu_id']);
+   $port=intval($_POST['port']);
+   // always start with deleting former PCUs
+   $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
+   $former_pcu_ids = $nodes[0]['pcu_ids'];
+   if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
+       if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1) 
+        drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
+       else 
+        drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
+     }
+   // re-attach only if provided pcu_id >=0
+   if ($pcu_id >= 0) {
+     if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
+       drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+     else
+       drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+   } else {
+     drupal_set_message ('Detached node from all PCUs');
+   }
+   
+   plc_redirect(l_node($node_id));
+   break;
+ }
+
+ case 'reboot-node-with-pcu': {
+   $node_id=intval($_POST['node_id']);
+   $hostname= $_POST['hostname'];
+   $test = $_POST['test'];
+   settype($test, "boolean");
+
+   $ret = $api->RebootNodeWithPCU( $node_id, $test );
+   $error= $api->error();
+
+   if( empty( $error ) ) {
+     drupal_set_message("Reboot node $hostname: $ret");
+     plc_redirect(l_node($node_id));
+   } else {
+     drupal_set_error($error);
+   }
+   break;
+ }
+   
+
 //////////////////////////////////////////////////////////// interfaces
  case 'delete-interfaces' : {
    $interface_ids=$_POST['interface_ids'];
@@ -352,20 +433,45 @@ switch ($action) {
    plc_redirect(l_node($_POST['node_id']));
  }
 
+ case 'new-interface': {
+   plc_redirect(l_interface_add($_POST['node_id']));
+ }
+
  case 'add-interface': {
-   $node_id=$_POST['node_id'];
+   $node_id=intval($_POST['node_id']);
    foreach ($interface_details as $field) {
      $interface[$field]= $_POST[$field];
+     // these must be integers
      if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
-       $interface[$field]= intval( $interface[$field] );
+       if ( empty ($interface[$field]) ) 
+        unset ($interface[$field]);
+       else 
+        $interface[$field]= intval( $interface[$field] );
      }
    }
-   $result=$api->AddInterface( intval( $node_id ), $interface );
-   if ($result >0 ) 
-     drupal_set_message ("Interface $result added into node $node_id");
-   else
+   $interface_id =$api->AddInterface( $node_id , $interface );
+   if ($interface_id <= 0 ) {
      drupal_set_error ("Could not create interface");
-   plc_redirect (l_node($node_id));
+     drupal_set_error ($api->error());
+   } else {
+     $ip=$interface['ip'];
+     drupal_set_message ("Interface $ip added into node $node_id");
+     if ($_POST['is-virtual']) {
+       $ifname=$_POST['ifname'];
+       if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0) 
+        drupal_set_error ("Could not set tag 'ifname'=$ifname");
+       else 
+        drupal_set_message ("Set tag 'ifname'=$ifname");
+       $alias=$_POST['alias'];
+       // deafult to interface_id
+       if ( ! $alias ) $alias=strval($interface_id);
+       if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0) 
+        drupal_set_error ("Could not set tag 'alias'=$alias");
+       else 
+        drupal_set_message ("Set tag 'alias'=$alias");
+     }
+   }
+   plc_redirect (l_node_interfaces($node_id));
  }
    
  case 'update-interface': {
@@ -373,14 +479,18 @@ switch ($action) {
    foreach ($interface_details as $field) {
      $interface[$field]= $_POST[$field];
      if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
-       $interface[$field]= intval( $interface[$field] );
+       if ( intval($interface[$field]) != 0 ) {
+           $interface[$field]= intval( $interface[$field]);
+       } elseif ($field=='bwlimit' ) {
+           $interface[$field] = NULL;
+       }
      }
    }
    $result=$api->UpdateInterface( intval( $interface_id ), $interface );
    if ($result == 1 ) 
      drupal_set_message ("Interface $interface_id updated");
    else
-     drupal_set_error ("Could not update interface");
+     drupal_set_error ("Could not update interface: " . $api->error());
    plc_redirect (l_interface($interface_id));
  }
    
@@ -432,8 +542,11 @@ switch ($action) {
 
    if ($_POST['login_base']) 
      $fields['login_base'] = $_POST['login_base'];
-   if ($_POST['max_slices']) 
+   if (isset($_POST['max_slices']))
      $fields['max_slices'] = intval($_POST['max_slices']);
+   if (isset($_POST['enabled'])) {
+     $fields['enabled'] = (bool)$_POST['enabled'];
+   }
    
    $retcod=$api->UpdateSite( intval( $site_id ), $fields );
    if ($retcod == 1) 
@@ -448,12 +561,11 @@ switch ($action) {
 //////////////////////////////////////////////////////////// slices
  case 'delete-slice': {
    $slice_id = $_POST['slice_id'];
-   $api->DeleteSlice( intval( $slice_id ) );
-   $error= $api->error();
-   if( empty( $error ) ) {
-       drupal_set_message("Deleted slice $slice_id");
+   if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
+     drupal_set_message("Slice $slice_id deleted");
+     plc_redirect(l_slices());
    } else {
-       drupal_set_error($error);
+     drupal_set_error("Could not delete slice $slice_id " . $api->error());
    }
    break;
  }
@@ -490,8 +602,6 @@ switch ($action) {
      drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
      plc_redirect(l_slice($slice_id));
    }
-   plc_debug('slice_id',$slice_id);
-   plc_debug('expires',$expires);
    if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
      drupal_set_message("Slice renewed");
    else
@@ -504,16 +614,33 @@ switch ($action) {
    $slice_id = intval ($_POST['slice_id']);    
    $person_ids = $_POST['person_ids'];
    
+   $slice_name = "";
+   $tmp_slices = $api->GetSlices($slice_id, array("name"));
+   if (count($tmp_slices) > 0) {
+       $tmp_slice = $tmp_slices[0];
+       $slice_name = $tmp_slice["name"];
+   }
+   $notify_subject = "Removed from slice: " . $slice_name;
+   $notify_body = sprintf("You have been removed from the slice %s.
+
+Our support team will be glad to answer any question that you might have.
+",$slice_name);
+   $notify_person_ids = array();
+   
    $success=true;
    $counter=0;
    foreach( $person_ids as $person_id ) {
      if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1) 
        $success=false;
-     else
+     else {
+         array_push($notify_person_ids, intval($person_id));
        $counter++;
+     }
    }
-   if ($success) 
+   if ($success) {
+     $adm->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
      drupal_set_message ("Deleted $counter person(s)");
+   }
    else
      drupal_set_error ("Could not delete all selected persons, only $counter were removed");
    plc_redirect(l_slice($slice_id) . " &show_persons=true");
@@ -523,17 +650,37 @@ switch ($action) {
  case 'add-persons-in-slice': {
    $slice_id = intval ($_POST['slice_id']);    
    $person_ids = $_POST['person_ids'];
+
+   $slice_name = "";
+   $tmp_slices = $api->GetSlices($slice_id, array("name"));
+   if (count($tmp_slices) > 0) {
+     $tmp_slice = $tmp_slices[0];
+     $slice_name = $tmp_slice["name"];
+   }
+   $notify_subject = "Added to slice: " . $slice_name;
+   $notify_body = sprintf("You have been added to the slice %s as a user.
+
+You can go to your slice page following the link below:
+https://%s:%d/db/slices/index.php?id=%d
+
+Our support team will be glad to answer any question that you might have.
+",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
+   $notify_person_ids = array();
    
    $success=true;
    $counter=0;
    foreach ($person_ids as $person_id) {
      if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1) 
        $success=false;
-     else
+     else {
+       array_push($notify_person_ids, intval($person_id));
        $counter++;
+     }
    }
-   if ($success) 
+   if ($success) {
+     $adm->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
      drupal_set_message ("Added $counter person(s)");
+   }
    else
      drupal_set_error ("Could not add all selected persons, only $counter were added");
    plc_redirect(l_slice($slice_id) . "&show_persons=true" );
@@ -549,7 +696,7 @@ switch ($action) {
      drupal_set_message ("Removed $count node(s)");
    else
      drupal_set_error ("Could not remove selected nodes");
-   plc_redirect(l_slice($slice_id) . " &show_nodes=true");
+   plc_redirect(l_slice_nodes($slice_id));
    break;
  }
 
@@ -561,10 +708,53 @@ switch ($action) {
      drupal_set_message ("Added $count node(s)");
    else
      drupal_set_error ("Could not add all selected nodes");
-   plc_redirect(l_slice($slice_id) . "&show_nodes=true" );
+   plc_redirect(l_slice_nodes($slice_id));
    break;
  }
 
+ case 'update-initscripts': {
+//     expects:        slice_id & name & previous-initscript & previous-initscript-code 
+//                     & initscript & initscript-code
+   $slice_id = intval ($_POST['slice_id']);    
+   $previous_initscript=$_POST['previous-initscript'];
+   $initscript=$_POST['initscript'];
+   $previous_initscript_code=html_entity_decode($_POST['previous-initscript-code']);
+   $initscript_code=$_POST['initscript-code'];
+
+   $changes=FALSE;
+   if (strcmp($initscript,$previous_initscript) != 0) {
+     $newvalue=$api->SetSliceInitscript($slice_id,$initscript);
+     $status = (strcmp($newvalue,$initscript)==0) ? "OK" : "failed";
+     if (! $initscript)                drupal_set_message("Removed shared initscript '" . $previous_initscript . "' " . $status);
+     else                      drupal_set_message("Replaced shared initscript with '" . $initscript . "' " . $status);
+     $changes=TRUE;
+   }
+
+   // somehow some \r chars make it here; just ignore them
+   $previous_initscript_code=str_replace("\r","",$previous_initscript_code);
+   //   plc_debug_txt('previous initscript_code after cr',$previous_initscript_code);
+
+   $initscript_code=str_replace("\r","",$initscript_code);
+   // make sure the script ends with a single \n 
+   $initscript_code=trim($initscript_code);
+   if (!empty($initscript_code) && $initscript_code[strlen($initscript_code)-1] != "\n")
+     $initscript_code.="\n";
+   // plc_debug_txt('initscript_code after cr & nl/eof',$initscript_code);
+
+   if (strcmp($initscript_code,$previous_initscript_code) != 0) {
+     $newvalue=$api->SetSliceInitscriptCode($slice_id,$initscript_code);
+     // plc_debug_txt('newvalue',$newvalue);
+     $status=(strcmp($newvalue,$initscript_code)==0) ? "OK" : "failed";
+     if (! $initscript_code)   drupal_set_message("Removed initscript code " . $status);
+     else                      drupal_set_message("Installed new initscript code " . $status);
+     $changes=TRUE;
+   }
+   if (!$changes) drupal_set_message("No changes required in initscript");
+   plc_redirect(l_slice($slice_id) . "&show_details=0&show_initscripts=1" );
+   break;
+ }
+
+
  case 'delete-slice-tags': {
    $slice_id = intval($_POST['slice_id']);
    $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
@@ -579,7 +769,7 @@ switch ($action) {
    }
    if ($success)
      drupal_set_message ("Deleted $count slice tag(s)");
-   plc_redirect(l_slice($slice_id) . "&show_tags=true" );
+   plc_redirect(l_slice($slice_id) . "&show_tags=1" );
    break;
  }
   
@@ -601,8 +791,11 @@ switch ($action) {
    if ($result)
      drupal_set_message ("Added slice tag.");
    else 
-     drupal_set_error("Could not add slice tag");
-   plc_redirect(l_slice($slice_id) . "&show_tags=true" );
+       drupal_set_error("Could not add slice tag");
+   if ($_POST['sliver_action'])
+       plc_redirect(l_sliver($node_id,$slice_id));
+   else
+       plc_redirect(l_slice($slice_id) . "&show_tags=true" );
    break;
  }
 
@@ -628,6 +821,7 @@ switch ($action) {
    else 
      drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
    plc_redirect(l_tag($tag_type_id));
+   break;
  }
 
  case 'add-tag-type': {
@@ -651,6 +845,7 @@ switch ($action) {
    else
      drupal_set_error ("Could not create tag type $tagname");
    plc_redirect( l_tags());
+   break;
  }
 
  case 'delete-tag-types': {
@@ -674,6 +869,30 @@ switch ($action) {
    break;
  }
 
+ case 'remove-roles-from-tag-type' : {
+   $tag_type_id=$_POST['tag_type_id'];
+   $role_ids=$_POST['role_ids'];
+   if ( ! $role_ids) {
+     drupal_set_error("You have not selected role(s) to remove");
+   } else {
+     foreach( $role_ids as $role_id)  
+       if ( $api->DeleteRoleFromTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1 ) 
+        drupal_set_error ("Could not remove role $role_id from tag type $tag_type_id");
+   }
+   plc_redirect (l_tag_roles($tag_type_id));
+ }
+     
+ case 'add-role-to-tag-type' : {
+   $tag_type_id=$_POST['tag_type_id'];
+   $role_id=$_POST['role_id'];
+   if ( ! $role_id) {
+     drupal_set_error ("You have not selected a role to add");
+   } else if ($api->AddRoleToTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1) {
+     drupal_set_error("Could not add role $role_id to tag $tag_type_id");
+   }
+   plc_redirect (l_tag_roles($tag_type_id));
+ }
+
 //////////////////////////////////////// tags   
  case 'set-tag-on-node': 
  case 'set-tag-on-interface': {
@@ -722,9 +941,9 @@ switch ($action) {
    }
    
    if ($node_mode)
-     plc_redirect (l_node($node_id));
+     plc_redirect (l_node_tags($node_id));
    else
-     plc_redirect (l_interface($interface_id));
+     plc_redirect (l_interface_tags($interface_id));
  }
 
  case 'delete-node-tags' : 
@@ -759,11 +978,119 @@ switch ($action) {
    else
      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
    if ($node_mode)
-     plc_redirect(l_node($_POST['node_id']));
+     plc_redirect(l_node_tags($_POST['node_id']));
+   else
+     plc_redirect(l_interface_tags($_POST['interface_id']));
+ }
+
+//////////////////////////////////////// nodegroups
+ case 'update-nodegroup': {
+   $nodegroup_id = $_POST['nodegroup_id'];
+   $groupname = $_POST['groupname'];
+   $value = $_POST['value'];
+
+   $fields=array();
+   $fields['groupname']=$groupname;
+   $fields['value']=$value;
+   if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1) 
+     drupal_set_message ('Nodegroup updated');
+   else 
+     drupal_set_error ("Could not update nodegroup $groupname");
+   
+   plc_redirect(l_nodegroup($nodegroup_id));
+
+ }
+
+ case 'add-nodegroup': {
+   $groupname=$_POST['groupname'];
+   if ( ! $groupname ) {
+     drupal_set_error ('Empty groupname');
+     plc_redirect (l_nodegroups());
+   }
+   $tag_type_id=intval($_POST['tag_type_id']);
+   if ( ! $tag_type_id ) {
+     drupal_set_error ('You must select a tag in the dropdown list');
+     plc_redirect (l_nodegroups());
+   }
+   $value=$_POST['value'];
+   if ( ! $value ) {
+     drupal_set_message ("Empty value.. let's see ..");
+   }
+   if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0) 
+     drupal_set_message ("Nodegroup $groupname created");
+   else
+     drupal_set_error ("Could not create nodegroup $groupname");
+
+   plc_redirect (l_nodegroups());
+   break;
+ }
+
+ case 'delete-nodegroups': {
+   $nodegroup_ids=$_POST['nodegroup_ids'];
+   if ( ! $nodegroup_ids ) {
+     drupal_set_message("action=delete-nodegroups - No group selected");
+     plc_redirect(l_nodegroups());
+   }
+   $success=true;
+   $counter=0;
+   foreach ($nodegroup_ids as $nodegroup_id) 
+     if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1) 
+       $success=false;
+     else
+       $counter++;
+   if ($success) 
+     drupal_set_message ("Deleted $counter group(s)");
    else
-     plc_redirect(l_interface($_POST['interface_id']));
+     drupal_set_error ("Could not delete all selected groups, only $counter were removed");
+   plc_redirect (l_nodegroups());
+   break;
  }
 
+//////////////////////////////////////// leases
+ case 'manage-leases': {
+   $actions=json_decode($_POST['actions']);
+   $add_requested=0;
+   $add_done=0;
+   $del_requested=0;
+   $del_done=0;
+   $errors=array();
+   foreach ($actions as $action) {
+     if ($action[0] == 'add-leases') {
+       $nodenames=$action[1];
+       $add_requested += count($nodenames);
+       $slicename=$action[2];
+       $t_from=intval($action[3]);
+       $t_until=intval($action[4]);
+       $hash = $api->AddLeases($nodenames,$slicename,$t_from,$t_until);
+       // update number of added leases
+       $ids=$hash['new_ids'];
+       $add_done += count($ids);
+       // update global errors array
+       foreach ($api_errors=$hash['errors'] as $error) $errors[]=$error;
+     } else if ($action[0]=='delete-leases') {
+       $lease_id=intval($action[1]);
+       $del_requested += 1;
+       if ($api->DeleteLeases(array($lease_id)) == 1) {
+        $del_done += 1;
+       } else {
+        $errors []= "Could not delete lease " . $lease_id;
+       }
+     } else {
+       $errors []= "in actions.php, manage-leases, wrong action ". $action[0];
+     }
+   }
+   
+   if (count($errors)==0) {
+     echo("All leases updated (" . $add_done . " added and " . $del_done . " deleted)");
+   } else {
+     foreach ($errors as $error) echo($error. "\n");
+     echo("Leases updated only partially (" . 
+         $add_done . "/" . $add_requested . " added and " . 
+         $del_done . "/" . $del_requested . " deleted)");
+   }     
+
+   break;
+ }
 
 ////////////////////////////////////////