diff --git a/edit-mailbox.php b/edit-mailbox.php index e3b586e0..0b58d04d 100644 --- a/edit-mailbox.php +++ b/edit-mailbox.php @@ -74,12 +74,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") $tActive = ('t'==$user_details['active']) ? 1 : 0; } - $result = db_query ("SELECT * FROM $table_domain WHERE domain='$fDomain'"); - if ($result['rows'] == 1) - { - $row = db_array ($result['result']); - $tMaxquota = $row['maxquota']; - } + $tMaxquota = allowed_quota($fDomain, $user_details['quota']); } } @@ -121,6 +116,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $tName = $fName; $tQuota = $fQuota; $tActive = $fActive; + $tMaxquota = allowed_quota($fDomain, $user_details['quota']); + $pEdit_mailbox_quota_text_error = $PALANG['pEdit_mailbox_quota_text_error']; } } diff --git a/functions.inc.php b/functions.inc.php index c31eaa8f..090f68f0 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -704,6 +704,30 @@ function check_quota ($quota, $domain, $username="") { } +/** + * Get allowed maximum quota for a mailbox + * @param String $domain + * @param Integer $current_user_quota (in bytes) + * @return Integer allowed maximum quota (in MB) + */ +function allowed_quota($domain, $current_user_quota) { + $domain_properties = get_domain_properties($domain); + + $tMaxquota = $domain_properties['maxquota']; + + if (boolconf('domain_quota') && $domain_properties['quota']) { + $dquota = $domain_properties['quota'] - divide_quota($domain_properties['quota_sum'] - $current_user_quota); + if ($dquota < $tMaxquota) { + $tMaxquota = $dquota; + } + + if ($tMaxquota == 0) { + $tMaxquota = $dquota; + } + } + return $tMaxquota; +} + // // multiply_quota @@ -1218,7 +1242,7 @@ function pacrypt ($pw, $pw_db="") { die ('unknown/invalid $CONF["encrypt"] setting: ' . $CONF['encrypt']); } - $password = escape_string ($password); + $password = escape_string ($password); # TODO: disable escaping - https://sourceforge.net/tracker/?func=detail&aid=3301752&group_id=191583&atid=937964 return $password; }