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
- + get_size_web_sum_user($mem->user["uid"]); - + // $totalweb is in KB, so we call get_size_unit() with it in Bytes + $t=$quota->get_size_unit($totalweb * 1024); echo "

"._("Web Space:")." "; - echo sprintf("%.1f", $totalweb / 1024)." "._("MB"); + echo sprintf("%.1f", $t['size'])." ".$t['unit']; echo "

"; ?> - + @@ -45,32 +47,36 @@ if (!isset($mode)) { # when included from adm_login, mode is not set $totalmail+=$mstmp; } + $t=$quota->get_size_unit($totalmail); echo "

"._("Mailboxes size:")." "; - echo sprintf("%.1f", $totalmail / 1024)." "._("MB"); + echo sprintf("%.1f", $t['size'])." ".$t['unit']; echo "

"; - foreach ($domaines_user as $domaine) { + foreach ($domaines_user as $domaine) { $alias_sizes = $quota->get_size_mail_details_domain($domaine); - $domsize = 0; + $domsize = 0; foreach ($alias_sizes as $e) { - $domsize += $e['size']; - echo ""; - echo ""; - 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 ""; + echo ""; + 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 "\"".$pc."%\""; + } + echo ""; } - if ($mode==0) { - echo sprintf("%.1f", $ms / 1024)." "._("MB"); - } elseif ($mode==1) { - echo sprintf("%.1f", $pc)." %"; - } else { - echo "\"".$pc."%\""; - } - echo ""; } if ($totalmail) { $tpc = intval(100 * $domsize / $totalmail); @@ -83,7 +89,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set if ($mode!=2) echo " style=\"text-align: right\""; echo ">"; if ($mode==0) { - echo sprintf("%.1f", $domsize / 1024)." "._("MB"); + echo sprintf("%.1f", $d['size'])." ".$d['unit']; } elseif ($mode==1) { echo sprintf("%.1f", $tpc)." %"; } else { @@ -91,18 +97,19 @@ if (!isset($mode)) { # when included from adm_login, mode is not set } echo ""; } - } +} ?>
{$domaine}".str_replace("_","@",$e["alias"])."
{$domaine}".str_replace("_","@",$e["alias"])."
- + get_size_db_sum_user($mem->user["login"]); + $t = $quota->get_size_unit($totaldb); 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 "".$d["db"].""; - $ds=$d["size"]; + $ds = $quota->get_size_unit($d["size"]); if ($totaldb) { - $pc=intval(100*$ds/$totaldb); + $pc=intval(100*$ds['size']/$totaldb); } else { $pc=0; } if (isset($mode) && $mode==0) { - echo sprintf("%.1f", $ds / 1024/1024)." "._("MB"); + echo sprintf("%.1f", $ds['size'])." ".$ds['unit']; } elseif (isset($mode) &&$mode==1) { echo sprintf("%.1f", $pc)." %"; } else { @@ -140,17 +147,16 @@ if (!isset($mode)) { # when included from adm_login, mode is not set - + get_size_mailman_sum_user($c["uid"]); if ($totallist) { -?> - -"._("Mailman lists:")." "; - echo sprintf("%.1f", $totallist/1024)." "._("MB"); - echo "

"; + // $totalweb is in KB, so we call get_size_unit() with it in Bytes + $t=$quota->get_size_unit($totallist * 1024); + echo "

"._("Mailman lists:")." "; + echo sprintf("%.1f", $t['size'])." ".$t['unit']; + echo "

"; ?> @@ -168,14 +174,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set echo ""; - $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 ==== */
".$d["list"]."