From 476d89b54df17f9c9ecace16914822ed4af51be4 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Wed, 6 Jul 2011 19:15:59 +0200 Subject: [PATCH] bacula-web: Added boolean parameter display_unit and fixed bug with unit algorythm --- .../includes/utils/cutils.class.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gui/bacula-web/includes/utils/cutils.class.php b/gui/bacula-web/includes/utils/cutils.class.php index 7b38c83f62..aa08a9bd97 100644 --- a/gui/bacula-web/includes/utils/cutils.class.php +++ b/gui/bacula-web/includes/utils/cutils.class.php @@ -15,20 +15,20 @@ +-------------------------------------------------------------------------+ */ class CUtils { - static public function Get_Human_Size( $size, $decimal = 2, $unit = 'auto' ) + static public function Get_Human_Size( $size, $decimal = 2, $unit = 'auto', $display_unit = true ) { - $unit_id = 0; - $lisible = false; - $units = array('B','KB','MB','GB','TB'); - $hsize = $size; + $unit_id = 0; + $lisible = false; + $units = array('B','KB','MB','GB','TB'); + $hsize = $size; switch( $unit ) { case 'auto'; while( !$lisible ) { if ( $hsize >= 1024 ) { - $hsize = $hsize / 1024; - $unit_id += 1; + $hsize = $hsize / 1024; + $unit_id++; } else $lisible = true; @@ -36,13 +36,18 @@ class CUtils { break; default: - $p = array_search( $unit, $units); - $hsize = $hsize / pow(1024,$p); + $exp = array_keys( $units, $unit); + $unit_id = current($exp); + $hsize = $hsize / pow( 1024, $unit_id ); break; } // end switch $hsize = sprintf("%." . $decimal . "f", $hsize); - $hsize = $hsize . ' ' . $units[$unit_id]; + + // Display unit or not + if( $display_unit == true ) + $hsize = $hsize . ' ' . $units[$unit_id]; + return $hsize; } } -- 2.39.5