0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-20 03:36:20 +02:00

list-domain.php:

- use DomainHander->getList()
  - line count: 126 -> 85 = 41 less :-)
- preselect correct username in admin dropdown



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1231 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
Christian Boltz 2011-10-22 22:54:48 +00:00
parent 7f9d947e8f
commit 3a419a3246

View File

@ -32,7 +32,7 @@ if (authentication_has_role('global-admin')) {
//if (authentication_has_role('admin')) {
$list_admins = list_admins ();
$is_superadmin = 1;
$fUsername = escape_string(safepost('fUsername', safeget('username'))); # prefer POST over GET variable
$fUsername = escape_string(safepost('fUsername', safeget('username', authentication_get_username()))); # prefer POST over GET variable
if ($fUsername != "") $admin_properties = get_admin_properties($fUsername);
} else {
$list_admins = array(authentication_get_username());
@ -51,62 +51,21 @@ if (isset($admin_properties) && $admin_properties['domain_count'] == 'ALL') { #
$list_domains = list_domains_for_admin(authentication_get_username());
}
$table_domain = table_by_key('domain');
$table_mailbox = table_by_key('mailbox');
$table_alias = table_by_key('alias');
if ($list_all_domains == 1) {
$where = " WHERE $table_domain.domain != 'ALL' "; # TODO: the ALL dummy domain is annoying...
$where = " domain != 'ALL' "; # TODO: the ALL dummy domain is annoying...
} else {
$list_domains = escape_string($list_domains);
$where = " WHERE $table_domain.domain IN ('" . join("','", $list_domains) . "') ";
$where = db_in_clause('domain', $list_domains);
}
# fetch domain data and number of mailboxes
# PgSQL requires the extensive GROUP BY statement (https://sourceforge.net/forum/message.php?msg_id=7386240)
# and also in the field list (https://sourceforge.net/tracker/?func=detail&aid=2859165&group_id=191583&atid=937964)
# Note: future versions should auto-generate the field list based on $struct in DomainHandler (use all fields from the domain table)
$table_domain_fieldlist = "
$table_domain.domain, $table_domain.description, $table_domain.aliases, $table_domain.mailboxes,
$table_domain.maxquota, $table_domain.quota, $table_domain.transport, $table_domain.backupmx, $table_domain.created,
$table_domain.modified, $table_domain.active
";
$query = "
SELECT $table_domain_fieldlist , COUNT( DISTINCT $table_mailbox.username ) AS mailbox_count, SUM( $table_mailbox.quota ) AS total_quota
FROM $table_domain
LEFT JOIN $table_mailbox ON $table_domain.domain = $table_mailbox.domain
$where
GROUP BY $table_domain_fieldlist
ORDER BY $table_domain.domain
";
$result = db_query($query);
$domain_properties = array();
while ($row = db_array ($result['result'])) {
$domain_properties[$row['domain']] = $row;
$handler = new DomainHandler();
if ($handler->getList($where)) {
$domain_properties = $handler->result();
} else {
$domain_properties = array();
# TODO: check if there was an error or simply no domains
}
# fetch number of aliases
# doing this separate is much faster than doing it in one "big" query
$query = "
SELECT $table_domain.domain, COUNT( DISTINCT $table_alias.address ) AS alias_count
FROM $table_domain
LEFT JOIN $table_alias ON $table_domain.domain = $table_alias.domain
$where
GROUP BY $table_domain.domain
ORDER BY $table_domain.domain
";
$result = db_query($query);
while ($row = db_array ($result['result'])) {
# add number of aliases to $domain_properties array. mailbox aliases do not count.
$domain_properties [$row['domain']] ['alias_count'] = $row['alias_count'] - $domain_properties [$row['domain']] ['mailbox_count'];
$domain_properties [$row['domain']] ['total_quota'] = (int) divide_quota($domain_properties [$row['domain']] ['total_quota']); # convert to MB
if ($domain_properties [$row['domain']] ['quota'] == -1) $domain_properties [$row['domain']] ['quota'] = $PALANG['pOverview_unlimited'];
if ($domain_properties [$row['domain']] ['maxquota'] == -1) $domain_properties [$row['domain']] ['maxquota'] = $PALANG['pOverview_unlimited'];
}
$smarty->assign ('domain_properties', $domain_properties);
if ($is_superadmin)