From 8479d79bde17003e67d660244c83952fa6bb3d98 Mon Sep 17 00:00:00 2001 From: quenenni Date: Wed, 16 Aug 2017 19:46:53 +0200 Subject: [PATCH] =?UTF-8?q?classe=20quota=20&=20fichiers=20section=20admin?= =?UTF-8?q?=20associ=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bureau/admin/quota_show.php | 6 +-- bureau/admin/quotas_oneuser.php | 65 ++++++++++++++++++++++++--------- bureau/admin/quotas_users.php | 11 +++--- bureau/class/m_quota.php | 48 ++++++++++++------------ 4 files changed, 79 insertions(+), 51 deletions(-) diff --git a/bureau/admin/quota_show.php b/bureau/admin/quota_show.php index d58b55bc..0d1be01e 100644 --- a/bureau/admin/quota_show.php +++ b/bureau/admin/quota_show.php @@ -37,9 +37,9 @@ include_once("head.php"); getquota(); if (!is_array($q) || empty($q) ) { - echo "

"._("No quotas for this account, or quotas currently unavailable!")."

"; - include_once("foot.php"); - die(); + $msg->raise('Alert', "quota", _("No quotas for this account, or quotas currently unavailable!")); + include_once("main.php"); + exit(); } echo ""; diff --git a/bureau/admin/quotas_oneuser.php b/bureau/admin/quotas_oneuser.php index 90876120..9e5f7de3 100644 --- a/bureau/admin/quotas_oneuser.php +++ b/bureau/admin/quotas_oneuser.php @@ -8,10 +8,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set $mode = 0; } // $mode = 4; // Pour Debuguer le mode "graphique" des quotas + +// Si la var $usr existe, c'est qu'on appelle les quotas pour 1 user à partir des quotas généraux de l'admin +// Sinon, on récupère l'id du user à récupérer via $mem->user["login"] +if (isset($usr) && is_int($usr)) { + $id_usr=$usr; + $login=$admin->get_login_by_uid($id_usr); +} else { + $id_usr = $mem->user["uid"]; + $login = $mem->user["login"]; +} ?>
-

%s account"),$mem->user["login"]); ?>

+

%s account"),$login); ?>

@@ -30,6 +40,8 @@ if (!isset($mode)) { # when included from adm_login, mode is not set +

+
@@ -41,7 +53,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set enum_domains($mem->user["uid"]); + $domaines_user = $dom->enum_domains($id_usr); $totalmail=0; foreach ($domaines_user as $domaine) { $mstmp = $quota->get_size_mail_sum_domain($domaine); @@ -84,10 +96,10 @@ if (!isset($mode)) { # when included from adm_login, mode is not set $tpc = 0; } if (count($alias_sizes) > 0) { - echo ""; + echo ""; echo ""; + echo ">"; if ($mode==0) { echo sprintf("%.1f", $d['size'])." ".$d['unit']; } elseif ($mode==1) { @@ -95,7 +107,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set } else { $quota->quota_displaybar($tpc); } - echo ""; + echo ""; } } ?> @@ -106,12 +118,12 @@ if (!isset($mode)) { # when included from adm_login, mode is not set get_size_db_sum_user($mem->user["login"]); + $totaldb = $quota->get_size_db_sum_user($login); $t = $quota->get_size_unit($totaldb); - echo "

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

"; + + echo "

"._("Databases:")." "; + echo "

"; ?>
". _('Total'). " {$domaine}
". _('Total'). " {$domaine}
@@ -124,7 +136,7 @@ if (!isset($mode)) { # when included from adm_login, mode is not set get_size_db_details_user($mem->user["login"]); + $db_sizes = $quota->get_size_db_details_user($login); foreach ($db_sizes as $d) { echo "quota_displaybar(2*$pc, 0); + $quota->quota_displaybar($pc, 0); } echo ""; } + + if (count($db_sizes) > 0 && $mode==0) { + echo ""; + echo ""; + } ?>
".$d["db"]."
". _('Total'). " " . _("Databases:").""; + echo sprintf("%.1f", $t['size'])." ".$t['unit']; + echo "
@@ -151,16 +170,16 @@ if (!isset($mode)) { # when included from adm_login, mode is not set get_size_mailman_sum_user($mem->user["uid"]); + $totallist = $quota->get_size_mailman_sum_user($id_usr); if ($totallist) { // $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 "

"; + + echo "

"._("Mailman lists:")." "; + echo "

"; ?> - +
@@ -170,14 +189,14 @@ if (!isset($mode)) { # when included from adm_login, mode is not set get_size_mailman_details_user($mem->user["uid"]); + $mailman_size = $quota->get_size_mailman_details_user($id_usr); foreach ($mailman_size as $d) { echo ""; $ds = $quota->get_size_unit($d["size"] * 1024); if ($totallist) { - $pc=intval(100*$ds['size']/$totallist); + $pc=intval(100*$d['size']/$totallist); } else { $pc=0; } @@ -190,10 +209,20 @@ if (!isset($mode)) { # when included from adm_login, mode is not set } echo ""; } + + if (count($db_sizes) > 0 && $mode==0) { + echo ""; + echo ""; + echo sprintf("%.1f", $t['size'])." ".$t['unit']; + echo ""; + } ?>
".$d["list"]."
". _('Total'). " " . _("Mailman lists:")."
+

 

diff --git a/bureau/admin/quotas_users.php b/bureau/admin/quotas_users.php index f46b36d0..1a6764e9 100644 --- a/bureau/admin/quotas_users.php +++ b/bureau/admin/quotas_users.php @@ -11,7 +11,8 @@ $fields = array ( getFields($fields); if (!$admin->enabled) { - __("This page is restricted to authorized staff"); + $msg->raise('Error', "admin", _("This page is restricted to authorized staff")); + echo $msg->msg_html_all(); exit(); } @@ -22,9 +23,7 @@ include_once ("head.php");

$error

"; -} +echo $msg->msg_html_all(); ?>

enum_domains($c["uid"]); @@ -350,7 +349,7 @@ foreach ($all as $c) { $mls=$c["mailmansize"]; $mailsize=$quota->get_size_unit($ms); - $mailmansize=$quota->get_size_unit($mls); + $mailmansize=$quota->get_size_unit($mls * 1024); // Espace WEB $ws = $c["websize"]; diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index ac0e44e1..e229a46a 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -137,8 +137,8 @@ class m_quota { * the defaults value. */ function synchronise_user_profile() { - global $db, $err; - $err->log("quota", "synchronise_user_profile"); + global $db, $msg; + $msg->log("quota", "synchronise_user_profile"); $q = "insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);"; if (!$db->query($q)) { return false; @@ -153,8 +153,8 @@ class m_quota { */ function create_missing_quota_profile() { - global $db, $quota, $err; - $err->log("quota", "create_missing_quota_profile"); + global $db, $quota, $msg; + $msg->log("quota", "create_missing_quota_profile"); $qt = $quota->getquota('', true); $type = $quota->listtype(); foreach ($type as $t) { @@ -172,8 +172,8 @@ class m_quota { * @Return array the quota used and total for this ressource (or for all ressource if unspecified) */ function getquota($ressource = "", $recheck = false) { - global $db, $err, $cuid, $get_quota_cache, $hooks, $mem; - $err->log("quota", "getquota", $ressource); + global $db, $msg, $cuid, $get_quota_cache, $hooks, $mem; + $msg->log("quota", "getquota", $ressource); if ($recheck) { // rebuilding quota $get_quota_cache = null; $this->quotas = array(); @@ -240,8 +240,8 @@ class m_quota { * @param integer size of the quota (available or used) */ function setquota($ressource, $size) { - global $err, $db, $cuid; - $err->log("quota", "setquota", $ressource . "/" . $size); + global $msg, $db, $cuid; + $msg->log("quota", "setquota", $ressource . "/" . $size); if (floatval($size) == 0) { $size = "0"; } @@ -252,7 +252,7 @@ class m_quota { $a = array(); exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a); if (!isset($a[1]) || $size != $a[1]) { - $err->raise("quota", _("Error writing the quota entry!")); + $msg->raise('Error', "quota", _("Error writing the quota entry!")); return false; } } @@ -272,8 +272,8 @@ class m_quota { * Erase all quota information about the user. */ function delquotas() { - global $db, $err, $cuid; - $err->log("quota", "delquota"); + global $db, $msg, $cuid; + $msg->log("quota", "delquota"); $db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid)); return true; } @@ -327,14 +327,14 @@ class m_quota { * @return boolean true if all went ok */ function addtype($type) { - global $db, $err; + global $db, $msg; $qlist = $this->qlist(); 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"); + $msg->raise('Error', "quota", _("Type can only contains characters a-z and 0-9")); // à traduire return false; } while (list($key, $val) = each($qlist)) { @@ -383,8 +383,8 @@ class m_quota { * The user we are talking about is in the global $cuid. */ function addquotas() { - global $db, $err, $cuid; - $err->log("quota", "addquota"); + global $db, $msg, $cuid; + $msg->log("quota", "addquota"); $ql = $this->qlist(); reset($ql); @@ -478,7 +478,7 @@ class m_quota { /* 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 WHERE delivery = 'dovecot';;"); + return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_quota ;"); } /* sum of mailbox sizes for one domain */ @@ -491,19 +491,19 @@ class m_quota { /* count of mailbox sizes from all domains */ function get_size_mail_count_all() { - return $this->_get_count_sql("SELECT COUNT(*) AS count FROM mailbox WHERE delivery = 'dovecot';"); + return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota;"); } /* count of mailbox for one domain */ function get_size_mail_count_domain($dom) { - return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'"); + return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota WHERE user 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 user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;"); + return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_quota WHERE user LIKE '%@{$dom}' ORDER BY alias;"); } /* sum of mailman lists sizes from all domains */ @@ -515,7 +515,7 @@ class m_quota { /* sum of mailman lists sizes for one domain */ function get_size_mailman_sum_domain($dom) { - return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'"); + return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman s INNER JOIN mailman m ON s.list = m.list AND s.uid = m.uid WHERE m.domain = '$dom'"); } /* sum of mailman lists for one user */ @@ -624,8 +624,8 @@ class m_quota { * globals $cuid is the appropriate user */ function hook_admin_add_member() { - global $err; - $err->log("quota", "hook_admin_add_member"); + global $msg; + $msg->log("quota", "hook_admin_add_member"); $this->addquotas(); $this->getquota('', true); // actualise quota } @@ -637,8 +637,8 @@ class m_quota { * EXPERIMENTAL function ;) */ function alternc_export_conf() { - global $err; - $err->log("quota", "export"); + global $msg; + $msg->log("quota", "export"); $str = " "; $q = $this->getquota();