Code

Updated Partition creation
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 16 May 2011 06:41:25 +0000 (06:41 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 16 May 2011 06:41:25 +0000 (06:41 +0000)
-Allow to enter partition size with its unit e.g. 100GB

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20828 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc
gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc

index 76938fb9eaf2cf05360c096b06ea274e8c651e90..dea20dcb355b0cf1607d6698f836353b54d4a3cd 100644 (file)
@@ -284,6 +284,30 @@ class AddPartitionDialog
         }
     }
 
+   
+    /*! \brief  Converts a given size string to its size-value in MB.
+     *              E.g.        '200TB' => '209715200' MB
+     */ 
+    function convertSize($size)
+    {
+        $map = array();
+        $map['/mb/i'] = 1;
+        $map['/m/i'] = 1;
+        $map['/gb/i'] = 1024;
+        $map['/g/i'] = 1024;
+        $map['/tb/i'] = 1024;
+        $map['/t/i'] = 1024;
+        $map['/pb/i'] = 1024;
+        $map['/p/i'] = 1024;
+        foreach($map as $key => $multiplicator){
+            if(preg_match($key, $size)){
+                $size = intval(preg_replace("/[^0-9]/", "", $size));
+                return($size * $multiplicator);
+            }
+        }
+        return(intval(preg_replace("/[^0-9]/", $size)));
+    }
+
 
     /*! \brief     Stores the changes back to the remote table model. 
      *  @return    TRUE on success else false.
@@ -325,7 +349,7 @@ class AddPartitionDialog
             $fsOptions = $this->v_fsOptions;
             $group = $this->v_group;
             $target = $this->v_mountPoint;
-            $size = intval($this->v_size);
+            $size = $this->convertSize($this->v_size);
             $encrypt = $this->v_encrypt;
             
             $maxSize = NULL;
@@ -404,7 +428,7 @@ class AddPartitionDialog
             }
 
             // Collect options
-            $size = intval($this->p_size);
+            $size = $this->convertSize($this->p_size);
             $maxSize = NULL;
             if($this->p_size_options == 2){
                 $maxSize = $this->p_size_max_value;
index 5b975365d8106f568257ddf6d306fb5b97b371a9..a8e6da20c0d307121a0407bafe91169eb09da4bf 100644 (file)
@@ -388,11 +388,7 @@ class DevicePartition
     function __convertPartSize($size)
     {
         $label = _("MB");
-        if($size%1024 == 0){
-            $size = $size/1024;
-            $label = _("GB");
-        }
-        return($size."".$label);
+        return($size." ".$label);
     }
 }