Code

Updated FAI partition handling
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiGroupHandle.inc
index 7b4454cfac833186f19294297b62e4da96674ae5..eb31295ad968ea011760147a6dde4dedeccd5daf 100644 (file)
@@ -10,13 +10,22 @@ class faiGroupHandle{
 
   public function __construct($FAI_group, $Action)
   {
-    if(in_array($Action,array("edit","remove"))){
+    if(in_array($Action,array("edit","remove","copy","cut"))){
       $this->mode = $Action;
+    }else{
+      trigger_error("Wrong action type '".$Action."'.");
+      exit();
     }
 
     /* Preset required values */
+    $select_set = FALSE;
     foreach($FAI_group as $type => $data){
       $FAI_group[$type]['selected'] = FALSE;
+      $FAI_group[$type]['freezed'] = isset($data['FAIstate']) && preg_match("/freeze/",$data['FAIstate']);
+      if(!$select_set && ($this->mode == "cut" || $this->mode == "edit") && !$FAI_group[$type]['freezed']){
+        $FAI_group[$type]['selected'] = TRUE;
+        $select_set =TRUE;
+      }
     }
     $this->FAI_group = $FAI_group;
   }
@@ -33,20 +42,28 @@ class faiGroupHandle{
   function save_object()
   {
     if(isset($_POST['faiGroupHandle'])){
-      foreach($this->FAI_group as $key => $group){
-        if(isset($_POST[$this->mode."_".$key])){
-          $this->FAI_group[$key]['selected'] = TRUE;
-        }else{
-          $this->FAI_group[$key]['selected'] = FALSE;
+      if(in_array($this->mode,array("copy","cut","remove"))){
+        foreach($this->FAI_group as $key => $group){
+          if(isset($_POST[$this->mode."_".$key])){
+            $this->FAI_group[$key]['selected'] = TRUE;
+          }else{
+            $this->FAI_group[$key]['selected'] = FALSE;
+          }
+        } 
+      }else{
+        if(isset($_POST['edit_selected']) && isset($this->FAI_group[get_post('edit_selected')])){
+          foreach($this->FAI_group as $key => $obj){
+            $this->FAI_group[$key]['selected'] = FALSE;
+          }
+          $this->FAI_group[get_post('edit_selected')]['selected'] = TRUE;
         }
-      } 
+      }
       if(isset($_POST['faiGroupHandle_apply']) || isset($_POST['faiGroupHandle_cancel'])){
         $this->open = FALSE;
       }
       if(isset($_POST['faiGroupHandle_cancel'])){
         $this->canceled = TRUE;
       }
-    
     }
   }