From fc7bc9529a12d3b85bb64b38a4f0c9029a963727 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 20 Jun 2007 22:45:35 +0000 Subject: [PATCH] Search enhancements git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@4 a1433add-5e2c-0410-b055-b7f2511e0802 --- VIRTUAL_VACATION/vacation.pl | 51 +++++++++++++++-------------- admin/search.php | 16 ++++++++-- search.php | 62 +++++++++++++++++++++++------------- templates/admin_search.tpl | 22 +++++++++++-- templates/search.tpl | 22 +++++++++++-- 5 files changed, 120 insertions(+), 53 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index f94545a0..f5496bdc 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -26,30 +26,33 @@ use DBI; use strict; use Sys::Syslog; -# values that will be set in /etc/mail/vacation/vacationrc: -our $db_type; -our $db_host; -our $db_user; -our $db_pass; -our $db_name; -our $sendmail; -our $logfile; -our $debugfile; -our $syslog; -our $logger; - -require "/etc/mail/vacation/vacationrc"; -# example config file: -# $db_type = 'mysql'; -# $db_host = 'localhost'; -# $db_user = 'postfixadmin'; -# $db_pass = 'postfixadmin'; -# $db_name = 'postfix'; -# $sendmail = "/usr/sbin/sendmail"; -# $logfile = ""; # specify a file name here for example: vacation.log -# $debugfile = ""; # sepcify a file name here for example: vacation.debug -# $syslog = 0; # 1 if log entries should be sent to syslog -# $logger = "/usr/bin/logger"; + +$db_type = 'mysql'; +$db_host = 'localhost'; +$db_user = 'postfixadmin'; +$db_pass = 'postfixadmin'; +$db_name = 'postfix'; +$sendmail = "/usr/sbin/sendmail"; +$logfile = ""; # specify a file name here for example: vacation.log +$debugfile = ""; # specify a file name here for example: vacation.debug +$syslog = 0; # 1 if log entries should be sent to syslog +$logger = "/usr/bin/logger"; + +# Alternatively, you can put the variables above in a +# config file that is readable by the vacation user. +# To do so, move them from here to there, declare them +# with 'our' here and include the file with 'require' +#our $db_type; +#our $db_host; +#our $db_user; +#our $db_pass; +#our $db_name; +#our $sendmail; +#our $logfile; +#our $debugfile; +#our $syslog; +#our $logger; +#require "/etc/mail/vacation/vacationrc"; my $dbh = DBI->connect("DBI:$db_type:$db_name:$db_host", "$db_user", "$db_pass", { RaiseError => 1 }) or &exit_error($DBI::errstr); diff --git a/admin/search.php b/admin/search.php index b6af64ae..28755b22 100644 --- a/admin/search.php +++ b/admin/search.php @@ -16,7 +16,9 @@ // // Form POST \ GET Variables: // -// fSearch +// search +// fDomain +// fGo // require ("../variables.inc.php"); require ("../config.inc.php"); @@ -28,6 +30,8 @@ $SESSID_USERNAME = check_session (); $tAlias = array(); $tMailbox = array(); +$list_domains = list_domains (); + if ($_SERVER['REQUEST_METHOD'] == "GET") { @@ -94,6 +98,14 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") 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'] == "YES") { @@ -126,7 +138,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") } } - $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username"; if ('pgsql'==$CONF['database_type']) { $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; diff --git a/search.php b/search.php index 067d8faf..4717e0c2 100644 --- a/search.php +++ b/search.php @@ -24,6 +24,15 @@ require ("./functions.inc.php"); include ("./languages/" . check_language () . ".lang"); $SESSID_USERNAME = check_session(); +if (!check_admin($SESSID_USERNAME)) +{ + $list_domains = list_domains_for_admin ($SESSID_USERNAME); +} +else +{ + $list_domains = list_domains (); +} + $tAlias = array(); $tMailbox = array(); @@ -48,7 +57,11 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { if (check_owner ($SESSID_USERNAME, $row['domain'])) { - $tAlias[] = $row; + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } + $tAlias[] = $row; } } } @@ -56,28 +69,25 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") if ($CONF['vacation_control_admin'] == '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%' ORDER BY $table_mailbox.username"); - if ('pgsql'==$CONF['database_type']) - { - // FIXME: postgres query needs to be rewrited - $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; - } } else { $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; - if ('pgsql'==$CONF['database_type']) - { - $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; - } } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { if (check_owner ($SESSID_USERNAME, $row['domain'])) { - $tMailbox[] = $row; + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } + $tMailbox[] = $row; } } } @@ -91,6 +101,14 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") 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['domain'])) $fdomain = escape_string ($_POST['domain']); + + if (empty ($fSearch) && !empty ($fgo)) + { + header("Location: overview.php?domain=" . $_POST['domain'] ) && exit; + } + if ($CONF['alias_control_admin'] == "YES") { @@ -108,6 +126,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { if (check_owner ($SESSID_USERNAME, $row['domain'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } @@ -115,20 +137,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") if ($CONF['vacation_control_admin'] == '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%' ORDER BY $table_mailbox.username"); - if ('pgsql'==$CONF['database_type']) - { - // FIXME: postgres query needs to be rewrited - $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; - } + $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%' ORDER BY username"; - if ('pgsql'==$CONF['database_type']) - { - $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; - } + $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username"; } $result = db_query ("$query"); @@ -138,6 +151,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { if (check_owner ($SESSID_USERNAME, $row['domain'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } $tMailbox[] = $row; } } diff --git a/templates/admin_search.tpl b/templates/admin_search.tpl index f2861d67..87185298 100644 --- a/templates/admin_search.tpl +++ b/templates/admin_search.tpl @@ -1,7 +1,23 @@
-

- + + + + +
+

+
+ New search: + +
@@ -71,7 +87,7 @@ if (sizeof ($tMailbox) > 0) print " " . $active . "\n"; if ($CONF['alias_control'] == 'YES') { - print " " . $PALANG['pOverview_alias_edit'] . "\n"; + print " " . $PALANG['pOverview_alias_edit'] . "\n"; } print " " . $PALANG['edit'] . "\n"; print " " . $PALANG['del'] . "\n"; diff --git a/templates/search.tpl b/templates/search.tpl index 1ed4bd26..c3503797 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -1,7 +1,25 @@
-

- + + + + + + +
+

+
+ New search: + +