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