model/DomainHandler.php:

- set $domain_field to enable domain permission handling

list-domain.php:
- use permission handling of DomainHandler. This means:
  - no need to call list_domains_for_admin() 
  - no longer hand over SQL sniplets
  - much easier handling for superadmins and "simulate admin" mode
  - 14 lines less code for permission handling etc.
- remove superfluous/outdated header comments
- move $smarty_assign('select_options') to global section (it's the
  same code for domain admins and superadmins)

Note: don't try to read the diff of list-domain.php.
Read the complete file instead ;-)



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1267 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 13 years ago
parent 68c79b9013
commit a0e59f82b9

@ -13,53 +13,31 @@
*
* File: list-domain.php
* List all domains as a quick overview.
* Template File: adminlistdomain.tpl
*
* Template Variables:
*
* -none-
*
* Form POST \ GET Variables:
*
* fUsername
*/
require_once('common.php');
authentication_require_role('admin');
if (authentication_has_role('global-admin')) {
//if (authentication_has_role('admin')) {
# default: domain admin restrictions
$admin_username = authentication_get_username();
$list_admins = array(authentication_get_username());
$is_superadmin = 0;
$fUsername = "";
if (authentication_has_role('global-admin')) { # more permissions? Fine!
$list_admins = list_admins ();
$is_superadmin = 1;
$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());
$is_superadmin = 0;
$fUsername = "";
}
$list_all_domains = 0;
if (isset($admin_properties) && $admin_properties['domain_count'] == 'ALL') { # list all domains for superadmins
$list_all_domains = 1;
} elseif (!empty($fUsername)) {
$list_domains = list_domains_for_admin ($fUsername);
} elseif ($is_superadmin) {
$list_all_domains = 1;
} else {
$list_domains = list_domains_for_admin(authentication_get_username());
}
if ($list_all_domains == 1) {
$where = " domain != 'ALL' "; # TODO: the ALL dummy domain is annoying...
} else {
$list_domains = escape_string($list_domains);
$where = db_in_clause('domain', $list_domains);
$fUsername = safepost('fUsername', safeget('username', authentication_get_username())); # prefer POST over GET variable
if ($fUsername != "") {
$admin_username = $fUsername;
}
}
$handler = new DomainHandler();
if ($handler->getList($where)) {
$handler = new DomainHandler(0, $admin_username);
if ($handler->getList()) {
$domain_properties = $handler->result();
} else {
$domain_properties = array();
@ -68,14 +46,10 @@ if ($handler->getList($where)) {
$smarty->assign ('domain_properties', $domain_properties);
if ($is_superadmin)
{
$smarty->assign('select_options', select_options($list_admins, array ($fUsername)), false);
$smarty->assign ('select_options', select_options($list_admins, array ($fUsername)), false);
if ($is_superadmin) {
$smarty->assign('smarty_template', 'adminlistdomain');
}
else
{
$smarty->assign ('select_options', select_options($list_admins, array ($fUsername)), false);
} else {
$smarty->assign ('smarty_template', 'overview-get');
}

@ -6,6 +6,8 @@
*/
class DomainHandler extends PFAHandler {
protected $domain_field = 'domain';
protected function validate_new_id() {
$valid = check_domain($this->id);

Loading…
Cancel
Save