From 42a765131e6956583dcc9d818c2182ea11ebe29b Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Mon, 25 Oct 2010 21:59:23 +0200 Subject: [PATCH] bacula-web: New function ByteToSize() in classe Bweb classe - New function BytesToSize created in order to replace fsize_format Smarty plugin in generaldata.tpl --- gui/bacula-web/classes.inc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gui/bacula-web/classes.inc b/gui/bacula-web/classes.inc index b300c8f49d..a4abd46622 100644 --- a/gui/bacula-web/classes.inc +++ b/gui/bacula-web/classes.inc @@ -132,7 +132,7 @@ class Bweb extends DB { while ( $tmp1 = $result->fetchRow() ) { $pos = array_key_exists($tmp[0],$volume); if ($pos != FALSE) - array_push($volume["$tmp[0]"],$tmp1); + array_push($vo lume["$tmp[0]"],$tmp1); else $volume += array($tmp[0]=>array($tmp1)); } @@ -169,8 +169,27 @@ class Bweb extends DB { $dbsize->free(); return $database_size; } - -} + + 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'; } + } + } class BGraph { -- 2.39.5