From 31631dc93c0f34f6f1a2af89976f53faed392f2d Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 16 May 2011 06:41:25 +0000 Subject: [PATCH] Updated Partition creation -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 --- .../goto/Device/class_AddPartitionDialog.inc | 28 +++++++++++++++++-- .../goto/Device/class_DevicePartition.inc | 6 +--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc index 76938fb9e..dea20dcb3 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_AddPartitionDialog.inc @@ -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; diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc index 5b975365d..a8e6da20c 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DevicePartition.inc @@ -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); } } -- 2.30.2