From: Davide Franco Date: Mon, 25 Oct 2010 19:59:23 +0000 (+0200) Subject: bacula-web: New function ByteToSize() in classe Bweb classe X-Git-Tag: Release-5.2.1~989 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=42a765131e6956583dcc9d818c2182ea11ebe29b;p=bacula%2Fbacula bacula-web: New function ByteToSize() in classe Bweb classe - New function BytesToSize created in order to replace fsize_format Smarty plugin in generaldata.tpl --- 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 {