Refactoring quotas 'oneuser' display with get_size_xx function

This commit is contained in:
domi 2012-08-24 17:16:29 +00:00
parent 70009c1118
commit 4a8c177fcb
2 changed files with 70 additions and 15 deletions

View File

@ -8,10 +8,10 @@ if (!defined("QUOTASONE")) return;
<p><h3><center><?php __("Account"); ?> <span style="font-weight: bold;"><?php echo $c["login"]; ?></span></center></h3></p>
<?php
list($totalweb)=@mysql_fetch_array(mysql_query("SELECT SUM(size) FROM size_web WHERE uid = '" . $c["uid"] . "'"));
$totalweb = $quota->get_size_web_sum_user($c["uid"]);
echo "<p>"._("Web Space:")." ";
echo sprintf("%.1f", $totalweb / 1024)."&nbsp;"._("MB");
echo "<p>"._("Web Space:")." ";
echo sprintf("%.1f", $totalweb / 1024)."&nbsp;"._("MB");
echo "</p>";
?>
@ -31,14 +31,18 @@ if (!defined("QUOTASONE")) return;
$s=mysql_query("SELECT * FROM domaines WHERE compte='".$c["uid"]."';");
$totalmail=0;
while ($d=mysql_fetch_array($s)) {
list($mstmp)=@mysql_fetch_array(mysql_query("SELECT SUM(size) FROM size_mail WHERE alias LIKE '%\_".$d["domaine"]."';"));
$mstmp = $quota->get_size_mail_sum_domain($d["domaine"]);
$totalmail+=$mstmp;
}
echo "<p>"._("Mail boxes:")." ";
echo sprintf("%.1f", $totalmail / 1024)."&nbsp;"._("MB");
echo "</p>";
$s=mysql_query("SELECT * FROM domaines WHERE compte='".$c["uid"]."';");
while ($d=mysql_fetch_array($s)) {
$t=mysql_query("SELECT alias,size FROM size_mail WHERE alias LIKE '%\_".$d["domaine"]."' ORDER BY alias;");
while ($e=mysql_fetch_array($t)) {
$alias_sizes = $quota->get_size_mail_details_domain($d["domaine"]);
foreach ($alias_sizes as $e) {
echo "<tr><td>".$d["domaine"]."</td>";
echo "<td>".str_replace("_","@",$e["alias"])."</td>";
echo "<td";
@ -64,6 +68,15 @@ if (!defined("QUOTASONE")) return;
</table>
<p>&nbsp;</p>
<?php
// Espace DB :
$totaldb = $quota->get_size_db_sum_user($c["login"]);
echo "<p>"._("Databases:")." ";
echo sprintf("%.1f", $totaldb/(1024*1024))."&nbsp;"._("MB");
echo "</p>";
?>
<table class="tedit">
<thead>
<tr>
@ -74,10 +87,8 @@ if (!defined("QUOTASONE")) return;
<tbody>
<?php
// Espace DB :
list($totaldb)=@mysql_fetch_array(mysql_query("SELECT SUM(size) FROM size_db WHERE db='".$c["login"]."' OR db LIKE '".$c["login"]."\_%';"));
$s=mysql_query("SELECT db,size FROM size_db WHERE db='".$c["login"]."' OR db LIKE '".$c["login"]."\_%';");
while ($d=mysql_fetch_array($s)) {
$db_sizes = $quota->get_size_db_details_user($c["login"]);
foreach ($db_sizes as $d) {
echo "<tr><td>".$d["db"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\"";
echo ">";
@ -100,11 +111,17 @@ if (!defined("QUOTASONE")) return;
</table>
<?php
list($totallist)=@mysql_fetch_array(mysql_query("SELECT SUM(size) FROM size_mailman WHERE uid='".$c["uid"]."'"));
$totallist = $quota->get_size_mailman_sum_user($c["uid"]);
if ($totallist) {
?>
<p>&nbsp;</p>
<?php
echo "<p>"._("Mailman lists:")." ";
echo sprintf("%.1f", $totallist/1024)."&nbsp;"._("MB");
echo "</p>";
?>
<table class="tedit">
<thead>
<tr>
@ -115,9 +132,9 @@ if (!defined("QUOTASONE")) return;
<tbody>
<?php
// Espace Liste :
$s=mysql_query("SELECT list,size FROM size_mailman WHERE uid='".$c["uid"]."' ORDER BY list ASC");
while ($d=mysql_fetch_array($s)) {
// Espace Liste :
$mailman_size = $quota->get_size_mailman_details_user($c["uid"]);
foreach ($mailman_size as $d) {
echo "<tr><td>".$d["list"]."</td><td";
if ($mode!=2) echo " style=\"text-align: right\"";
echo ">";

View File

@ -387,6 +387,20 @@ class m_quota {
}
}
function _get_size_and_record_sql($sql) {
global $db,$err,$cuid;
$db->query($sql);
if ($db->num_rows() == 0) {
return array();
} else {
$ret = array();
while ($db->next_record()) {
$ret[] = $db->Record;
}
return $ret;
}
}
/* sum of websites sizes from all users */
function get_size_web_sum_all() {
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web;");
@ -397,6 +411,7 @@ 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(size) AS sum FROM size_mail;");
@ -417,6 +432,12 @@ class m_quota {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mail FROM size_mail WHERE alias LIKE '%\_{$dom}'");
}
/* 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 alias,size FROM size_mail WHERE alias 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;");
@ -427,6 +448,11 @@ class m_quota {
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'");
}
/* sum of mailman lists for one user */
function get_size_mailman_sum_user($u) {
return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
}
/* count of mailman lists sizes from all domains */
function get_size_mailman_count_all() {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman;");
@ -437,6 +463,12 @@ class m_quota {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
}
/* get list of mailman list and size for one user */
function get_size_mailman_details_user($u) {
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;");
@ -452,11 +484,17 @@ class m_quota {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db;");
}
/* count of mailman lists for one user */
/* count of databases for one user */
function get_size_db_count_user($u) {
return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
}
/* get list of databases name and size for one user */
function get_size_db_details_user($u) {
return $this->_get_size_and_record_sql("SELECT db,size FROM size_db WHERE db='{$u}' OR db LIKE '{$u}\_%';");
}
#list($dc)=@mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM domaines;"));