(See #1364) Fix some bugs that gave us a bad display of user quotas

This commit is contained in:
Axel ROGER 2012-11-08 14:33:46 +00:00
parent 28b949201e
commit ecafca7e58
2 changed files with 60 additions and 48 deletions

View File

@ -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
<div style="width: 550px">
<!-- Les esapces web -->
<!-- Webspaces -->
<?php
$totalweb = $quota->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 "<p>"._("Web Space:")." ";
echo sprintf("%.1f", $totalweb / 1024)."&nbsp;"._("MB");
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
?>
<!-- Les mails -->
<!-- Mails -->
<table class="tedit">
<thead>
@ -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 "<p>"._("Mailboxes size:")." ";
echo sprintf("%.1f", $totalmail / 1024)."&nbsp;"._("MB");
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
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 "<tr><td>{$domaine}</td>";
echo "<td>".str_replace("_","@",$e["alias"])."</td>";
echo "<td"; if ($mode!=2) echo " style=\"text-align: right\""; 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 "<tr><td>{$domaine}</td>";
echo "<td>".str_replace("_","@",$e["alias"])."</td>";
echo "<td"; if ($mode!=2) echo " style=\"text-align: right\""; 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'])."&nbsp;".$ms['unit'];
} elseif ($mode==1) {
echo sprintf("%.1f", $pc)."&nbsp;%";
} else {
echo "<img src=\"hippo_bleue.gif\" style=\"width: ".(2*$pc)."px; height: 16px\" alt=\"".$pc."%\" title=\"".$pc."\"/>";
}
echo "</td></tr>";
}
if ($mode==0) {
echo sprintf("%.1f", $ms / 1024)."&nbsp;"._("MB");
} elseif ($mode==1) {
echo sprintf("%.1f", $pc)."&nbsp;%";
} else {
echo "<img src=\"hippo_bleue.gif\" style=\"width: ".(2*$pc)."px; height: 16px\" alt=\"".$pc."%\" title=\"".$pc."\"/>";
}
echo "</td></tr>";
}
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 "><i>";
if ($mode==0) {
echo sprintf("%.1f", $domsize / 1024)."&nbsp;"._("MB");
echo sprintf("%.1f", $d['size'])."&nbsp;".$d['unit'];
} elseif ($mode==1) {
echo sprintf("%.1f", $tpc)."&nbsp;%";
} else {
@ -91,18 +97,19 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
}
echo "</i></td></tr>";
}
}
}
?>
</tbody>
</table>
<!-- Les bases -->
<!-- Databases -->
<?php
$totaldb = $quota->get_size_db_sum_user($mem->user["login"]);
$t = $quota->get_size_unit($totaldb);
echo "<p>"._("Databases:")." ";
echo sprintf("%.1f", $totaldb/(1024*1024))."&nbsp;"._("MB");
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
?>
@ -121,14 +128,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
echo "<tr><td>".$d["db"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\"";
echo ">";
$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)."&nbsp;"._("MB");
echo sprintf("%.1f", $ds['size'])."&nbsp;".$ds['unit'];
} elseif (isset($mode) &&$mode==1) {
echo sprintf("%.1f", $pc)."&nbsp;%";
} else {
@ -140,17 +147,16 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
</tbody>
</table>
<!-- Les listes -->
<!-- Mailing lists -->
<?php
$totallist = $quota->get_size_mailman_sum_user($c["uid"]);
if ($totallist) {
?>
<?php
echo "<p>"._("Mailman lists:")." ";
echo sprintf("%.1f", $totallist/1024)."&nbsp;"._("MB");
echo "</p>";
// $totalweb is in KB, so we call get_size_unit() with it in Bytes
$t=$quota->get_size_unit($totallist * 1024);
echo "<p>"._("Mailman lists:")." ";
echo sprintf("%.1f", $t['size'])."&nbsp;".$t['unit'];
echo "</p>";
?>
<table class="tedit">
@ -168,14 +174,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set
echo "<tr><td>".$d["list"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\"";
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)."&nbsp;"._("MB");
echo sprintf("%.1f", $ds['size'])."&nbsp;".$ds['unit'];
} elseif ($mode==1) {
echo sprintf("%.1f", $pc)."&nbsp;%";
} else {

View File

@ -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 ==== */