Another step in code cleanup: replaced search.php with search mode in

list-virtual.php. We now have two file less to maintain without loosing
functionality :-)

Only remaining bug: in search mode, no page browser is displayed.
This means that you'll only see the first $CONF['page_size'] search results
*without* the possibility to see the next page of results.
(BTW: search.php simply ignored $CONF['page_size'] ;-)


search.php, templates/search.tpl:
- deleted, RIP ;-)

configs/menu.conf:
- change search form to use list-virtual.php instead of search.php

list-virtual.php:
- added TODO note about the "no page browser in search mode" bug

templates/list-virtual.tpl:
- hand over $search to all tabs



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@869 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 14 years ago
parent 4c912f1da8
commit a46d0c5278

@ -38,8 +38,8 @@ tr_header = <tr class="header">
tr_hilightoff = <tr class="hilightoff" onmouseover="className='hilighton';" onmouseout="className='hilightoff';">
url_delete = delete.php
url_search = search.php
form_search = <form name="search" method="post" action="search.php"><input name="search" size="10" /></form>
url_search = list-virtual.php
form_search = <form name="search" method="post" action="list-virtual.php"><input name="search" size="10" /></form>
[main]
_txt_list_domain = pMenu_overview

@ -279,6 +279,16 @@ $tCanAddAlias = false;
$tCanAddMailbox = false;
# TODO: needs reworking for $search...
# TODO: (= bug: no page browser displayed in search mode!) - https://sourceforge.net/tracker/?func=detail&aid=2782818&group_id=191583&atid=937964
# for non-search mode, get_domain_properties counts the aliases and mailboxes
# Options:
# a)
# if ($search == "") -> get_domain_properties
# else -> "manual count"
# b)
# "manual count" for all cases (not really more work, queries are similar)
#
# Note: get_domain_properties also creates the page browser (which needs performance tuning anyway...)
$limit = get_domain_properties($fDomain);
if (isset ($limit)) {
if ($fDisplay >= $page_size) {

@ -1,188 +0,0 @@
<?php
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE.TXT.
*
* Further details on the project are available at :
* http://www.postfixadmin.com or http://postfixadmin.sf.net
*
* @version $Id$
* @license GNU GPL v2 or later.
*
* File: search.php
* Provides a method for searching for a user/mailbox
* Template File: search.tpl
*
* Template Variables:
*
* tAlias
* tMailbox
*
* Form POST \ GET Variables:
*
* fSearch
* fGo
* fDomain
*/
require_once('common.php');
authentication_require_role('admin');
$SESSID_USERNAME = authentication_get_username();
if(authentication_has_role('global-admin')) {
$list_domains = list_domains ();
}
else {
$list_domains = list_domains_for_admin ($SESSID_USERNAME);
}
$tAlias = array();
$tMailbox = array();
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
if (isset ($_GET['search'])) $fSearch = escape_string ($_GET['search']);
if (isset ($_GET['fGo'])) $fGo = escape_string ($_GET['fGo']);
if (isset ($_GET['fDomain'])) $fDomain = escape_string ($_GET['domain']);
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if (isset ($_POST['search'])) $fSearch = escape_string ($_POST['search']);
if (isset ($_POST['fGo'])) $fGo = escape_string ($_POST['fGo']);
if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
}
if (empty ($fSearch) /* && !empty ($fGo) */)
{
header("Location: list-virtual.php?domain=" . $fDomain ) && exit;
}
if ($CONF['alias_control_admin'] == "YES")
{
$query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
$table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active
FROM $table_alias
WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address";
}
else
{
// find all aliases which don't have a matching entry in table_mailbox
$query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
$table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active
FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username
WHERE address LIKE '%$fSearch%' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address";
}
$result = db_query ($query);
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
{
if ('pgsql'==$CONF['database_type'])
{
$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tAlias[] = $row;
}
}
}
if ($CONF['vacation_control_admin'] == 'YES' && $CONF['vacation'] == 'YES')
{
$query = ("SELECT $table_mailbox.*, $table_vacation.active AS v_active FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email WHERE $table_mailbox.username LIKE '%$fSearch%' OR $table_mailbox.name LIKE '%$fSearch%' ORDER BY $table_mailbox.username");
}
else
{
$query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username";
}
$result = db_query ($query);
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
{
if ('pgsql'==$CONF['database_type'])
{
$row['created']=gmstrftime('%c %Z',strtotime($row['created']));
$row['modified']=gmstrftime('%c %Z',strtotime($row['modified']));
$row['active']=('t'==$row['active']) ? 1 : 0;
}
$tMailbox[] = $row;
}
}
}
$check_alias_owner = array ();
if ((is_array ($tAlias) and sizeof ($tAlias) > 0))
for ($i = 0; $i < sizeof ($tAlias); $i++)
$check_alias_owner [$i] = check_alias_owner ($SESSID_USERNAME, $tAlias[$i]['address']);
$divide_quota = array ();
if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
for ($i = 0; $i < sizeof ($tMailbox); $i++)
{
$divide_quota ['quota'][$i] = divide_quota ($tMailbox[$i]['quota']);
}
for ($i = 0; $i < sizeof ($tAlias); $i++)
{
if ((is_array ($tAlias) and sizeof ($tAlias) > 0))
{
$tAlias[$i]['display_address'] = $tAlias[$i]['address'];
if (stristr($tAlias[$i]['display_address'],$fSearch))
{
$new_address = str_ireplace($fSearch, "<span style='background-color: lightgreen'>".$fSearch."</span>", $tAlias[$i]['display_address']);
$tAlias[$i]['display_address'] = $new_address;
}
if (stristr($tAlias[$i]['goto'], $fSearch))
{
$tAlias[$i]['goto'] = str_ireplace($fSearch, "<span style='background-color: lightgreen'>".$fSearch."</span>", $tAlias[$i]['goto']);
}
($tAlias [$i]['active'] == 1) ? $tAlias [$i]['active'] = $PALANG ['YES'] : $tAlias [$i]['active'] = $PALANG ['NO'];
}
}
for ($i = 0; $i < sizeof ($tMailbox); $i++)
{
if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
{
$tMailbox[$i]['display_username'] = $tMailbox[$i]['username'];
if (stristr($tMailbox[$i]['display_username'],$fSearch))
{
$new_name = str_ireplace ($fSearch, "<span style='background-color: lightgreen'>".$fSearch."</span>", $tMailbox[$i]['display_username']);
$tMailbox [$i]['display_username'] = $new_name;
}
if (stristr($tMailbox[$i]['name'],$fSearch))
{
$tMailbox[$i]['name'] = str_ireplace($fSearch, "<span style='background-color: lightgreen'>".$fSearch."</span>", $tMailbox[$i]['name']);
}
($tMailbox [$i]['active'] == 1) ? $tMailbox [$i]['active'] = $PALANG ['YES'] : $tMailbox [$i]['active'] = $PALANG ['NO'];
($tMailbox [$i]['v_active'] == 1) ? $tMailbox [$i]['v_active'] = $PALANG ['pOverview_vacation_edit'] : $tMailbox [$i]['v_active'] = '';
}
}
$smarty->assign ('fSearch', $fSearch);
$smarty->assign ('select_options', select_options ($list_domains, array ($list_domains[0])), false);
$smarty->assign ('tAlias', $tAlias, false);
$smarty->assign ('check_alias_owner', $check_alias_owner);
$smarty->assign ('tMailbox', $tMailbox, false);
$smarty->assign ('divide_quota', $divide_quota);
$smarty->assign ('smarty_template', 'search');
$smarty->display ('index.tpl');
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
?>

@ -14,10 +14,10 @@
</div>
<div id="tabbar">
<ul>
<li><a href="?domain={$smarty.get.domain}&tab=mailbox">{$PALANG.pOverview_mailbox_title}</a></li>
<li><a href="?domain={$smarty.get.domain}&tab=alias">{$PALANG.pOverview_alias_title}</a></li>
<li><a href="?domain={$smarty.get.domain}&tab=mailbox{if $search != ""}&search={$search}{/if}">{$PALANG.pOverview_mailbox_title}</a></li>
<li><a href="?domain={$smarty.get.domain}&tab=alias{if $search != ""}&search={$search}{/if}">{$PALANG.pOverview_alias_title}</a></li>
{if $boolconf_alias_domain}
<li><a href="?domain={$smarty.get.domain}&tab=alias_domain">{$PALANG.pOverview_alias_domain_title}</a></li>
<li><a href="?domain={$smarty.get.domain}&tab=alias_domain{if $search != ""}&search={$search}{/if}">{$PALANG.pOverview_alias_domain_title}</a></li>
{/if}
</ul>
</div>

@ -1,96 +0,0 @@
<div id="overview">
<form name="search" method="post" action="{#url_search#}">
<table width="750">
<tr>
<td>
<h4>{$PALANG.pSearch_welcome}{$fSearch}</h4>
</td>
<td>{$PALANG.pSearch}:<input name="search" /></td>
{if $authentication_has_role.global_admin}
<td></td>
{/if}
<td align="right">
<select class="flat" name="fDomain" >{$select_options}</select>
{if $authentication_has_role.global_admin}
<input class="button" type="submit" name="fGo" value="{$PALANG.pReturn_to} {$PALANG.pAdminMenu_list_virtual}" /></td>
{else}
<input class="button" type="submit" name="fGo" value="{$PALANG.pReturn_to} {$PALANG.pMenu_overview}" /></td>
{/if}
</tr>
</table>
</form>
</div>
{if $tAlias}
<table id="alias_table">
<tr>
<td colspan="5"><h3>{$PALANG.pOverview_alias_title}</h3></td>
</tr>
{#tr_header#}
<td>{$PALANG.pOverview_alias_address}</td>
<td>{$PALANG.pOverview_alias_goto}</td>
<td>{$PALANG.pOverview_alias_modified}</td>
<td>{$PALANG.pOverview_alias_active}</td>
<td colspan="2">&nbsp;</td>
</tr>
{foreach from=$tAlias item=item key=i}
{#tr_hilightoff#}
<td>{$item.display_address}</td>
<td>{$item.goto}</td>
<td>{$item.modified}</td>
{if $CONF.special_alias_control===YES || $authentication_has_role.global_admin}
<td><a href="edit-active.php?alias={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}&amp;return=search.php?search={$fSearch|escape:"url"}">{$item.active}</a></td>
<td><a href="edit-alias.php?address={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}">{$PALANG.edit}</a></td>
<td><a href="delete.php?table=alias&amp;delete={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}" onclick="return confirm ('{$PALANG.confirm}{$PALANG.pOverview_get_aliases|escape:"url"}: {$item.address|escape:"url"}');">{$PALANG.del}</a></td>
{else}
{if $check_alias_owner[$i]}
<td><a href="edit-active.php?alias={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}&amp;return=search.php?search={$fSearch|escape:"url"}">{$item.active}</a></td>
<td><a href="edit-alias.php?address={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}">{$PALANG.edit}</a></td>
<td><a href="delete.php?table=alias&amp;delete={$item.address|escape:"url"}&amp;domain={$item.domain|escape:"url"}" onclick="return confirm ('{$PALANG.confirm}{$PALANG.pOverview_get_aliases}: {$item.address}');">{$PALANG.del}</a></td>
{else}
<td>&nbsp;</td>
<td>&nbsp;</td>
{/if}
{/if}
</tr>
{/foreach}
</table>
{/if}
{if $tMailbox}
<table id="mailbox_table">
<tr>
<td colspan="7"><h3>{$PALANG.pOverview_mailbox_title}</h3></td>
</tr>
<tr class="header">
<td>{$PALANG.pOverview_mailbox_username}</td>
<td>{$PALANG.pOverview_mailbox_name}</td>
{if $CONF.quota===YES}<td>{$PALANG.pOverview_mailbox_quota}</td>{/if}
<td>{$PALANG.pOverview_mailbox_modified}</td>
<td>{$PALANG.pOverview_mailbox_active}</td>
<td colspan="2">&nbsp;</td>
{assign var="colspan" value=2}
{if $CONF.vacation_control_admin===YES}{assign var="colspan" value=$colspan+1}{/if}
{if $CONF.alias_control_admin===YES}{assign var="colspan" value=$colspan+1}{/if}
{if $authentication_has_role.global_admin && $CONF.alias_control===YES}{assign var="colspan" value=3}{/if}
<td colspan="{$colspan}">&nbsp;</td>
</tr>
{foreach from=$tMailbox item=item key=i}
{#tr_hilightoff#}
<td>{$item.display_username}</td>
<td>{$item.name}</td>
{if $CONF.quota===YES}
<td>{$divide_quota.quota[$i]}</td>
{/if}
<td>{$item.modified}</td>
<td><a href="edit-active.php?username={$item.username|escape:"url"}&amp;domain={$item.domain}&amp;return=search.php?search={$fSearch|escape:"url"}">{$item.active}</a></td>
{if $CONF.vacation_control_admin===YES}
<td><a href="edit-vacation.php?username={$item.username|escape:"url"}&amp;domain={$item.domain}">{$item.v_active}</a></td>
{/if}
{if $CONF.alias_control===YES || $CONF.alias_control_admin===YES}
<td><a href="edit-alias.php?address={$item.username|escape:"url"}&amp;domain={$item.domain}">{$PALANG.pOverview_alias_edit}</a></td>
{/if}
<td><a href="edit-mailbox.php?username={$item.username|escape:"url"}&amp;domain={$item.domain}">{$PALANG.edit}</a></td>
<td><a href="delete.php?table=mailbox&amp;delete={$item.username|escape:"url"}&amp;domain={$item.domain}" onclick="return confirm ('{$PALANG.confirm}{$PALANG.pOverview_get_mailboxes}: {$item.username}');">{$PALANG.del}</a></td>
</tr>
{/foreach}
</table>
{/if}
Loading…
Cancel
Save