Code

Gray out preserved partitions
[gosa.git] / plugins / admin / fai / class_faiPartitionTableEntry.inc
index 878ffafe935e28c69c6028ff42b2b60cda0c4844..9b21944a9f51a8dcfaae49021cfd75a9158f4e72 100644 (file)
@@ -17,7 +17,6 @@ class faiPartitionTableEntry extends plugin
   
   var $partitions           = array();
   var $UsedAttrs            = array();
-  var $AvailableDiskNames   = array();
   var $is_edit              = false;
   var $old_cn               = "";
   var $status               = "new";
@@ -29,16 +28,6 @@ class faiPartitionTableEntry extends plugin
     $this->UsedAttrs  = array("cn","description","FAIpartitionType","FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
                          "FAImountOptions","FAIfsOptions","FAIpartitionFlags");
 
-    /* Generate available disknames, to avoid duplicates in cn */
-    $this->AvailableDiskNames = array();
-    foreach(array("a","b","c","d","e","f","g","h") as $ts){
-      if(!in_array("hd".$ts,$usedDiskNames)){
-        $this->AvailableDiskNames["hd".$ts]= "hd".$ts;
-      }
-    }
-    
-    $this->AvailableDiskNames['disk1']= "disk1";
-    $this->AvailableDiskNames['disk2']= "disk2";
     /* Default status is new */
     $this->status = "new";    
  
@@ -140,7 +129,6 @@ class faiPartitionTableEntry extends plugin
       $this->partitions = $tmp;
     }
 
-
     /* To add a partitions we only append an empty 
      *  array to the already defined partitions.
      */
@@ -153,10 +141,6 @@ class faiPartitionTableEntry extends plugin
       $this->partitions[count($this->partitions)+1]=$tmp;
     }
 
-    /* Tell smarty which Disknames are available.
-     */
-    $smarty->assign("cns", $this->AvailableDiskNames); 
-    
     /* $setup contains a table with the partitions. 
      */
     $smarty->assign("setup", $this->generateParts());
@@ -183,34 +167,39 @@ class faiPartitionTableEntry extends plugin
   {
     /* Define Arrays with allowed syntax */
     $PartitionTypes   = array("primary","logical");
-    $FAIfsTypes       = array("ext2","ext3","xfs","swap","reiserfs","dos fat 16","win fat 32");
+    $FAIfsTypes       = array("ext2","ext3","xfs","swap","reiserfs","dosfat16","winfat32");
 
     /* Display Header */
-    $str = "<table>";
-    $str .= "<tr>";
-    $str .= "<td>"._("Nr")."</td>";
-    $str .= "<td>"._("Name")."</td>";
-    $str .= "<td>"._("Description")."</td>";
-    $str .= "<td>"._("Type")."</td>";
-    $str .= "<td>"._("FS type")."</td>";
-    $str .= "<td>"._("Mount point")."</td>";
-    $str .= "<td>"._("Size in MB")."</td>";
-    $str .= "<td>"._("Mount options")."</td>";
-    $str .= "<td>"._("FS option")."</td>";
-    $str .= "<td>"._("Preserve")."</td>";
-    $str .= "<td></td>";
-    $str .= "</tr>";
-
+    $str = "<table style='width:100%'>";
+    if (count($this->partitions)){
+      $str .= "<tr>";
+      $str .= "<td>"._("Type")."</td>";
+      $str .= "<td>"._("FS type")."</td>";
+      $str .= "<td>"._("Mount point")."</td>";
+      $str .= "<td>"._("Size in MB")."</td>";
+      $str .= "<td>"._("Mount options")."</td>";
+      $str .= "<td>"._("FS option")."</td>";
+      $str .= "<td>"._("Preserve")."</td>";
+      $str .= "<td>&nbsp;</td>";
+      $str .= "</tr>";
+    }
+    
     /* Walk through all defined partitions.
      * Create a new row for each partition and append it to 
      *  the header defined above.
      * To be able to check the posts later, we append a key to each single postfield. like cn_1 ... cn_2
      */
     foreach($this->partitions as $key => $part){
+      
+      $dis = "";
+      if($part['FAIpartitionFlags'] == "preserve"){
+        $dis = " disabled ";
+      }
+
       if($part['status']!="delete"){
         /* Generate Partition select box  
          */
-        $PartitionType = "<select name='FAIpartitionType_".$key."'>";
+        $PartitionType = "<select name='FAIpartitionType_".$key."' id='FAIpartitionType_".$key."' ".$dis.">";
         foreach($PartitionTypes as $type){
           if($part['FAIpartitionType'] == $type){
             $PartitionType .="<option value='".$type."' selected >".$type."</option>";
@@ -223,7 +212,7 @@ class faiPartitionTableEntry extends plugin
 
         /* Generate fsType select box  
          */
-        $FAIfsType= "<select name='FAIfsType_".$key."'>";
+        $FAIfsType= "<select name='FAIfsType_".$key."' id='FAIfsType_".$key."' ".$dis.">";
         foreach($FAIfsTypes as $type){
           if($part['FAIfsType'] == $type){
             $FAIfsType  .="<option value='".$type."' selected >".$type."</option>";
@@ -233,23 +222,29 @@ class faiPartitionTableEntry extends plugin
         }        
         $FAIfsType.="</select>";   
 
-        $str .= "<tr>";
-        $str .= "<td>".($key)."</td>";
-        $str .= "<td><input name='cn_".$key."'                value='".$part['cn']."'               maxlength='8' style='width:80px;'></td>";
-        $str .= "<td><input name='description_".$key."'       value='".$part['description']."'      maxlength='8' style='width:80px;'></td>";
-        $str .= "<td>".$PartitionType."</td>";
-        $str .= "<td>".$FAIfsType."</td>";
-        $str .= "<td><input name='FAImountPoint_".$key."'     value='".$part['FAImountPoint']."'    ></td>";
-        $str .= "<td><input name='FAIpartitionSize_".$key."'  value='".$part['FAIpartitionSize']."' style='width:200px;'></td>";
-        $str .= "<td><input name='FAImountOptions_".$key."'   value='".$part['FAImountOptions']."'  style='width:100px;'></td>";
-        $str .= "<td><input name='FAIfsOptions_".$key."'      value='".$part['FAIfsOptions']."'     style='width:100px;'></td>";
+        $str .= "\n<tr>";
+        $str .= "\n<td>".$PartitionType."</td>";
+        $str .= "\n<td>".$FAIfsType."</td>";
+        $str .= "\n<td><input name='FAImountPoint_".$key."'    ".$dis."  value='".$part['FAImountPoint']."'    id='FAImountPoint_".$key."'></td>";
+        $str .= "\n<td><input name='FAIpartitionSize_".$key."'  ".$dis." value='".$part['FAIpartitionSize']."' id='FAIpartitionSize_".$key."' size=12></td>";
+        $str .= "\n<td><input name='FAImountOptions_".$key."'  ".$dis."  value='".$part['FAImountOptions']."'  id='FAImountOptions_".$key."' style='width:100px;'></td>";
+        $str .= "\n<td><input name='FAIfsOptions_".$key."'     ".$dis."  value='".$part['FAIfsOptions']."'     id='FAIfsOptions_".$key."' style='width:100px;'></td>";
+
+        $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ".
+                                 "changeState('FAIpartitionSize_".$key."') ; ".
+                                 "changeState('FAImountOptions_".$key."') ; ".
+                                 "changeState('FAIpartitionType_".$key."') ; ".
+                                 "changeState('FAIfsType_".$key."') ; ".
+                                 "changeState('FAIfsOptions_".$key."') ; \"";
+  
+
         if($part['FAIpartitionFlags']!=false){
-          $str .= "<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked></td>";
+          $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked ".$changeState."></td>";
         }else{
-          $str .= "<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve'></td>";
+          $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' ".$changeState."></td>";
         }
-        $str .= "<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."'></td>";
-        $str .= "</tr>";    
+        $str .= "\n<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."'></td>";
+        $str .= "\n</tr>";    
       }
     }
     $str.="</table>";
@@ -257,6 +252,36 @@ class faiPartitionTableEntry extends plugin
 
   }
 
+  function save()
+  {
+    $tmp = array();
+    $tmp['cn']          = $this->DISK_cn;
+
+    /* Attach partitions */
+    foreach($this->partitions as $key=>$val) {
+      $this->partitions[$key]['FAIpartitionNr']=$key;
+    }
+
+    /* Attach deleted */
+    foreach($this->deletePartitions as $key=>$val) {
+      $this->partitions[$key."-delete"]=$val;
+      $this->partitions[$key."-delete"]['status']="delete";
+    }
+
+    $tmp['description'] = $this->DISK_description;
+    $tmp['partitions']  = $this->partitions;
+    $tmp['status']      = $this->status;
+
+    /* If hdd name has changed, tell partitionTable to rename it */
+    if(($this->is_edit)&&($this->old_cn != $this->DISK_cn)){
+      $tmp['rename']['from']  = $this->old_cn;
+      $tmp['rename']['to']    = $this->DISK_cn;
+    }
+
+    return($tmp);
+  }
+
+
   /* Save data to object */
   function save_object()
   {
@@ -288,17 +313,6 @@ class faiPartitionTableEntry extends plugin
   {
     $message= array();
    
-    /* Check descriptions 
-     */ 
-    if(empty($this->DISK_description)){
-      $message[] = _("Please enter a description for your disk.");
-    }
-
-    $str = utf8_encode("üöä");
-    if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->DISK_description)){
-      $message[]=_("Please enter a valid description.");
-    }
-    
     /* check every partition.
      * if there is an invalid value defined, append an errorstr to message
      */
@@ -310,140 +324,64 @@ class faiPartitionTableEntry extends plugin
     }      
 
     foreach($this->partitions as $key => $part){
-    
-      if((empty($part['cn']))||(preg_match("/[^0-9a-z]/",$part['cn']))){
-        $message[]=sprintf(_("Please enter a valid name for partition %s."),($key));
-      }
-
-      if(in_array($part['cn'],$alreadyUsed['cn'])){
-        $message[]=sprintf(_("please enter a unique name for partition %s"),($key));
+  
+      /* Skip all checks, if preserve is set */ 
+      if($part['FAIpartitionFlags'] == "preserve"){
+        $this->partitions[$key]['FAIpartitionType'] = "preserve";
+        $this->partitions[$key]['FAIfsType']        = "preserve";
+        $this->partitions[$key]['FAIpartitionSize'] = "preserve";
+        continue;
       }
-    
-      if(in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint'])){
+      if((in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint']))&&($part['FAIfsType']!="swap")){
         $message[]=sprintf(_("please enter a unique mount point for partition %s"),($key));
       }
 
-      if(empty($part['description'])){
-        $message[]=sprintf(_("Please enter a valid description for partition %s." ),($key));
-      }
-
-      if((empty($part['FAImountPoint']))||(!((preg_match("/^\/.*/",$part['FAImountPoint']))||(preg_match("/^swap$/",$part['FAImountPoint']))))){
-        $message[]=sprintf(_("Please enter a valid mount point for partition %s." ),($key));
+      if($part['FAIfsType']!="swap"){
+        if((empty($part['FAImountPoint']))||(!((preg_match("/^\/.*/",$part['FAImountPoint']))||(preg_match("/^swap$/",$part['FAImountPoint']))))){
+          $message[]=sprintf(_("Please enter a valid mount point for partition %s." ),($key));
+        }
       }
-
       if($part['FAIfsType'] == "swap"){
         if(in_array($part['FAIfsType'],$alreadyUsed['FAIfsType'])){
           $message[]=sprintf(_("File system type 'swap' is already used, change file system type for partition %s."),$key);
         }
       }
+      if(($part['FAIfsType'] == "swap")&&(!empty($part['FAImountPoint']))&&($part['FAImountPoint']!="swap")){
+        $message[]=_("Please use 'swap' as mount point, if 'swap' is used as fs-type.");
+      }
 
       $tmp = split("-",$part['FAIpartitionSize']);
-      if(count($tmp)!=2){
-        $message[]=sprintf(_("Please enter a range for partition size, 'from-to', for partition %s."),($key));
-      }elseif((!is_numeric($tmp[0]))||(!is_numeric($tmp[1]))){
-        $message[]=sprintf(_("Please enter a valid range for partition %s."),($key)); 
-      }elseif($tmp[0]>=$tmp[1]){
-        $message[]=sprintf(_("Please enter a valid range for partition %s."),($key));
-      }elseif($this->checkSize($part['FAIpartitionSize'],$alreadyUsed['FAIpartitionSize'],$key)){
-        $message[]=$this->checkSize($part['FAIpartitionSize'],$alreadyUsed['FAIpartitionSize'],$key);
+      switch (count($tmp)){
+        case 0:
+                $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key));
+                break;
+        case 1:
+                if (!is_id(is_id($tmp[0]))){
+                  $message[]= sprintf(_("Please enter a valid partition size for partition %s."),($key));
+                }
+                break;
+                
+        case 2:
+                if((!is_id($tmp[0]))||(!is_id($tmp[1]))){
+                  $message[]=sprintf(_("Please enter a valid range for partition %s."),($key)); 
+                }elseif($tmp[0]>=$tmp[1]){
+                  $message[]=sprintf(_("Please enter a valid range for partition %s."),($key));
+                }
+                break;
+
+        default:
+                $message[]=sprintf(_("Please enter a range for partition size for partition %s."),($key));
       }
+
       foreach($this->UsedAttrs as $attrs){
         $alreadyUsed[$attrs][$key] = $part[$attrs];
       }      
     }
 
-
-    /* Only show 5 errors */
-    $cnt = 0;
-    if(count($message)>5){
-      foreach($message as $msg){
-        if($cnt < 5){
-          $tmp2[]=$msg;
-        }
-        $cnt ++;
-      }
-    $tmp2[] = "...";
-    $message = $tmp2;
-    }
-
     return ($message);
   }
  
-
-  /* This function checks the selected partition sizes 
-   * If a size setting overlap with another, it returns an error msg
-   */ 
-  function checkSize($current,$others,$ckey){
-    $tmp = split("-",$current);
-    $from = $tmp[0];
-    $to   = $tmp[1];
-    foreach($others as $key=> $other){
-      $tmp  = split("-",$other);
-      $oth_from = $tmp[0];
-      $oth_to   = $tmp[1];
-      /* surrounds another entry */
-      if( (($from <= $oth_from)&&($to >= $oth_to))||    // inside
-          (($from >= $oth_from)&&($to <= $oth_to))||    // outside
-          (($to >= $oth_from)&&($to <= $oth_to))  ||    // overlap at right
-          (($from >= $oth_from)&&($from <= $oth_to)) ){ // overlap left
-        $message =sprintf( _("Size settings for partition %s, overlap with size settings for partition %s."),$ckey,$key);
-        return($message);
-      }
-    }
-    return(false);
-  }
-  
-  function save()
-  {
-    /* This function returns the new or edited disk with its partitions.
-     * If the disk was edited and not a new one, we reset the name of the disk
-     *  to keep the correct index.
-     */
-
-    /* Check partition rename
-    */
-    foreach($this->partitions as $key => $part){
-      if($part['cn'] != $part['old_cn']){
-        if($part['status'] == "edited"){
-
-          $tmp          = $part;
-          $tmp['status']= "delete";
-          $tmp['cn']    = $part['old_cn'];
-
-          $this->deletePartitions[] = $tmp;
-        }
-        $this->partitions[$key]['old_cn']=$part['cn'];
-        $this->partitions[$key]['status']="new";
-      }
-    }
-
-    $tmp = array();
-    $tmp['cn']          = $this->DISK_cn;
-    /* Attach partitions */ 
-    foreach($this->partitions as $key=>$val) {
-      $this->partitions[$key]['FAIpartitionNr']=$key;
-    }
-
-    /* Attach deleted */ 
-    foreach($this->deletePartitions as $key=>$val) {
-      $this->partitions[$key."-delete"]=$val;
-      $this->partitions[$key."-delete"]['status']="delete";
-    } 
-    $tmp['description'] = $this->DISK_description;
-    $tmp['partitions']  = $this->partitions;
-    $tmp['status']      = $this->status;
-
-    /* If hdd name has changed, tell partitionTable to rename it */
-    if(($this->is_edit)&&($this->old_cn != $this->DISK_cn)){
-      $tmp['rename']['from']  = $this->old_cn;    
-      $tmp['rename']['to']    = $this->DISK_cn;    
-    }
-
-    return($tmp);
-  }
-
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: