b2e337743df8d1e35f3abfeb2bdb9cd41be42c5a
5 * Handle addressbook searching in the popup window.
7 * NOTE: A lot of this code is similar to the code in
8 * addrbook_search_html.html -- If you change one,
9 * change the other one too!
11 * @copyright © 1999-2007 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * @package squirrelmail
15 * @subpackage addressbook
19 * Include the SquirrelMail initialization file.
21 require('../include/init.php');
23 include_once(SM_PATH
. 'functions/forms.php');
24 include_once(SM_PATH
. 'functions/addressbook.php');
25 include_once(SM_PATH
. 'templates/util_addressbook.php');
29 * @param array $res Array of search results
30 * @param bool $includesource [Default=true]
33 function display_result($res, $includesource = true) {
34 global $oTemplate, $oErrorHandler;
36 if(sizeof($res) <= 0) return;
38 $oTemplate->assign('use_js', true);
39 $oTemplate->assign('include_abook_name', $includesource);
40 $oTemplate->assign('addresses', formatAddressList($res));
42 $oTemplate->display('addrbook_search_list.tpl');
45 /* ================= End of functions ================= */
47 /** lets get the global vars we may need */
49 if (! sqgetGlobalVar('show' , $show)) {
52 if (! sqgetGlobalVar('query', $query, SQ_POST
)) {
55 if (! sqgetGlobalVar('listall', $listall, SQ_POST
)) {
58 if (! sqgetGlobalVar('backend', $backend, SQ_POST
)) {
65 /** set correct value of $default_charset */
69 if (empty($query) && empty($show) && !isset($listall)) {
70 $oTemplate->assign('note', htmlspecialchars(_("No persons matching your search were found")));
71 $oTemplate->display('note.tpl');
75 /* Initialize addressbook, show init errors only in bottom frame */
76 $showerr=($show=='form' ?
false : true);
77 $abook = addressbook_init($showerr);
79 /* Create search form (top frame) */
80 if ($show == 'form' && ! isset($listall)) {
81 echo "<form name=\"sform\" target=\"abookres\" action=\"addrbook_search.php\" method=\"POST\">\n";
83 $oTemplate->assign('use_js', true);
84 $oTemplate->assign('backends', getBackends());
85 $oTemplate->display('addressbook_search_form.tpl');
90 * List addresses (bottom frame)
91 * If listall is set, list all entries in selected backend.
92 * If $show is 'blank' (initial call of address book popup) - list
93 * personal address book.
95 if ($show == 'blank' ||
isset($listall)) {
97 if($backend != -1 ||
$show == 'blank') {
98 if ($show == 'blank') {
99 $backend = $abook->localbackend
;
101 $res = $abook->list_addr($backend);
104 usort($res,'alistcmp');
105 display_result($res, false);
107 plain_error_message(sprintf(_("Unable to list addresses from %s"), $abook->backends
[$backend]->sname
));
110 $res = $abook->list_addr();
111 usort($res,'alistcmp');
112 display_result($res, true);
115 } elseif (!empty($query)) {
116 /* Do the search (listall is not set. query is set.)*/
119 $res = $abook->s_search($query);
121 $res = $abook->s_search($query, $backend);
124 if (!is_array($res)) {
125 plain_error_message( _("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error
)) );
126 } elseif (sizeof($res) == 0) {
127 $oTemplate->assign('note', _("No persons matching your search were found"));
128 $oTemplate->display('note.tpl');
130 display_result($res);
134 * listall is not set, query is not set or empty.
135 * User hit search button without entering search expression.
137 plain_error_message(_("Nothing to search"));
141 $oTemplate->display('footer.tpl');