Port Thijs fix (rev.13790) to DEVEL: no words must be an empty array, not a string...
[squirrelmail.git] / src / addrbook_search_html.php
1 <?php
2 /**
3 * addrbook_search_html.php
4 *
5 * Handle addressbook searching with pure html.
6 *
7 * This file is included from compose.php
8 *
9 * @copyright &copy; 1999-2009 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage addressbook
14 */
15
16 /**
17 * Include the SquirrelMail initialization file.
18 * Because this file can also be included within compose we check for the $bInit
19 * var which is set inside ini.php. It's needed because compose already includes
20 * init.php.
21 */
22 if (!isset($bInit)) {
23 /** This is the addrbook_search_html page */
24 define('PAGE_NAME', 'addrbook_search_html');
25
26 include('../include/init.php');
27 }
28
29 /** SquirrelMail required files. */
30 include_once(SM_PATH . 'functions/date.php');
31 include_once(SM_PATH . 'functions/addressbook.php');
32 include_once(SM_PATH . 'templates/util_addressbook.php');
33
34 sqgetGlobalVar('session', $session, SQ_POST);
35 sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
36 if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
37 $addrquery='';
38 sqgetGlobalVar('listall', $listall, SQ_POST);
39 sqgetGlobalVar('backend', $backend, SQ_POST);
40
41 /**
42 * Insert hidden data
43 */
44 function addr_insert_hidden() {
45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, $mailprio,
46 $request_mdn, $request_dr, $identity, $session, $composeMessage;
47
48 //FIXME Do not echo HTML from the core. This file already uses templates mostly, so why are we echoing here at all?!?
49 if (substr($body, 0, 1) == "\r") {
50 echo addHidden('body', "\n".$body);
51 } else {
52 echo addHidden('body', $body);
53 }
54
55 if (is_object($composeMessage) && $composeMessage->entities)
56 echo addHidden('attachments', serialize($composeMessage->entities));
57
58 echo addHidden('session', $session).
59 addHidden('subject', $subject).
60 addHidden('send_to', $send_to).
61 addHidden('send_to_bcc', $send_to_bcc).
62 addHidden('send_to_cc', $send_to_cc).
63 addHidden('mailprio', $mailprio).
64 addHidden('request_mdn', $request_mdn).
65 addHidden('request_dr', $request_dr).
66 addHidden('identity', $identity).
67 addHidden('mailbox', $mailbox).
68 addHidden('from_htmladdr_search', 'true');
69 }
70
71
72 /**
73 * List search results
74 * @param array $res Array containing results of search
75 * @param bool $includesource If true, adds backend column to address listing
76 */
77 function addr_display_result($res, $includesource = true) {
78 global $PHP_SELF, $oTemplate, $oErrorHandler;
79
80
81 echo addForm($PHP_SELF, 'post', 'addressbook').
82 addHidden('html_addr_search_done', 'true');
83 addr_insert_hidden();
84
85 $oTemplate->assign('compose_addr_pop', false);
86 $oTemplate->assign('include_abook_name', $includesource);
87 $oTemplate->assign('addresses', formatAddressList($res));
88
89 $oTemplate->display('addrbook_search_list.tpl');
90
91 echo '</form>';
92 }
93
94 /* --- End functions --- */
95
96 if ($compose_new_win == '1') {
97 compose_Header($color, $mailbox);
98 }
99 else {
100 displayPageHeader($color, $mailbox);
101 }
102
103 /** set correct value of $default_charset */
104 set_my_charset();
105
106 /* Initialize addressbook */
107 $abook = addressbook_init();
108
109
110 /* Search form */
111 echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
112 addr_insert_hidden();
113 if (isset($session)) {
114 echo addHidden('session', $session);
115 }
116
117 $oTemplate->assign('compose_addr_pop', false);
118 $oTemplate->assign('backends', getBackends());
119
120 $oTemplate->display('addressbook_search_form.tpl');
121
122 echo "</form>\n";
123 do_hook('addrbook_html_search_below', $null);
124 /* End search form */
125
126 /* List addresses. Show personal addressbook */
127 if ($addrquery == '' || ! empty($listall)) {
128 // TODO: recheck all conditions and simplity if statements
129 if (! isset($backend) || $backend != -1 || $addrquery == '') {
130 if ($addrquery == '' && empty($listall)) {
131 $backend = $abook->localbackend;
132 }
133
134 $res = $abook->list_addr($backend);
135
136 if (is_array($res)) {
137 usort($res,'alistcmp');
138 addr_display_result($res, false);
139 } else {
140 plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
141 }
142
143 } else {
144 $res = $abook->list_addr();
145 usort($res,'alistcmp');
146 addr_display_result($res, true);
147 }
148 $oTemplate->display('footer.tpl');
149 exit;
150 } elseif (!empty($addrquery)) {
151 /* Do the search */
152 if ($backend == -1) {
153 $res = $abook->s_search($addrquery);
154 } else {
155 $res = $abook->s_search($addrquery, $backend);
156 }
157
158 if (!is_array($res)) {
159 plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error)));
160 } elseif (sizeof($res) == 0) {
161 $oTemplate->assign('note', _("No persons matching your search were found"));
162 $oTemplate->display('note.tpl');
163 } else {
164 addr_display_result($res);
165 }
166 } else {
167 // not first time display, not listall and search is empty
168 // TODO: I think, this part of control structure is never reached.
169 plain_error_message(_("Nothing to search"));
170 }
171
172 if ($addrquery == '' || sizeof($res) == 0) {
173 //FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
174 echo '<div style="text-align: center;">'.
175 addForm('compose.php','post','k');
176 addr_insert_hidden();
177 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
178 '</form></div></nobr>';
179 }
180
181 echo '<hr />';
182
183 $oTemplate->display('footer.tpl');