diff --git a/bureau/admin/quotas_oneuser.php b/bureau/admin/quotas_oneuser.php index 7dd07018..e9dae581 100644 --- a/bureau/admin/quotas_oneuser.php +++ b/bureau/admin/quotas_oneuser.php @@ -3,6 +3,7 @@ require_once("../class/config.php"); if (!defined("QUOTASONE")) return; +//FIXME missing getfield for $mode if (!isset($mode)) { # when included from adm_login, mode is not set $mode = 0; } @@ -13,19 +14,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
"._("Web Space:")." "; - echo sprintf("%.1f", $totalweb / 1024)." "._("MB"); + echo sprintf("%.1f", $t['size'])." ".$t['unit']; echo "
"; ?> - +{$domaine} | "; - echo "".str_replace("_","@",$e["alias"])." | "; - echo ""; - $ms=$e["size"]; - if ($totalmail) { - $pc=intval(100*$ms/$totalmail); - } else { - $pc=0; + if($e['size'] > 0) { + $domsize += $e['size']; + $d = $quota->get_size_unit($domsize); + echo " |
{$domaine} | "; + echo "".str_replace("_","@",$e["alias"])." | "; + echo "";
+ $ms = $quota->get_size_unit($e['size']);
+ if ($totalmail) {
+ $pc=intval(100*($ms['size']/$totalmail));
+ } else {
+ $pc=0;
+ }
+ if ($mode==0) {
+ echo sprintf("%.1f", $ms['size'])." ".$ms['unit'];
+ } elseif ($mode==1) {
+ echo sprintf("%.1f", $pc)." %";
+ } else {
+ echo "![]() |
"._("Databases:")." "; - echo sprintf("%.1f", $totaldb/(1024*1024))." "._("MB"); + echo sprintf("%.1f", $t['size'])." ".$t['unit']; echo "
"; ?> @@ -121,14 +128,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set echo ""._("Mailman lists:")." "; + echo sprintf("%.1f", $t['size'])." ".$t['unit']; + echo "
"; ?>".$d["list"]." | "; - $ds=$d["size"]; + $ds = $quota->get_size_unit($d["size"] * 1024); if ($totallist) { - $pc=intval(100*$ds/$totallist); + $pc=intval(100*$ds['size']/$totallist); } else { $pc=0; } if ($mode==0) { - echo sprintf("%.1f", $ds / 1024)." "._("MB"); + echo sprintf("%.1f", $ds['size'])." ".$ds['unit']; } elseif ($mode==1) { echo sprintf("%.1f", $pc)." %"; } else { diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index 6fe70e4e..12b4411c 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -261,7 +261,7 @@ class m_quota { if(empty($type)) return false; $type=strtolower($type); if (!preg_match("#^[a-z0-9]*$#",$type)) { - $err->raise("quota", _("Type can only contains characters a-z and 0-9")); + $err->raise("quota", "Type can only contains characters a-z and 0-9"); return false; } while (list($key,$val)=each($qlist)) { @@ -401,7 +401,6 @@ class m_quota { return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';"); } - /* sum of mailbox sizes from all domains */ function get_size_mail_sum_all() { return $this->_get_sum_sql("SELECT SUM(bytes) AS sum FROM mailbox;"); @@ -409,7 +408,7 @@ class m_quota { /* sum of mailbox sizes for one domain */ function get_size_mail_sum_domain($dom) { - return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_view WHERE user LIKE '%@{$dom}'"); + return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_view WHERE user LIKE '%@{$dom}';"); } /* count of mailbox sizes from all domains */ @@ -424,10 +423,9 @@ class m_quota { /* get list of mailbox alias and size for one domain */ function get_size_mail_details_domain($dom) { - return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE alias LIKE '%@{$dom}' ORDER BY alias;"); + return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;"); } - /* sum of mailman lists sizes from all domains */ function get_size_mailman_sum_all() { return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman;"); @@ -458,7 +456,6 @@ class m_quota { return $this->_get_size_and_record_sql("SELECT list,size FROM size_mailman WHERE uid='{$u}' ORDER BY list ASC"); } - /* sum of databases sizes from all users */ function get_size_db_sum_all() { return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db;"); @@ -484,7 +481,16 @@ class m_quota { return $this->_get_size_and_record_sql("SELECT db,size FROM size_db WHERE db='{$u}' OR db LIKE '{$u}\_%';"); } - + /* Return appropriate value and unit of a size given in Bytes (e.g. 1024 Bytes -> return 1 KB) */ + function get_size_unit($size) { + $units=array(1073741824=>_("GB"), 1048576=>_("MB"), 1024=>_("KB"), 0=>_("B")); + foreach($units as $value=>$unit){ + if($size>=$value){ + $size=str_pad(round($size/($value ? $value : 1), 1), 5, ' ', STR_PAD_LEFT); + return array('size'=>$size, 'unit'=>$unit); + } + } + } /* ==== Hook functions ==== */ |