]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Added boolean parameter display_unit and fixed bug with unit algorythm
authorDavide Franco <bacula-dev@dflc.ch>
Wed, 6 Jul 2011 17:15:59 +0000 (19:15 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:20 +0000 (14:49 +0200)
gui/bacula-web/includes/utils/cutils.class.php

index 7b38c83f628f9c6921af0d8b7bd6fb074da1f435..aa08a9bd97bdfe3cb2a27245fa722fcf5b543e95 100644 (file)
 +-------------------------------------------------------------------------+ 
 */
 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;
        }
 }