From: Davide Franco Date: Wed, 27 Oct 2010 20:24:18 +0000 (+0200) Subject: bacula-web: Removed fzise_format and new function in classes.inc X-Git-Tag: Release-5.2.1~988 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=69d49471bc4b5dcdfde098dc73a2e348d779d6ed;p=bacula%2Fbacula bacula-web: Removed fzise_format and new function in classes.inc - 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 --- diff --git a/gui/bacula-web/classes.inc b/gui/bacula-web/classes.inc index a4abd46622..df5adb8020 100644 --- a/gui/bacula-web/classes.inc +++ b/gui/bacula-web/classes.inc @@ -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 { diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 96fe053f23..80a506603e 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -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(); diff --git a/gui/bacula-web/templates/generaldata.tpl b/gui/bacula-web/templates/generaldata.tpl index bd6ffa406d..348d488ad3 100644 --- a/gui/bacula-web/templates/generaldata.tpl +++ b/gui/bacula-web/templates/generaldata.tpl @@ -25,7 +25,7 @@ - {$bytes_stored|fsize_format} + {$bytes_stored} @@ -43,7 +43,7 @@ - {$database_size|fsize_format} + {$database_size} diff --git a/gui/bacula-web/templates/last_run_report.tpl b/gui/bacula-web/templates/last_run_report.tpl index bde0fc60b7..7c58f5c021 100644 --- a/gui/bacula-web/templates/last_run_report.tpl +++ b/gui/bacula-web/templates/last_run_report.tpl @@ -43,7 +43,7 @@ {t}Bytes transferred last 24h{/t} - {$bytes_totales|fsize_format} + {$bytes_totales} diff --git a/gui/bacula-web/templates/volumes.tpl b/gui/bacula-web/templates/volumes.tpl index 1a74ee98b8..7bbc12adf1 100644 --- a/gui/bacula-web/templates/volumes.tpl +++ b/gui/bacula-web/templates/volumes.tpl @@ -34,7 +34,7 @@ {/if} {$current3.0} - {$current3.1|fsize_format|default:0} + {$current3.1} {$current3.4}