From 6027422c1be95eef28776a2697917fddffdb094e Mon Sep 17 00:00:00 2001
From: tokul
Date: Mon, 20 Jun 2005 16:04:41 +0000
Subject: [PATCH] 529563 fixes and some cleanup: * require_once converted to
include_once and moved to the top part of script. * internal script functions
are placed after includes * instead of testing form vars with isset, we check
sqgetGlobalVar(). * list all request uses list_addr() function instead of
wide (*) search. * listall variable is tested with isset() instead of
empty().
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9639 7612ce4b-ef26-0410-bec9-ea0150e637f0
---
src/addrbook_search.php | 122 +++++++++++++++++++++-------------------
1 file changed, 63 insertions(+), 59 deletions(-)
diff --git a/src/addrbook_search.php b/src/addrbook_search.php
index 3445d3dd..d3c99c35 100644
--- a/src/addrbook_search.php
+++ b/src/addrbook_search.php
@@ -25,21 +25,11 @@ define('SM_PATH','../');
/** SquirrelMail required files. */
require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'functions/forms.php');
-
-/** lets get the global vars we may need */
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
-sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
-
-sqgetGlobalVar('show' , $show);
-sqgetGlobalVar('query', $query, SQ_POST);
-sqgetGlobalVar('listall', $listall, SQ_POST);
-sqgetGlobalVar('backend', $backend, SQ_POST);
+include_once(SM_PATH . 'functions/strings.php');
+include_once(SM_PATH . 'functions/global.php');
+include_once(SM_PATH . 'functions/html.php');
+include_once(SM_PATH . 'functions/forms.php');
+include_once(SM_PATH . 'functions/addressbook.php');
/**
* Function to include JavaScript code
@@ -170,8 +160,24 @@ function display_result($res, $includesource = true) {
/* ================= End of functions ================= */
-require_once('../functions/strings.php');
-require_once('../functions/addressbook.php');
+/** lets get the global vars we may need */
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
+sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
+
+if (! sqgetGlobalVar('show' , $show)) {
+ $show = '';
+}
+if (! sqgetGlobalVar('query', $query, SQ_POST)) {
+ $query = '';
+}
+if (! sqgetGlobalVar('listall', $listall, SQ_POST)) {
+ unset($listall);
+}
+if (! sqgetGlobalVar('backend', $backend, SQ_POST)) {
+ $backend = '';
+}
displayHtmlHeader();
@@ -179,11 +185,6 @@ displayHtmlHeader();
global $default_charset;
set_my_charset();
-/* Initialize vars */
-if (!isset($query)) { $query = ''; }
-if (!isset($show)) { $show = ''; }
-if (!isset($backend)) { $backend = ''; }
-
/* Choose correct colors for top and bottom frame */
if ($show == 'form' && !isset($listall)) {
echo '' .
_("No persons matching your search were found"),
'center' ) .
@@ -209,8 +210,8 @@ if (empty($query) && empty($show) && empty($listall)) {
$showerr=($show=='form' ? false : true);
$abook = addressbook_init($showerr);
-/* Create search form */
-if ($show == 'form' && empty($listall)) {
+/* Create search form (top frame) */
+if ($show == 'form' && ! isset($listall)) {
echo '
' . "\n";
} else {
-
- /* Show personal addressbook */
- if ($show == 'blank' && empty($listall)) {
+ /**
+ * List addresses (bottom frame)
+ * If listall is set, list all entries in selected backend.
+ * If $show is 'blank' (initial call of address book popup) - list
+ * personal address book.
+ */
+ if ($show == 'blank' || isset($listall)) {
if($backend != -1 || $show == 'blank') {
if ($show == 'blank') {
@@ -262,9 +267,9 @@ if ($show == 'form' && empty($listall)) {
display_result($res, false);
} else {
echo html_tag( 'p', '' .
- sprintf(_("Unable to list addresses from %s"),
- $abook->backends[$backend]->sname) . '' ,
- 'center' ) . "\n";
+ sprintf(_("Unable to list addresses from %s"),
+ $abook->backends[$backend]->sname) . '' ,
+ 'center' ) . "\n";
}
} else {
$res = $abook->list_addr();
@@ -272,41 +277,40 @@ if ($show == 'form' && empty($listall)) {
display_result($res, true);
}
- } else {
- if( !empty( $listall ) ){
- $query = '*';
- }
-
- /* Do the search */
- if (!empty($query)) {
+ } elseif (!empty($query)) {
+ /* Do the search (listall is not set. query is set.)*/
- if($backend == -1) {
- $res = $abook->s_search($query);
- } else {
- $res = $abook->s_search($query, $backend);
- }
+ if($backend == -1) {
+ $res = $abook->s_search($query);
+ } else {
+ $res = $abook->s_search($query, $backend);
+ }
- if (!is_array($res)) {
- echo html_tag( 'p', '
' .
- _("Your search failed with the following error(s)") .
- ':
' . $abook->error . "\n" ,
- 'center' ) .
+ if (!is_array($res)) {
+ echo html_tag( 'p', '
' .
+ _("Your search failed with the following error(s)") .
+ ':
' . $abook->error . "\n" ,
+ 'center' ) .
"\n