]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Removed fzise_format and new function in classes.inc
authorDavide Franco <bacula-dev@dflc.ch>
Wed, 27 Oct 2010 20:24:18 +0000 (22:24 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Tue, 2 Nov 2010 07:20:32 +0000 (08:20 +0100)
  - Removed fsize_format in the following templates last_run_report.tpl, generaldata.tpl and volumes.tpl
  - Created new function human_file_size that convert filesize in KB, MB, GB, etc...
  - Fixed GetDbSize function indentation in classes.inc
  - Fixed some php typo in classes.inc

gui/bacula-web/classes.inc
gui/bacula-web/index.php
gui/bacula-web/templates/generaldata.tpl
gui/bacula-web/templates/last_run_report.tpl
gui/bacula-web/templates/volumes.tpl

index a4abd4662267d5723fdde9d3d0351e7bfd958e89..df5adb8020f184c7bf94986bfc6f49a8c64002cf 100644 (file)
@@ -79,7 +79,7 @@ class Bweb extends DB {
                 
                 if (DB::isError($this->link))
                     die($this->link->getMessage());
-                $this->driver = $this->dsn[phptype];                            
+                $this->driver = $this->dsn['phptype'];                            
                 register_shutdown_function(array(&$this,'close'));
                $this->dbs_name = $this->dsn['database'];
        }
@@ -132,7 +132,7 @@ class Bweb extends DB {
                         while ( $tmp1 = $result->fetchRow() ) {
                                 $pos = array_key_exists($tmp[0],$volume);
                                 if ($pos != FALSE)
-                                        array_push($vo lume["$tmp[0]"],$tmp1);
+                                        array_push($volume["$tmp[0]"],$tmp1);
                                 else
                                         $volume += array($tmp[0]=>array($tmp1));
                         }
@@ -143,53 +143,61 @@ class Bweb extends DB {
                 return $volume;
         }
         
-        function GetDbSize() {
-                if ( $this->driver == "mysql") {
-                        $dbsize = $this->link->query("show table status")
-                                or die ("classes.inc: Error query: 3");
-                        if ( $dbsize->numRows() ) {
-                                while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
-                                        $database_size += $res["Data_length"];
-                        }
-                        else
-                                return 0;
-                }
-                else if ( $this->driver == "pgsql") {
-                        $dbsize = $this->link->query("select pg_database_size('$this->dbs_name')")
-                                or die ("classes.inc: Error query: 4");
-                       if (PEAR::isError($dbsize))
-                           die($dbsize->getMessage());
-                        if ( $dbsize->numRows() ) {
-                                while ( $res = $dbsize->fetchRow() )
-                                        $database_size += $res[0];
-                        }
-                        else
-                                return 0;
-                }       
-        $dbsize->free();
-        return $database_size;  
-        }
+               function human_file_size( $size, $decimal = 2 )
+               {
+                       $unit_id = 0;
+                       $lisible = false;
+                       $units = array('B','KB','MB','GB','TB');
+                       $hsize = $size;
+                               
+                       while( !$lisible ) {
+                               if ( $hsize >= 1024 ) {
+                                       $hsize    = $hsize / 1024;
+                                       $unit_id += 1;
+                               } 
+                               else {
+                                       $lisible = true;
+                               } 
+                       } 
+                       // Format human size
+                       $hsize = sprintf("%." . $decimal . "f", $hsize);
+                       return $hsize . ' ' . $units[$unit_id];
+               } // end function
+
                
-               function bytesToSize($bytes, $precision = 2)
-               {  
-                       $kilobyte = 1024;
-                       $megabyte = $kilobyte * 1024;
-                       $gigabyte = $megabyte * 1024;
-                       $terabyte = $gigabyte * 1024;
-                       if (($bytes >= 0) && ($bytes < $kilobyte)) {
-                               return $bytes . ' B'; }
-                       { elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) {
-                               return round($bytes / $kilobyte, $precision) . ' KB';
-                       } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) {
-                               return round($bytes / $megabyte, $precision) . ' MB';
-                       } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) {
-                               return round($bytes / $gigabyte, $precision) . ' GB';
-                       } elseif ($bytes >= $terabyte) {
-                               return round($bytes / $gigabyte, $precision) . ' TB';
-                       } else {
-                               return $bytes . ' B'; }
-                       }
-               }
+               function GetDbSize() 
+               {
+                       $database_size = 0;
+                       if ( $this->driver == "mysql") {
+                               $dbsize = $this->link->query("show table status") or die ("classes.inc: Error query: 3");
+                               
+                               if ( $dbsize->numRows() ) {
+                                       while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
+                                               $database_size += $res["Data_length"];
+                } else {
+                                       return 0;
+                               } // end if else
+            } // end if
+            else if ( $this->driver == "pgsql") {
+                               $dbsize = $this->link->query("select pg_database_size('$this->dbs_name')") or die ("classes.inc: Error query: 4");
+                               
+                               if (PEAR::isError($dbsize))
+                                       die($dbsize->getMessage());
+                    
+                                       if ( $dbsize->numRows() ) {
+                                               while ( $res = $dbsize->fetchRow() )
+                                                       $database_size += $res[0];
+                    } else {
+                                               return 0;
+                                       }
+            } // end if       
+                               
+                       $dbsize->free();
+               
+                       return $this->human_file_size( $database_size );  
+        } // end function GetDbSize()
+               
+} // end class Bweb
 
 class BGraph {
 
index 96fe053f23d6418c695c09239396843ff9945b80..80a506603e16b6442c33d9ec9597716acbe38d02 100644 (file)
@@ -55,9 +55,13 @@ if ( $dbSql->driver == "pgsql")
 $bytes_stored =& $dbSql->link->getOne("select SUM(VolBytes) from Media")
         or die ("Error query: 4");
 
+// Database size
 $smarty->assign('database_size', $dbSql->GetDbSize());
-$smarty->assign('bytes_stored',$bytes_stored);
 
+// Total bytes stored
+$smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
+
+// Number of clients
 $tmp = $client->fetchRow();
 $smarty->assign('clientes_totales',$tmp[0]);
 
@@ -72,7 +76,9 @@ $tmp = $last24bytes->fetchRow();
         $tmp = $last24bytes->fetchRow();        
 }*/
 
-$smarty->assign('bytes_totales',$tmp[0]);
+// Transfered bytes since last 24 hours
+$smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
+
 $smarty->assign('total_jobs', $tmp[1]);
 
 $tmp = $totalfiles->fetchRow();
index bd6ffa406d779bb87f444bc4aa49b463bff09941..348d488ad3b5286c83164a00a6768204bb25b255 100644 (file)
@@ -25,7 +25,7 @@
        </td>
        
        <td>
-       <font color=red>{$bytes_stored|fsize_format}</font>
+       <font color=red>{$bytes_stored}</font>
        </td>
 </tr>
 
@@ -43,7 +43,7 @@
        </td>
        
        <td>
-       <font color=red>{$database_size|fsize_format}</font>
+       <font color=red>{$database_size}</font>
        </td>
 </tr>
 
index bde0fc60b751b20a2a8c3a74d2682cb24d5d2c10..7c58f5c021cd427c5e145ef51700613c7f126a5e 100644 (file)
@@ -43,7 +43,7 @@
                <b>{t}Bytes transferred last 24h{/t}</b>
        </td> 
        <td style="font-size: 13px; color: blue">
-               {$bytes_totales|fsize_format}
+               {$bytes_totales}
        </td>
  </tr> 
  <tr>
index 1a74ee98b89e26e8521f31e74b11337c3551cf16..7bbc12adf1259dba41a47a7153820f6ee78b8a63 100644 (file)
@@ -34,7 +34,7 @@
                         {/if}
                                 <tr align=center bgcolor={cycle values="#D9E3FC,#CBE7F5"}>
                                         <td>{$current3.0}</td>
-                                        <td>{$current3.1|fsize_format|default:0}</td>
+                                        <td>{$current3.1}</td>
                                         <td>{$current3.4}</td>
                                         <td {popup text='$current3.6}>
                                                                                        {if $current3.6|date_format:"%Y" <= "1979"}