Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiPartitionTableEntry.inc
index e8db4d5e40c54f185f090ff41f65e6991a218211..110fa50c35d92663a40203e0ae90149373e4b986 100644 (file)
@@ -9,11 +9,11 @@ class faiPartitionTableEntry extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes   = array("DISK_cn","DISK_description");
+  var $attributes   = array("DISKcn","DISKdescription");
   var $objectclasses= array();
 
-  var $DISK_cn              = "";
-  var $DISK_description     = "";
+  var $DISKcn              = "";
+  var $DISKdescription     = "";
   
   var $partitions           = array();
   var $UsedAttrs            = array();
@@ -22,6 +22,8 @@ class faiPartitionTableEntry extends plugin
   var $status               = "new";
   var $deletePartitions     = array();
 
+  var $FAIstate             = "";
+
   function faiPartitionTableEntry ($config, $dn= NULL,$usedDiskNames=array(),$disk=false)
   {
     plugin::plugin ($config, $dn);
@@ -71,16 +73,20 @@ class faiPartitionTableEntry extends plugin
       }
 
       /* Set default attributes */
-      $this->DISK_cn          = $disk['cn'];
-      $this->DISK_description = $disk['description'];
+      $this->DISKcn          = $disk['cn'];
+      $this->DISKdescription = $disk['description'];
       $this->partitions       = $disk['partitions'];
       $this->is_edit          = true;
       $this->old_cn           = $disk['cn'];
     }
   }
 
+
   function execute()
   {
+    /* Call parent execute */
+    plugin::execute();
+
     /* Fill templating stuff */
     $smarty     = get_smarty();
     $s_action   = "";
@@ -104,7 +110,7 @@ class faiPartitionTableEntry extends plugin
      * The number specifies the index we want to delete
      */
     foreach($_POST as $name => $value){
-      if(preg_match("/Delete_.*/",$name)){
+      if((preg_match("/Delete_.*/",$name)) && $this->acl_is_removeable()){
         $tmp = split("_",$name);
         $s_action = "remove";
         $s_entry  = $tmp[1]; 
@@ -115,9 +121,10 @@ class faiPartitionTableEntry extends plugin
      * We must sort the index again, else we possibly got problems 
      * with partitions order.
      */
-    if($s_action == "remove"){
+    if($s_action == "remove" && $this->acl_is_removeable()){
       if($this->partitions[$s_entry]['status'] == "edited"){
-        $this->deletePartitions[]= $this->partitions[$s_entry];
+        $this->deletePartitions[$s_entry]= $this->partitions[$s_entry];
+        $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry;
         unset($this->partitions[$s_entry]);
       }else{
         unset($this->partitions[$s_entry]);
@@ -129,11 +136,10 @@ class faiPartitionTableEntry extends plugin
       $this->partitions = $tmp;
     }
 
-
     /* To add a partitions we only append an empty 
      *  array to the already defined partitions.
      */
-    if(isset($_POST['AddPartition'])){
+    if(isset($_POST['AddPartition']) && $this->acl_is_createable()){
       foreach($this->UsedAttrs as $attr){
         $tmp[$attr]                = "";     
       }
@@ -149,15 +155,21 @@ class faiPartitionTableEntry extends plugin
       $smarty->assign($attr,$this->$attr);
     }
 
-    /* The user can't change a diskname 
-     *  if we are currently in edit mode for the specified disk 
-     */
-//    if($this->is_edit){
-//      $smarty->assign("DISK_cnACL"," disabled ");
-//    }else{
-      $smarty->assign("DISK_cnACL","");
-//    }
+    $tmp = $this->plInfo();
+    $sacl = "";
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
 
+      $acl = $this->getacl($name);
+      $sacl .= $acl;
+      if($this->FAIstate == "freezed"){
+        $acl = preg_replace("/w/","",$acl);
+      }
+      $smarty->assign($name."ACL",$acl);
+    }
+    $smarty->assign("allowSave",$sacl);
+   
+    $smarty->assign("sub_object_is_createable",$this->acl_is_createable());
     /* Fetch template and show the result
      */
     $display.= $smarty->fetch(get_template_path('faiPartitionTableEntry.tpl', TRUE));
@@ -167,20 +179,20 @@ class faiPartitionTableEntry extends plugin
   function generateParts()
   {
     /* Define Arrays with allowed syntax */
-    $PartitionTypes   = array("primary","logical");
-    $FAIfsTypes       = array("ext2","ext3","xfs","swap","reiserfs","dos fat 16","win fat 32");
+    $PartitionTypes   = array("primary"=>_("primary"),"logical"=>_("logical"));
+    $FAIfsTypes       = array("ext2","ext3","xfs","swap","reiserfs","dosfat16","winfat32");
 
     /* Display Header */
-    $str = "<table style='width:100%'>";
+    $str = "<table summary='' 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><b>"._("Type")."</b></td>";
+      $str .= "<td><b>"._("FS type")."</b></td>";
+      $str .= "<td><b>"._("Mount point")."</b></td>";
+      $str .= "<td><b>"._("Size in MB")."</b></td>";
+      $str .= "<td><b>"._("Mount options")."</b></td>";
+      $str .= "<td><b>"._("FS option")."</b></td>";
+      $str .= "<td><b>"._("Preserve")."</b></td>";
       $str .= "<td>&nbsp;</td>";
       $str .= "</tr>";
     }
@@ -191,46 +203,99 @@ class faiPartitionTableEntry extends plugin
      * 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 ";
+      }
+
+      $disableALL = "";
+      if($this->FAIstate =="freeze"){
+        $disableALL = " disabled ";
+      }
+
       if($part['status']!="delete"){
+
         /* Generate Partition select box  
          */
-        $PartitionType = "<select name='FAIpartitionType_".$key."'>";
-        foreach($PartitionTypes as $type){
-          if($part['FAIpartitionType'] == $type){
-            $PartitionType .="<option value='".$type."' selected >".$type."</option>";
-          }else{
-            $PartitionType .="<option value='".$type."'>".$type."</option>";
-          }
-        }        
-        $PartitionType.="</select>";   
+        $PartitionType = "";
+        if($this->acl_is_writeable("FAIpartitionType")){
+          $PartitionType = "<select name='FAIpartitionType_".$key."' id='FAIpartitionType_".$key."' ".$disableALL.">";
+          foreach($PartitionTypes as $type => $PTname){
+            if($part['FAIpartitionType'] == $type){
+              $PartitionType .="<option value='".$type."' selected >".$PTname."</option>";
+            }else{
+              $PartitionType .="<option value='".$type."'>".$PTname."</option>";
+            }
+          }        
+          $PartitionType.="</select>";   
+        }elseif($this->acl_is_readable("FAIpartitionType")){
+          $PartitionType = $part['FAIpartitionType'];
+        }
 
 
         /* Generate fsType select box  
          */
-        $FAIfsType= "<select name='FAIfsType_".$key."'>";
-        foreach($FAIfsTypes as $type){
-          if($part['FAIfsType'] == $type){
-            $FAIfsType  .="<option value='".$type."' selected >".$type."</option>";
+        $FAIfsType= "";
+        if($this->acl_is_writeable("FAIfsType")){
+          $FAIfsType= "<select name='FAIfsType_".$key."' id='FAIfsType_".$key."' ".$dis." ".$disableALL.">";
+          foreach($FAIfsTypes as $type){
+            if($part['FAIfsType'] == $type){
+              $FAIfsType  .="<option value='".$type."' selected >".$type."</option>";
+            }else{
+              $FAIfsType .="<option value='".$type."'>".$type."</option>";
+            }
+          }        
+          $FAIfsType.="</select>";   
+        }elseif($this->acl_is_readable("FAIfsType")){
+          $FAIfsType = $part['FAIfsType'];
+        }
+
+        foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){
+          $$attr  = "";
+          if($this->acl_is_writeable($attr)){
+            $$attr = "<input name='".$attr."_".$key."'  ".$disableALL."  ".$dis."
+                        value='".$part[$attr]."'    id='".$attr."_".$key."'>";
+
+          }elseif($this->acl_is_readable($attr)){
+            $$attr = $part[$attr];
+          }
+        }
+
+
+        $str .= "\n<tr>";
+        $str .= "\n<td>".$PartitionType."</td>";
+        $str .= "\n<td>".$FAIfsType."</td>";
+        $str .= "\n<td>".$FAImountPoint."</td>";
+        $str .= "\n<td>".$FAIpartitionSize."</td>";
+        $str .= "\n<td>".$FAImountOptions."</td>";
+        $str .= "\n<td>".$FAIfsOptions."</td>";
+
+        $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ".
+                                 "changeState('FAIpartitionSize_".$key."') ; ".
+                                 "changeState('FAImountOptions_".$key."') ; ".
+                                 "changeState('FAIfsType_".$key."') ; ".
+                                 "changeState('FAIfsOptions_".$key."') ; \"";
+  
+        if($this->acl_is_writeable("FAIpartitionFlags")){
+          if($part['FAIpartitionFlags']!=false){
+            $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked ".$changeState." ".$disableALL."></td>";
+          }else{
+            $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' ".$changeState." ".$disableALL."></td>";
+          }
+        }else{
+          if($part['FAIpartitionFlags']!=false){
+            $str .= "<td>"._("False")."</td>";
           }else{
-            $FAIfsType .="<option value='".$type."'>".$type."</option>";
+            $str .= "<td>"._("True")."</td>";
           }
-        }        
-        $FAIfsType.="</select>";   
-
-        $str .= "<tr>";
-        $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']."' size=12></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>";
-        if($part['FAIpartitionFlags']!=false){
-          $str .= "<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked></td>";
+        }
+        if($this->acl_is_removeable()){
+          $str .= "\n<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."' ".$disableALL."></td>";    
         }else{
-          $str .= "<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve'></td>";
+          $str .= "\n<td><input type='submit' name='restricted' disabled value='"._("Remove")."'></td>";    
         }
-        $str .= "<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."'></td>";
-        $str .= "</tr>";    
+        $str .= "\n</tr>";    
       }
     }
     $str.="</table>";
@@ -241,7 +306,7 @@ class faiPartitionTableEntry extends plugin
   function save()
   {
     $tmp = array();
-    $tmp['cn']          = $this->DISK_cn;
+    $tmp['cn']          = $this->DISKcn;
 
     /* Attach partitions */
     foreach($this->partitions as $key=>$val) {
@@ -254,16 +319,15 @@ class faiPartitionTableEntry extends plugin
       $this->partitions[$key."-delete"]['status']="delete";
     }
 
-    $tmp['description'] = $this->DISK_description;
+    $tmp['description'] = $this->DISKdescription;
     $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)){
+    if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){
       $tmp['rename']['from']  = $this->old_cn;
-      $tmp['rename']['to']    = $this->DISK_cn;
+      $tmp['rename']['to']    = $this->DISKcn;
     }
-
     return($tmp);
   }
 
@@ -271,22 +335,21 @@ class faiPartitionTableEntry extends plugin
   /* Save data to object */
   function save_object()
   {
-    if(isset($_POST['TableEntryFrameSubmitted'])){
+
+
+    if((isset($_POST['TableEntryFrameSubmitted'])) && ($this->FAIstate != "freeze") ){
       plugin::save_object();
 
-      /* Check base attributes */
-      foreach($this->attributes as $attrs){
-        if(isset($_POST[$attrs])){
-          $this->$attrs = $_POST[$attrs];
-        }
-      }
-     
       foreach($this->partitions as $key => $part){
         foreach($this->UsedAttrs as $attrs){
-          if(isset($_POST[$attrs."_".$key])){
-            $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key];
-          }else{
-            $this->partitions[$key][$attrs] = false;
+
+          if($this->acl_is_writeable($attrs)){
+
+            if(isset($_POST[$attrs."_".$key])){
+              $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key];
+            }else{
+              $this->partitions[$key][$attrs] = false;
+            }
           }
         }
       }
@@ -297,8 +360,14 @@ class faiPartitionTableEntry extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
-   
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+  
+    /* Check for an empty disk name */
+    if(empty($this->DISKcn)){
+      $message[] = _("Please specify a valid disc name.");
+    }
+       
     /* check every partition.
      * if there is an invalid value defined, append an errorstr to message
      */
@@ -310,7 +379,14 @@ class faiPartitionTableEntry extends plugin
     }      
 
     foreach($this->partitions as $key => $part){
-    
+  
+      /* Skip all checks, if preserve is set */ 
+      if($part['FAIpartitionFlags'] == "preserve"){
+        $this->partitions[$key]['FAIfsType']        = "preserve";
+        $this->partitions[$key]['FAIpartitionSize'] = "preserve";
+        continue;
+      }
       if((in_array($part['FAImountPoint'],$alreadyUsed['FAImountPoint']))&&($part['FAIfsType']!="swap")){
         $message[]=sprintf(_("please enter a unique mount point for partition %s"),($key));
       }
@@ -341,7 +417,7 @@ class faiPartitionTableEntry extends plugin
                 break;
                 
         case 2:
-                if((!is_id($tmp[0]))||(!is_id($tmp[1]))){
+                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));
@@ -357,8 +433,46 @@ class faiPartitionTableEntry extends plugin
       }      
     }
 
+    $cnt = 0;
+    foreach($this->partitions as $key => $part){
+      if($part['FAIpartitionType'] == "primary"){
+        $cnt ++ ; 
+      }
+    }
+    if($cnt > 3){
+      $message[] = _("You have more than 3 primary partition table entries in your configuration, please check your configuration twice.");
+    }
+
     return ($message);
   }
+
+  
+
+  /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName" => _("Partition table entry"),
+          "plDescription" => _("FAI partition table entry"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 27,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "DISKcn"           => _("Name"),
+            "DISKdescription"  => _("Description"),
+            "FAIpartitionType"  => _("Partition type"),
+            "FAIpartitionNr"    => _("Partition no."),
+            "FAIfsType"         => _("File system type"),
+            "FAImountPoint"     => _("Mount point"),
+            "FAIpartitionSize"  => _("Partition size"),
+            "FAImountOptions"   => _("Mount options"),
+            "FAIfsOptions"      => _("File system options"),
+            "FAIpartitionFlags" => _("Partition flags"))
+          ));
+  }
+
  
 }