beautify alias list search parameters

AliasHandler:
- initStruct(): handle __mailbox_username as separate field (needed to
  make it searchable)
- split off a condition_ignore_mailboxes() function (used in getList()
  and getPagebrowser()) to add '__mailbox_username IS NULL' to the search
  condition array. Also, make sure $condition can be an array (preferred)
  or a string with a raw query

list-virtual.php:
- hand over a search array instead of a raw query


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1879 a1433add-5e2c-0410-b055-b7f2511e0802
pull/12/head
Christian Boltz 8 years ago
parent 16e1407621
commit 40b4fdf61c

@ -136,10 +136,9 @@ $table_alias = table_by_key('alias');
$table_mailbox = table_by_key('mailbox'); $table_mailbox = table_by_key('mailbox');
if (count($search) == 0 || !isset($search['_'])) { if (count($search) == 0 || !isset($search['_'])) {
$list_param = "domain='$fDomain'"; $search_alias = array('domain' => $fDomain);
} else { } else {
$searchterm = escape_string($search['_']); $search_alias = array('_' => $search['_']);
$list_param = "(address LIKE '%$searchterm%' OR goto LIKE '%$searchterm%')";
} }
$handler = new AliasHandler(0, $admin_username); $handler = new AliasHandler(0, $admin_username);
@ -153,8 +152,8 @@ $alias_data['struct']['goto_mailbox']['display_in_list'] = 0; # not useful/defin
$alias_data['struct']['on_vacation']['display_in_list'] = 0; $alias_data['struct']['on_vacation']['display_in_list'] = 0;
$alias_data['msg']['show_simple_search'] = False; # hide search box $alias_data['msg']['show_simple_search'] = False; # hide search box
$handler->getList($list_param, array(), $page_size, $fDisplay); $handler->getList($search_alias, array(), $page_size, $fDisplay);
$pagebrowser_alias = $handler->getPagebrowser($list_param, array()); $pagebrowser_alias = $handler->getPagebrowser($search_alias, array());
$tAlias = $handler->result(); $tAlias = $handler->result();

@ -42,7 +42,7 @@ class AliasHandler extends PFAHandler {
/*options*/ '', /*options*/ '',
/*not_in_db*/ 0, /*not_in_db*/ 0,
/*dont_write_to_db*/ 1, /*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__is_mailbox,0) as is_mailbox, __mailbox_username', /*select*/ 'coalesce(__is_mailbox,0) as is_mailbox',
# __mailbox_username is unused, but needed as workaround for a MariaDB bug # __mailbox_username is unused, but needed as workaround for a MariaDB bug
/*extrafrom*/ 'LEFT JOIN ( ' . /*extrafrom*/ 'LEFT JOIN ( ' .
' SELECT 1 as __is_mailbox, username as __mailbox_username ' . ' SELECT 1 as __is_mailbox, username as __mailbox_username ' .
@ -50,6 +50,7 @@ class AliasHandler extends PFAHandler {
' WHERE username IS NOT NULL ' . ' WHERE username IS NOT NULL ' .
' AND ' . db_in_clause($this->domain_field, $this->allowed_domains) . ' AND ' . db_in_clause($this->domain_field, $this->allowed_domains) .
' ) AS __mailbox ON __mailbox_username = address' ), ' ) AS __mailbox ON __mailbox_username = address' ),
'__mailbox_username' => pacol( 0, 0, 1, 'vtxt', '' , '' , 0), # filled via is_mailbox
'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0, 'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0,
/*options*/ '', /*options*/ '',
/*not_in_db*/ 1 ), # read_from_db_postprocess() sets the value /*not_in_db*/ 1 ), # read_from_db_postprocess() sets the value
@ -304,22 +305,28 @@ class AliasHandler extends PFAHandler {
return $db_result; return $db_result;
} }
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) { private function condition_ignore_mailboxes($condition, $searchmode) {
# only list aliases that do not belong to mailboxes # only list aliases that do not belong to mailboxes
# TODO: breaks if $condition is an array if (is_array($condition)) {
if ($condition != '') { $condition['__mailbox_username'] = 1;
$condition = " AND ( $condition ) "; $searchmode['__mailbox_username'] = 'NULL';
} else {
if ($condition != '') {
$condition = " ( $condition ) AND ";
}
$condition = " $condition __mailbox_username IS NULL ";
} }
return parent::getList( "__mailbox_username IS NULL $condition", $searchmode, $limit, $offset); return array($condition, $searchmode);
}
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) {
list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode);
return parent::getList($condition, $searchmode, $limit, $offset);
} }
public function getPagebrowser($condition, $searchmode = array()) { public function getPagebrowser($condition, $searchmode = array()) {
# only list aliases that do not belong to mailboxes list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode);
# TODO: breaks if $condition is an array return parent::getPagebrowser($condition, $searchmode);
if ($condition != '') {
$condition = " AND ( $condition ) ";
}
return parent::getPagebrowser( "__mailbox_username IS NULL $condition", $searchmode);
} }

Loading…
Cancel
Save