c61bb006 |
1 | <?php |
245a6892 |
2 | |
35586184 |
3 | /** |
a5ee5ac2 |
4 | * search.php |
35586184 |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * $Id$ |
10 | */ |
2d367c68 |
11 | |
86725763 |
12 | /* Path for SquirrelMail required files. */ |
13 | define('SM_PATH','../'); |
14 | |
15 | /* SquirrelMail required files. */ |
08185f2a |
16 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
17 | require_once(SM_PATH . 'functions/imap.php'); |
18 | require_once(SM_PATH . 'functions/imap_search.php'); |
19 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
20 | require_once(SM_PATH . 'functions/array.php'); |
21 | require_once(SM_PATH . 'functions/strings.php'); |
c61bb006 |
22 | |
e92eab8b |
23 | global $allow_thread_sort; |
56e0b3b7 |
24 | |
0b97a708 |
25 | /* get globals we may need */ |
26 | |
27 | $key = $_COOKIE['key']; |
28 | $username = $_SESSION['username']; |
29 | $onetimepad = $_SESSION['onetimepad']; |
30 | $delimiter = $_SESSION['delimiter']; |
31 | |
32 | if (isset($_GET['mailbox'])) { |
33 | $mailbox = strip_tags($_GET['mailbox']); |
34 | } |
35 | if (isset($_GET['submit'])) { |
36 | $submit = strip_tags($_GET['submit']); |
37 | } |
38 | if (isset($_GET['what'])) { |
39 | $what = $_GET['what']; |
40 | } |
41 | if (isset($_GET['where'])) { |
42 | $where = strip_tags($_GET['where']); |
43 | } |
44 | if (isset($_GET['checkall'])) { |
45 | $checkall = strip_tags($_GET['checkall']); |
46 | } |
47 | if (isset($_GET['count'])) { |
48 | $count = strip_tags($_GET['count']); |
49 | } |
50 | /* end of get globals */ |
51 | |
23a9084b |
52 | /* here are some functions, could go in imap_search.php |
23a9084b |
53 | this was here, pretty handy */ |
29eb5486 |
54 | function s_opt( $val, $sel, $tit ) { |
55 | echo " <option value=\"$val\""; |
0d672ac0 |
56 | if ( $sel == $val ) { |
bd9bbfef |
57 | echo ' selected'; |
99d2a184 |
58 | } |
29eb5486 |
59 | echo ">$tit</option>\n"; |
60 | } |
99d2a184 |
61 | |
bebf762c |
62 | /* function to get the recent searches and put them in the attributes array */ |
63 | function get_recent($username, $data_dir) { |
64 | $attributes = array(); |
65 | $types = array('search_what', 'search_where', 'search_folder'); |
56e0b3b7 |
66 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
56e0b3b7 |
67 | for ($x=1;$x<=$recent_count;$x++) { |
bebf762c |
68 | reset($types); |
69 | foreach ($types as $key) { |
70 | $attributes[$key][$x] = getPref($data_dir, $username, $key.$x, ""); |
71 | } |
56e0b3b7 |
72 | } |
bebf762c |
73 | return $attributes; |
56e0b3b7 |
74 | } |
75 | |
bebf762c |
76 | /* function to get the saved searches and put them in the saved_attributes array */ |
77 | function get_saved($username, $data_dir) { |
78 | $saved_attributes = array(); |
79 | $types = array('saved_what', 'saved_where', 'saved_folder'); |
80 | foreach ($types as $key) { |
81 | for ($x=1;;$x++) { |
82 | $saved_attributes[$key][$x] = getPref($data_dir, $username, $key."$x", ""); |
83 | if ($saved_attributes[$key][$x] == "") { |
84 | array_pop($saved_attributes[$key]); |
85 | break; |
86 | } |
87 | } |
56e0b3b7 |
88 | } |
bebf762c |
89 | return $saved_attributes; |
56e0b3b7 |
90 | } |
91 | |
23a9084b |
92 | /* function to update recent pref arrays */ |
93 | function update_recent($what, $where, $mailbox, $username, $data_dir) { |
bebf762c |
94 | $attributes = array(); |
95 | $types = array('search_what', 'search_where', 'search_folder'); |
96 | $input = array($what, $where, $mailbox); |
97 | $attributes = get_recent( $username, $data_dir); |
98 | reset($types); |
70c4fd84 |
99 | $dupe = 'no'; |
bebf762c |
100 | for ($i=1;$i<=count($attributes['search_what']);$i++) { |
101 | if (isset($attributes['search_what'][$i])) { |
102 | if ($what == $attributes['search_what'][$i] && |
103 | $where == $attributes['search_where'][$i] && |
104 | $mailbox == $attributes['search_folder'][$i]) { |
105 | $dupe = 'yes'; |
106 | } |
23a9084b |
107 | } |
108 | } |
70c4fd84 |
109 | if ($dupe == 'no') { |
bebf762c |
110 | $i = 0; |
111 | foreach ($types as $key) { |
112 | array_push ($attributes[$key], $input[$i]); |
113 | array_shift ($attributes[$key]); |
114 | $i++; |
115 | } |
116 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
117 | $n=0; |
118 | for ($i=1;$i<=$recent_count;$i++) { |
119 | reset($types); |
120 | foreach ($types as $key) { |
121 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
122 | } |
123 | $n++; |
124 | } |
56e0b3b7 |
125 | } |
126 | } |
127 | |
23a9084b |
128 | /* function to forget a recent search */ |
56e0b3b7 |
129 | function forget_recent($forget_index, $username, $data_dir) { |
bebf762c |
130 | $attributes = array(); |
131 | $types = array('search_what', 'search_where', 'search_folder'); |
132 | $attributes = get_recent( $username, $data_dir); |
133 | reset($types); |
134 | foreach ($types as $key) { |
7dba227d |
135 | array_splice($attributes[$key], $forget_index - 1, 1); |
bebf762c |
136 | array_unshift($attributes[$key], ''); |
137 | } |
138 | reset($types); |
56e0b3b7 |
139 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
140 | $n=0; |
141 | for ($i=1;$i<=$recent_count;$i++) { |
bebf762c |
142 | reset($types); |
143 | foreach ($types as $key) { |
144 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
145 | } |
23a9084b |
146 | $n++; |
56e0b3b7 |
147 | } |
148 | } |
23a9084b |
149 | |
150 | /* function to delete a saved search */ |
56e0b3b7 |
151 | function delete_saved($delete_index, $username, $data_dir) { |
bebf762c |
152 | $types = array('saved_what', 'saved_where', 'saved_folder'); |
153 | $attributes = get_saved($username, $data_dir); |
154 | foreach ($types as $key) { |
155 | array_splice($attributes[$key], $delete_index, 1); |
156 | } |
157 | reset($types); |
56e0b3b7 |
158 | $n=0; |
bebf762c |
159 | $saved_count = count($attributes['saved_what']); |
56e0b3b7 |
160 | $last_element = $saved_count + 1; |
56e0b3b7 |
161 | for ($i=1;$i<=$saved_count;$i++) { |
bebf762c |
162 | reset($types); |
163 | foreach ($types as $key) { |
164 | setPref($data_dir, $username, $key.$i, $attributes[$key][$n]); |
165 | } |
23a9084b |
166 | $n++; |
56e0b3b7 |
167 | } |
bebf762c |
168 | reset($types); |
169 | foreach($types as $key) { |
170 | removePref($data_dir, $username, $key.$last_element); |
56e0b3b7 |
171 | } |
70c4fd84 |
172 | } |
6c8388a9 |
173 | |
23a9084b |
174 | /* function to save a search from recent to saved */ |
56e0b3b7 |
175 | function save_recent($save_index, $username, $data_dir) { |
bebf762c |
176 | $attributes = array(); |
177 | $types = array('search_what', 'search_where', 'search_folder'); |
178 | $saved_types = array(0 => 'saved_what', 1 => 'saved_where', 2 => 'saved_folder'); |
179 | $saved_array = get_saved($username, $data_dir); |
180 | $save_index = $save_index -1; |
181 | $saved_count = (count($saved_array['saved_what']) + 1); |
182 | $attributes = get_recent ($username, $data_dir); |
183 | $n = 0; |
184 | foreach ($types as $key) { |
185 | $slice = array_slice($attributes[$key], $save_index, 1); |
186 | $name = $saved_types[$n]; |
187 | setPref($data_dir, $username, $name.$saved_count, $slice[0]); |
188 | $n++; |
189 | } |
56e0b3b7 |
190 | } |
191 | |
d215ca7d |
192 | function printSearchMessages($msgs,$mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false) { |
59a623e6 |
193 | global $sort, $color; |
194 | |
70f1b6b5 |
195 | $msort = calc_msort($msgs, $sort); |
59a623e6 |
196 | if ($cnt > 0) { |
197 | if ( $mailbox == 'INBOX' ) { |
198 | $showbox = _("INBOX"); |
199 | } else { |
200 | $showbox = imap_utf7_decode_local($mailbox); |
201 | } |
202 | echo html_tag( 'div', '<b><big>' . _("Folder:") . ' '. $showbox.'</big></b>','center') . "\n"; |
203 | |
70f1b6b5 |
204 | |
205 | $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt); |
4a6762c5 |
206 | $toggle_all = get_selectall_link(1, $sort); |
70f1b6b5 |
207 | |
4a6762c5 |
208 | echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>'; |
70f1b6b5 |
209 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, |
4a6762c5 |
210 | $msg_cnt_str, $toggle_all, 1); |
70f1b6b5 |
211 | |
212 | |
213 | printHeader($mailbox, 6, $color, false); |
214 | |
59a623e6 |
215 | displayMessageArray($imapConnection, $cnt, 1, |
d215ca7d |
216 | $msort, $mailbox, $sort, $color, $cnt, $where, $what); |
70f1b6b5 |
217 | |
218 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
4a6762c5 |
219 | echo '</td></tr></table>'; |
220 | |
59a623e6 |
221 | } |
222 | } |
223 | |
0d672ac0 |
224 | /* ------------------------ main ------------------------ */ |
225 | |
23a9084b |
226 | /* reset these arrays on each page load just in case */ |
bebf762c |
227 | $attributes = array (); |
228 | $saved_attributes = array (); |
70c4fd84 |
229 | $search_all = 'none'; |
23a9084b |
230 | $perbox_count = array (); |
aa45f943 |
231 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
56e0b3b7 |
232 | |
ba5f492c |
233 | /* get globals we may need */ |
234 | |
235 | $key = $_COOKIE['key']; |
236 | $username = $_SESSION['username']; |
237 | $onetimepad = $_SESSION['onetimepad']; |
238 | $delimiter = $_SESSION['delimiter']; |
239 | |
240 | if (isset($_GET['mailbox'])) { |
241 | $mailbox = strip_tags($_GET['mailbox']); |
242 | } |
243 | if (isset($_GET['submit'])) { |
244 | $submit = strip_tags($_GET['submit']); |
245 | } |
246 | if (isset($_GET['what'])) { |
247 | $what = $_GET['what']; |
248 | } |
249 | if (isset($_GET['where'])) { |
250 | $where = strip_tags($_GET['where']); |
251 | } |
252 | if (isset($_GET['checkall'])) { |
253 | $checkall = strip_tags($_GET['checkall']); |
254 | } |
255 | if (isset($_GET['count'])) { |
256 | $count = strip_tags($_GET['count']); |
257 | } |
d81e351b |
258 | |
23a9084b |
259 | /* get mailbox names */ |
29eb5486 |
260 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
c1cb7ba4 |
261 | $boxes = sqimap_mailbox_list($imapConnection); |
262 | |
23a9084b |
263 | /* set current mailbox to INBOX if none was selected or if page |
264 | was called to search all folders. */ |
14c62c12 |
265 | if ( !isset($mailbox) || $mailbox == 'None' || $mailbox == '' ) { |
56e0b3b7 |
266 | $mailbox = $boxes[0]['unformatted']; |
267 | } |
3b7d68e6 |
268 | if ($mailbox == 'All Folders') { |
70c4fd84 |
269 | $search_all = 'all'; |
c1cb7ba4 |
270 | } |
271 | |
548a552a |
272 | if (isset($composenew) && $composenew) { |
d7f8e6e6 |
273 | $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox). |
274 | "&session=$composesession&attachedmessages=true&"; |
275 | displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false); |
548a552a |
276 | } else { |
277 | displayPageHeader($color, $mailbox); |
278 | } |
23a9084b |
279 | /* See how the page was called and fire off correct function */ |
d4144adf |
280 | if ((!isset($submit) || empty($submit)) && !empty($what)) { |
70c4fd84 |
281 | $submit = _("Search"); |
d4144adf |
282 | } |
70c4fd84 |
283 | if ( !isset( $submit ) ) { |
70c4fd84 |
284 | $submit = ''; |
285 | } else if ($submit == _("Search") && !empty($what)) { |
aa45f943 |
286 | if ($recent_count > 0) { |
287 | update_recent($what, $where, $mailbox, $username, $data_dir); |
288 | } |
56e0b3b7 |
289 | } |
88cb1b4d |
290 | elseif ($submit == 'forget') { |
56e0b3b7 |
291 | forget_recent($count, $username, $data_dir); |
292 | } |
88cb1b4d |
293 | elseif ($submit == 'save') { |
56e0b3b7 |
294 | save_recent($count, $username, $data_dir); |
295 | } |
88cb1b4d |
296 | elseif ($submit == 'delete') { |
56e0b3b7 |
297 | delete_saved($count, $username, $data_dir); |
298 | } |
23a9084b |
299 | |
29eb5486 |
300 | do_hook('search_before_form'); |
56e0b3b7 |
301 | |
6206f6c4 |
302 | echo html_tag( 'table', |
dcbe1ecc |
303 | html_tag( 'tr', "\n" . |
304 | html_tag( 'td', '<b>' . _("Search") . '</b>', 'center', $color[0] ) |
305 | ) , |
306 | '', '', 'width="100%"') . "\n"; |
c61bb006 |
307 | |
23a9084b |
308 | /* update the recent and saved searches from the pref files */ |
bebf762c |
309 | $attributes = get_recent($username, $data_dir); |
bebf762c |
310 | $saved_attributes = get_saved($username, $data_dir); |
311 | $saved_count = count($saved_attributes['saved_what']); |
91954f9e |
312 | $count_all = 0; |
a7d0eaf6 |
313 | |
184ef883 |
314 | /* Saved Search Table */ |
56e0b3b7 |
315 | if ($saved_count > 0) { |
dcbe1ecc |
316 | echo "<br>\n" |
317 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
318 | . html_tag( 'tr', |
319 | html_tag( 'td', '<b>Saved Searches</b>', 'center' ) |
320 | ) |
321 | . html_tag( 'tr' ) |
322 | . html_tag( 'td' ) |
323 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="2" cellspacing="2" border="0"' ); |
184ef883 |
324 | for ($i=0; $i < $saved_count; ++$i) { |
88cb1b4d |
325 | if ($i % 2) { |
dcbe1ecc |
326 | echo html_tag( 'tr', '', '', $color[0] ); |
88cb1b4d |
327 | } else { |
dcbe1ecc |
328 | echo html_tag( 'tr', '', '', $color[4] ); |
184ef883 |
329 | } |
dcbe1ecc |
330 | echo html_tag( 'td', $saved_attributes['saved_folder'][$i], 'left', '', 'width="35%"' ) |
331 | . html_tag( 'td', $saved_attributes['saved_what'][$i], 'left' ) |
332 | . html_tag( 'td', $saved_attributes['saved_where'][$i], 'center' ) |
333 | . html_tag( 'td', '', 'right' ) |
334 | . '<a href=search.php' |
ba5f492c |
335 | . '?mailbox=' . htmlentities($saved_attributes['saved_folder'][$i]) |
336 | . '&what=' . htmlentities($saved_attributes['saved_what'][$i]) |
337 | . '&where=' . htmlentities($saved_attributes['saved_where'][$i]) |
dcbe1ecc |
338 | . '>' . _("edit") . '</a>' |
88cb1b4d |
339 | . ' | ' |
dcbe1ecc |
340 | . '<a href=search.php' |
bebf762c |
341 | . '?mailbox=' . urlencode($saved_attributes['saved_folder'][$i]) |
342 | . '&what=' . urlencode($saved_attributes['saved_what'][$i]) |
343 | . '&where=' . urlencode($saved_attributes['saved_where'][$i]) |
5e9e90fd |
344 | . '&submit=Search_no_update' |
dcbe1ecc |
345 | . '>' . _("search") . '</a>' |
88cb1b4d |
346 | . ' | ' |
dcbe1ecc |
347 | . "<a href=search.php?count=$i&submit=delete>" |
88cb1b4d |
348 | . _("delete") |
dcbe1ecc |
349 | . '</a>' |
350 | . '</td></tr>'; |
56e0b3b7 |
351 | } |
dcbe1ecc |
352 | echo "</table></td></tr></table>\n"; |
a7d0eaf6 |
353 | } |
354 | |
56e0b3b7 |
355 | if ($recent_count > 0) { |
fab3baa6 |
356 | echo "<br>\n" |
357 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
358 | . html_tag( 'tr', |
359 | html_tag( 'td', '<b>' . _("Recent Searches") . '</b>', 'center' ) |
360 | ) |
361 | . html_tag( 'tr' ) |
362 | . html_tag( 'td' ) |
363 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="0" cellspacing="0" border="0"' ); |
bebf762c |
364 | for ($i=1; $i <= $recent_count; ++$i) { |
365 | if (isset($attributes['search_folder'][$i])) { |
366 | if ($attributes['search_folder'][$i] == "") { |
367 | $attributes['search_folder'][$i] = "INBOX"; |
368 | } |
184ef883 |
369 | } |
370 | if ($i % 2) { |
fab3baa6 |
371 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
372 | } else { |
fab3baa6 |
373 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
374 | } |
bebf762c |
375 | if (isset($attributes['search_what'][$i]) && |
376 | !empty($attributes['search_what'][$i])) { |
fab3baa6 |
377 | echo html_tag( 'td', $attributes['search_folder'][$i], 'left', '', 'width="35%"' ) |
378 | . html_tag( 'td', $attributes['search_what'][$i], 'left' ) |
379 | . html_tag( 'td', $attributes['search_where'][$i], 'center' ) |
380 | . html_tag( 'td', '', 'right' ) |
381 | . "<a href=search.php?count=$i&submit=save>" |
184ef883 |
382 | . _("save") |
fab3baa6 |
383 | . '</a>' |
184ef883 |
384 | . ' | ' |
fab3baa6 |
385 | . '<a href=search.php' |
bebf762c |
386 | . '?mailbox=' . urlencode($attributes['search_folder'][$i]) |
387 | . '&what=' . urlencode($attributes['search_what'][$i]) |
388 | . '&where=' . urlencode($attributes['search_where'][$i]) |
5e9e90fd |
389 | . '&submit=Search_no_update' |
fab3baa6 |
390 | . '>' . _("search") . '</a>' |
184ef883 |
391 | . ' | ' |
fab3baa6 |
392 | . "<a href=search.php?count=$i&submit=forget>" |
184ef883 |
393 | . _("forget") |
fab3baa6 |
394 | . '</a>' |
395 | . '</td></tr>'; |
0d672ac0 |
396 | } |
bebf762c |
397 | } |
fab3baa6 |
398 | echo '</table></td></tr></table><br>'; |
56e0b3b7 |
399 | } |
184ef883 |
400 | |
d81e351b |
401 | |
402 | if (isset($newsort)) { |
403 | $sort = $newsort; |
404 | session_register('sort'); |
405 | } |
406 | |
407 | /********************************************************************* |
408 | * Check to see if we can use cache or not. Currently the only time * |
409 | * when you will not use it is when a link on the left hand frame is * |
410 | * used. Also check to make sure we actually have the array in the * |
411 | * registered session data. :) * |
412 | *********************************************************************/ |
413 | if (! isset($use_mailbox_cache)) { |
414 | $use_mailbox_cache = 0; |
415 | } |
416 | |
417 | /* There is a problem with registered vars in 4.1 */ |
418 | /* |
419 | if( substr( phpversion(), 0, 3 ) == '4.1' ) { |
420 | $use_mailbox_cache = FALSE; |
421 | } |
422 | */ |
423 | |
184ef883 |
424 | /* Search Form */ |
fab3baa6 |
425 | echo html_tag( 'div', '<b>' . _("Current Search") . '</b>', 'left' ) . "\n" |
426 | . '<form action="search.php" name="s">' |
427 | . html_tag( 'table', '', '', '', 'width="95%" cellpadding="0" cellspacing="0" border="0"' ) |
428 | . html_tag( 'tr' ) |
429 | . html_tag( 'td', '', 'left' ) |
430 | . '<select name="mailbox">'; |
56e0b3b7 |
431 | for ($i = 0; $i < count($boxes); $i++) { |
432 | if (!in_array('noselect', $boxes[$i]['flags'])) { |
433 | $box = $boxes[$i]['unformatted']; |
46bc57c1 |
434 | $box2 = str_replace(' ', ' ', |
435 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
3b7d68e6 |
436 | if( $box2 == 'INBOX' ) { |
437 | $box2 = _("INBOX"); |
70c4fd84 |
438 | } |
fab3baa6 |
439 | echo ' <option value="' . $box . '"'; |
440 | if ($mailbox == $box) { echo ' selected'; } |
441 | echo '>' . $box2 . '</option>' . "\n"; |
56e0b3b7 |
442 | } |
443 | } |
fab3baa6 |
444 | echo '<option value="All Folders"'; |
445 | if ($mailbox == 'All Folders') { |
446 | echo ' selected'; |
0d672ac0 |
447 | } |
fab3baa6 |
448 | echo ">All folders</option>\n"; |
449 | echo ' </select>'. |
450 | " </td>\n"; |
88cb1b4d |
451 | if ( !isset( $what ) ) { |
452 | $what = ''; |
453 | } |
e970aa41 |
454 | if ( !isset( $where ) ) { |
455 | $where = ''; |
456 | } |
457 | |
458 | |
56e0b3b7 |
459 | $what_disp = str_replace(',', ' ', $what); |
460 | $what_disp = str_replace('\\\\', '\\', $what_disp); |
461 | $what_disp = str_replace('\\"', '"', $what_disp); |
462 | $what_disp = str_replace('"', '"', $what_disp); |
fab3baa6 |
463 | echo html_tag( 'td', '<input type="text" size="35" name="what" value="' . $what_disp . '">' . "\n", 'center' ) |
464 | . html_tag( 'td', '', 'right' ) |
465 | . "<select name=\"where\">"; |
56e0b3b7 |
466 | s_opt( 'BODY', $where, _("Body") ); |
467 | s_opt( 'TEXT', $where, _("Everywhere") ); |
468 | s_opt( 'SUBJECT', $where, _("Subject") ); |
469 | s_opt( 'FROM', $where, _("From") ); |
470 | s_opt( 'CC', $where, _("Cc") ); |
471 | s_opt( 'TO', $where, _("To") ); |
fab3baa6 |
472 | echo " </select>\n" . |
473 | " </td>\n". |
474 | html_tag( 'td', '<input type="submit" name="submit" value="' . _("Search") . '">' . "\n", 'center', '', 'colspan="3"' ) . |
475 | " </tr>\n". |
476 | "</form>\n". |
477 | " </table>\n". |
478 | "</td></tr></table>\n"; |
56e0b3b7 |
479 | |
480 | |
88cb1b4d |
481 | do_hook('search_after_form'); |
56e0b3b7 |
482 | |
88cb1b4d |
483 | /* |
484 | search all folders option still in the works. returns a table for each |
70c4fd84 |
485 | folder it finds a match in. |
88cb1b4d |
486 | */ |
56e0b3b7 |
487 | |
e92eab8b |
488 | $old_value = 0; |
794d59c0 |
489 | if ($allow_thread_sort == TRUE) { |
e92eab8b |
490 | $old_value = $allow_thread_sort; |
794d59c0 |
491 | $allow_thread_sort = FALSE; |
e92eab8b |
492 | } |
493 | |
88cb1b4d |
494 | if ($search_all == 'all') { |
495 | $mailbox == ''; |
56e0b3b7 |
496 | $boxcount = count($boxes); |
d81e351b |
497 | echo '<BR><CENTER><B>' . |
88cb1b4d |
498 | _("Search Results") . |
d81e351b |
499 | "</B><CENTER><BR>\n"; |
56e0b3b7 |
500 | for ($x=0;$x<$boxcount;$x++) { |
501 | if (!in_array('noselect', $boxes[$x]['flags'])) { |
88cb1b4d |
502 | $mailbox = $boxes[$x]['unformatted']; |
503 | } |
70c4fd84 |
504 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
56e0b3b7 |
505 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
506 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
507 | $count_all = count($msgs); |
70f1b6b5 |
508 | printSearchMessages($msgs, $mailbox, $count_all, $imapConnection, |
d215ca7d |
509 | $where, $what, false, false); |
d81e351b |
510 | array_push($perbox_count, $count_all); |
23a9084b |
511 | } |
512 | } |
513 | for ($i=0;$i<count($perbox_count);$i++) { |
59a623e6 |
514 | if ($perbox_count[$i]) { |
515 | $count_all = true; |
e13e66be |
516 | break; |
88cb1b4d |
517 | } |
518 | } |
59a623e6 |
519 | if (!$count_all) { |
520 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
56e0b3b7 |
521 | } |
0d672ac0 |
522 | } |
0d672ac0 |
523 | |
23a9084b |
524 | /* search one folder option */ |
56e0b3b7 |
525 | else { |
70c4fd84 |
526 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
dcbe1ecc |
527 | echo '<br>' |
528 | . html_tag( 'div', '<b>' . _("Search Results") . '</b>', 'center' ) . "\n"; |
56e0b3b7 |
529 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
530 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
59a623e6 |
531 | if (count($msgs)) { |
70f1b6b5 |
532 | printSearchMessages($msgs, $mailbox, count($msgs), $imapConnection, |
d215ca7d |
533 | $where, $what, false, false); |
59a623e6 |
534 | } else { |
535 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
536 | } |
56e0b3b7 |
537 | } |
29eb5486 |
538 | } |
56e0b3b7 |
539 | |
23a9084b |
540 | /* must have search terms to search */ |
70c4fd84 |
541 | if ($submit == _("Search") && empty($what)) { |
dcbe1ecc |
542 | echo '<br>' |
543 | . html_tag( 'div', '<b>Please enter something to search for</b>', 'center' ) . "\n"; |
56e0b3b7 |
544 | } |
545 | |
e92eab8b |
546 | $allow_thread_sort = $old_value; |
547 | |
d81e351b |
548 | |
70c4fd84 |
549 | do_hook('search_bottom'); |
56e0b3b7 |
550 | sqimap_logout ($imapConnection); |
29eb5486 |
551 | echo '</body></html>'; |
99d2a184 |
552 | |
91954f9e |
553 | ?> |