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 | |
0fd2f513 |
208 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
209 | echo '<tr><td>'; |
210 | |
70f1b6b5 |
211 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, |
4a6762c5 |
212 | $msg_cnt_str, $toggle_all, 1); |
70f1b6b5 |
213 | |
0fd2f513 |
214 | echo '</td></tr>'; |
215 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
216 | echo '<tr><td>'; |
217 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
218 | echo ' <tr><td>'; |
219 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
220 | echo '<tr><td>'; |
70f1b6b5 |
221 | |
222 | printHeader($mailbox, 6, $color, false); |
223 | |
59a623e6 |
224 | displayMessageArray($imapConnection, $cnt, 1, |
d215ca7d |
225 | $msort, $mailbox, $sort, $color, $cnt, $where, $what); |
70f1b6b5 |
226 | |
0fd2f513 |
227 | echo '</td></tr></table></td></tr></table>'; |
70f1b6b5 |
228 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
4a6762c5 |
229 | echo '</td></tr></table>'; |
59a623e6 |
230 | } |
231 | } |
232 | |
0d672ac0 |
233 | /* ------------------------ main ------------------------ */ |
234 | |
23a9084b |
235 | /* reset these arrays on each page load just in case */ |
bebf762c |
236 | $attributes = array (); |
237 | $saved_attributes = array (); |
70c4fd84 |
238 | $search_all = 'none'; |
23a9084b |
239 | $perbox_count = array (); |
aa45f943 |
240 | $recent_count = getPref($data_dir, $username, 'search_memory', 0); |
56e0b3b7 |
241 | |
ba5f492c |
242 | /* get globals we may need */ |
243 | |
244 | $key = $_COOKIE['key']; |
245 | $username = $_SESSION['username']; |
246 | $onetimepad = $_SESSION['onetimepad']; |
247 | $delimiter = $_SESSION['delimiter']; |
248 | |
249 | if (isset($_GET['mailbox'])) { |
250 | $mailbox = strip_tags($_GET['mailbox']); |
251 | } |
252 | if (isset($_GET['submit'])) { |
253 | $submit = strip_tags($_GET['submit']); |
254 | } |
255 | if (isset($_GET['what'])) { |
256 | $what = $_GET['what']; |
257 | } |
258 | if (isset($_GET['where'])) { |
259 | $where = strip_tags($_GET['where']); |
260 | } |
261 | if (isset($_GET['checkall'])) { |
262 | $checkall = strip_tags($_GET['checkall']); |
263 | } |
264 | if (isset($_GET['count'])) { |
265 | $count = strip_tags($_GET['count']); |
266 | } |
d81e351b |
267 | |
23a9084b |
268 | /* get mailbox names */ |
29eb5486 |
269 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
c1cb7ba4 |
270 | $boxes = sqimap_mailbox_list($imapConnection); |
271 | |
23a9084b |
272 | /* set current mailbox to INBOX if none was selected or if page |
273 | was called to search all folders. */ |
14c62c12 |
274 | if ( !isset($mailbox) || $mailbox == 'None' || $mailbox == '' ) { |
56e0b3b7 |
275 | $mailbox = $boxes[0]['unformatted']; |
276 | } |
3b7d68e6 |
277 | if ($mailbox == 'All Folders') { |
70c4fd84 |
278 | $search_all = 'all'; |
c1cb7ba4 |
279 | } |
280 | |
548a552a |
281 | if (isset($composenew) && $composenew) { |
d7f8e6e6 |
282 | $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox). |
283 | "&session=$composesession&attachedmessages=true&"; |
284 | displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false); |
548a552a |
285 | } else { |
286 | displayPageHeader($color, $mailbox); |
287 | } |
23a9084b |
288 | /* See how the page was called and fire off correct function */ |
d4144adf |
289 | if ((!isset($submit) || empty($submit)) && !empty($what)) { |
70c4fd84 |
290 | $submit = _("Search"); |
d4144adf |
291 | } |
70c4fd84 |
292 | if ( !isset( $submit ) ) { |
70c4fd84 |
293 | $submit = ''; |
294 | } else if ($submit == _("Search") && !empty($what)) { |
aa45f943 |
295 | if ($recent_count > 0) { |
296 | update_recent($what, $where, $mailbox, $username, $data_dir); |
297 | } |
56e0b3b7 |
298 | } |
88cb1b4d |
299 | elseif ($submit == 'forget') { |
56e0b3b7 |
300 | forget_recent($count, $username, $data_dir); |
301 | } |
88cb1b4d |
302 | elseif ($submit == 'save') { |
56e0b3b7 |
303 | save_recent($count, $username, $data_dir); |
304 | } |
88cb1b4d |
305 | elseif ($submit == 'delete') { |
56e0b3b7 |
306 | delete_saved($count, $username, $data_dir); |
307 | } |
23a9084b |
308 | |
29eb5486 |
309 | do_hook('search_before_form'); |
56e0b3b7 |
310 | |
6206f6c4 |
311 | echo html_tag( 'table', |
dcbe1ecc |
312 | html_tag( 'tr', "\n" . |
313 | html_tag( 'td', '<b>' . _("Search") . '</b>', 'center', $color[0] ) |
314 | ) , |
315 | '', '', 'width="100%"') . "\n"; |
c61bb006 |
316 | |
23a9084b |
317 | /* update the recent and saved searches from the pref files */ |
bebf762c |
318 | $attributes = get_recent($username, $data_dir); |
bebf762c |
319 | $saved_attributes = get_saved($username, $data_dir); |
320 | $saved_count = count($saved_attributes['saved_what']); |
91954f9e |
321 | $count_all = 0; |
a7d0eaf6 |
322 | |
184ef883 |
323 | /* Saved Search Table */ |
56e0b3b7 |
324 | if ($saved_count > 0) { |
dcbe1ecc |
325 | echo "<br>\n" |
326 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
327 | . html_tag( 'tr', |
328 | html_tag( 'td', '<b>Saved Searches</b>', 'center' ) |
329 | ) |
330 | . html_tag( 'tr' ) |
331 | . html_tag( 'td' ) |
332 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="2" cellspacing="2" border="0"' ); |
184ef883 |
333 | for ($i=0; $i < $saved_count; ++$i) { |
88cb1b4d |
334 | if ($i % 2) { |
dcbe1ecc |
335 | echo html_tag( 'tr', '', '', $color[0] ); |
88cb1b4d |
336 | } else { |
dcbe1ecc |
337 | echo html_tag( 'tr', '', '', $color[4] ); |
184ef883 |
338 | } |
dcbe1ecc |
339 | echo html_tag( 'td', $saved_attributes['saved_folder'][$i], 'left', '', 'width="35%"' ) |
340 | . html_tag( 'td', $saved_attributes['saved_what'][$i], 'left' ) |
341 | . html_tag( 'td', $saved_attributes['saved_where'][$i], 'center' ) |
342 | . html_tag( 'td', '', 'right' ) |
343 | . '<a href=search.php' |
ba5f492c |
344 | . '?mailbox=' . htmlentities($saved_attributes['saved_folder'][$i]) |
345 | . '&what=' . htmlentities($saved_attributes['saved_what'][$i]) |
346 | . '&where=' . htmlentities($saved_attributes['saved_where'][$i]) |
dcbe1ecc |
347 | . '>' . _("edit") . '</a>' |
88cb1b4d |
348 | . ' | ' |
dcbe1ecc |
349 | . '<a href=search.php' |
bebf762c |
350 | . '?mailbox=' . urlencode($saved_attributes['saved_folder'][$i]) |
351 | . '&what=' . urlencode($saved_attributes['saved_what'][$i]) |
352 | . '&where=' . urlencode($saved_attributes['saved_where'][$i]) |
5e9e90fd |
353 | . '&submit=Search_no_update' |
dcbe1ecc |
354 | . '>' . _("search") . '</a>' |
88cb1b4d |
355 | . ' | ' |
dcbe1ecc |
356 | . "<a href=search.php?count=$i&submit=delete>" |
88cb1b4d |
357 | . _("delete") |
dcbe1ecc |
358 | . '</a>' |
359 | . '</td></tr>'; |
56e0b3b7 |
360 | } |
dcbe1ecc |
361 | echo "</table></td></tr></table>\n"; |
a7d0eaf6 |
362 | } |
363 | |
56e0b3b7 |
364 | if ($recent_count > 0) { |
fab3baa6 |
365 | echo "<br>\n" |
366 | . html_tag( 'table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"' ) |
367 | . html_tag( 'tr', |
368 | html_tag( 'td', '<b>' . _("Recent Searches") . '</b>', 'center' ) |
369 | ) |
370 | . html_tag( 'tr' ) |
371 | . html_tag( 'td' ) |
372 | . html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="0" cellspacing="0" border="0"' ); |
bebf762c |
373 | for ($i=1; $i <= $recent_count; ++$i) { |
374 | if (isset($attributes['search_folder'][$i])) { |
375 | if ($attributes['search_folder'][$i] == "") { |
376 | $attributes['search_folder'][$i] = "INBOX"; |
377 | } |
184ef883 |
378 | } |
379 | if ($i % 2) { |
fab3baa6 |
380 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
381 | } else { |
fab3baa6 |
382 | echo html_tag( 'tr', '', '', $color[0] ); |
184ef883 |
383 | } |
bebf762c |
384 | if (isset($attributes['search_what'][$i]) && |
385 | !empty($attributes['search_what'][$i])) { |
fab3baa6 |
386 | echo html_tag( 'td', $attributes['search_folder'][$i], 'left', '', 'width="35%"' ) |
387 | . html_tag( 'td', $attributes['search_what'][$i], 'left' ) |
388 | . html_tag( 'td', $attributes['search_where'][$i], 'center' ) |
389 | . html_tag( 'td', '', 'right' ) |
390 | . "<a href=search.php?count=$i&submit=save>" |
184ef883 |
391 | . _("save") |
fab3baa6 |
392 | . '</a>' |
184ef883 |
393 | . ' | ' |
fab3baa6 |
394 | . '<a href=search.php' |
bebf762c |
395 | . '?mailbox=' . urlencode($attributes['search_folder'][$i]) |
396 | . '&what=' . urlencode($attributes['search_what'][$i]) |
397 | . '&where=' . urlencode($attributes['search_where'][$i]) |
5e9e90fd |
398 | . '&submit=Search_no_update' |
fab3baa6 |
399 | . '>' . _("search") . '</a>' |
184ef883 |
400 | . ' | ' |
fab3baa6 |
401 | . "<a href=search.php?count=$i&submit=forget>" |
184ef883 |
402 | . _("forget") |
fab3baa6 |
403 | . '</a>' |
404 | . '</td></tr>'; |
0d672ac0 |
405 | } |
bebf762c |
406 | } |
fab3baa6 |
407 | echo '</table></td></tr></table><br>'; |
56e0b3b7 |
408 | } |
184ef883 |
409 | |
d81e351b |
410 | |
411 | if (isset($newsort)) { |
412 | $sort = $newsort; |
9837b0a5 |
413 | sqsession_register($sort, 'sort'); |
d81e351b |
414 | } |
415 | |
416 | /********************************************************************* |
417 | * Check to see if we can use cache or not. Currently the only time * |
418 | * when you will not use it is when a link on the left hand frame is * |
419 | * used. Also check to make sure we actually have the array in the * |
420 | * registered session data. :) * |
421 | *********************************************************************/ |
422 | if (! isset($use_mailbox_cache)) { |
423 | $use_mailbox_cache = 0; |
424 | } |
425 | |
426 | /* There is a problem with registered vars in 4.1 */ |
427 | /* |
428 | if( substr( phpversion(), 0, 3 ) == '4.1' ) { |
429 | $use_mailbox_cache = FALSE; |
430 | } |
431 | */ |
432 | |
184ef883 |
433 | /* Search Form */ |
fab3baa6 |
434 | echo html_tag( 'div', '<b>' . _("Current Search") . '</b>', 'left' ) . "\n" |
435 | . '<form action="search.php" name="s">' |
436 | . html_tag( 'table', '', '', '', 'width="95%" cellpadding="0" cellspacing="0" border="0"' ) |
437 | . html_tag( 'tr' ) |
438 | . html_tag( 'td', '', 'left' ) |
439 | . '<select name="mailbox">'; |
56e0b3b7 |
440 | for ($i = 0; $i < count($boxes); $i++) { |
441 | if (!in_array('noselect', $boxes[$i]['flags'])) { |
442 | $box = $boxes[$i]['unformatted']; |
46bc57c1 |
443 | $box2 = str_replace(' ', ' ', |
444 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
3b7d68e6 |
445 | if( $box2 == 'INBOX' ) { |
446 | $box2 = _("INBOX"); |
70c4fd84 |
447 | } |
fab3baa6 |
448 | echo ' <option value="' . $box . '"'; |
449 | if ($mailbox == $box) { echo ' selected'; } |
450 | echo '>' . $box2 . '</option>' . "\n"; |
56e0b3b7 |
451 | } |
452 | } |
fab3baa6 |
453 | echo '<option value="All Folders"'; |
454 | if ($mailbox == 'All Folders') { |
455 | echo ' selected'; |
0d672ac0 |
456 | } |
fab3baa6 |
457 | echo ">All folders</option>\n"; |
458 | echo ' </select>'. |
459 | " </td>\n"; |
88cb1b4d |
460 | if ( !isset( $what ) ) { |
461 | $what = ''; |
462 | } |
e970aa41 |
463 | if ( !isset( $where ) ) { |
0fd2f513 |
464 | $where = 'FROM'; |
e970aa41 |
465 | } |
466 | |
467 | |
56e0b3b7 |
468 | $what_disp = str_replace(',', ' ', $what); |
469 | $what_disp = str_replace('\\\\', '\\', $what_disp); |
470 | $what_disp = str_replace('\\"', '"', $what_disp); |
471 | $what_disp = str_replace('"', '"', $what_disp); |
fab3baa6 |
472 | echo html_tag( 'td', '<input type="text" size="35" name="what" value="' . $what_disp . '">' . "\n", 'center' ) |
473 | . html_tag( 'td', '', 'right' ) |
474 | . "<select name=\"where\">"; |
56e0b3b7 |
475 | s_opt( 'BODY', $where, _("Body") ); |
476 | s_opt( 'TEXT', $where, _("Everywhere") ); |
477 | s_opt( 'SUBJECT', $where, _("Subject") ); |
478 | s_opt( 'FROM', $where, _("From") ); |
479 | s_opt( 'CC', $where, _("Cc") ); |
480 | s_opt( 'TO', $where, _("To") ); |
fab3baa6 |
481 | echo " </select>\n" . |
482 | " </td>\n". |
483 | html_tag( 'td', '<input type="submit" name="submit" value="' . _("Search") . '">' . "\n", 'center', '', 'colspan="3"' ) . |
484 | " </tr>\n". |
485 | "</form>\n". |
486 | " </table>\n". |
487 | "</td></tr></table>\n"; |
56e0b3b7 |
488 | |
489 | |
88cb1b4d |
490 | do_hook('search_after_form'); |
56e0b3b7 |
491 | |
88cb1b4d |
492 | /* |
493 | search all folders option still in the works. returns a table for each |
70c4fd84 |
494 | folder it finds a match in. |
88cb1b4d |
495 | */ |
56e0b3b7 |
496 | |
e92eab8b |
497 | $old_value = 0; |
794d59c0 |
498 | if ($allow_thread_sort == TRUE) { |
e92eab8b |
499 | $old_value = $allow_thread_sort; |
794d59c0 |
500 | $allow_thread_sort = FALSE; |
e92eab8b |
501 | } |
502 | |
88cb1b4d |
503 | if ($search_all == 'all') { |
504 | $mailbox == ''; |
56e0b3b7 |
505 | $boxcount = count($boxes); |
d81e351b |
506 | echo '<BR><CENTER><B>' . |
88cb1b4d |
507 | _("Search Results") . |
d81e351b |
508 | "</B><CENTER><BR>\n"; |
56e0b3b7 |
509 | for ($x=0;$x<$boxcount;$x++) { |
510 | if (!in_array('noselect', $boxes[$x]['flags'])) { |
88cb1b4d |
511 | $mailbox = $boxes[$x]['unformatted']; |
512 | } |
70c4fd84 |
513 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
56e0b3b7 |
514 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
515 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
516 | $count_all = count($msgs); |
70f1b6b5 |
517 | printSearchMessages($msgs, $mailbox, $count_all, $imapConnection, |
d215ca7d |
518 | $where, $what, false, false); |
d81e351b |
519 | array_push($perbox_count, $count_all); |
23a9084b |
520 | } |
521 | } |
522 | for ($i=0;$i<count($perbox_count);$i++) { |
59a623e6 |
523 | if ($perbox_count[$i]) { |
524 | $count_all = true; |
e13e66be |
525 | break; |
88cb1b4d |
526 | } |
527 | } |
59a623e6 |
528 | if (!$count_all) { |
529 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
56e0b3b7 |
530 | } |
0d672ac0 |
531 | } |
0d672ac0 |
532 | |
23a9084b |
533 | /* search one folder option */ |
56e0b3b7 |
534 | else { |
70c4fd84 |
535 | if (($submit == _("Search") || $submit == 'Search_no_update') && !empty($what)) { |
dcbe1ecc |
536 | echo '<br>' |
537 | . html_tag( 'div', '<b>' . _("Search Results") . '</b>', 'center' ) . "\n"; |
56e0b3b7 |
538 | sqimap_mailbox_select($imapConnection, $mailbox); |
d81e351b |
539 | $msgs = sqimap_search($imapConnection, $where, $what, $mailbox, $color, 0, $search_all, $count_all); |
59a623e6 |
540 | if (count($msgs)) { |
70f1b6b5 |
541 | printSearchMessages($msgs, $mailbox, count($msgs), $imapConnection, |
d215ca7d |
542 | $where, $what, false, false); |
59a623e6 |
543 | } else { |
544 | echo '<br><center>' . _("No Messages Found") . '</center>'; |
545 | } |
56e0b3b7 |
546 | } |
29eb5486 |
547 | } |
56e0b3b7 |
548 | |
23a9084b |
549 | /* must have search terms to search */ |
70c4fd84 |
550 | if ($submit == _("Search") && empty($what)) { |
dcbe1ecc |
551 | echo '<br>' |
552 | . html_tag( 'div', '<b>Please enter something to search for</b>', 'center' ) . "\n"; |
56e0b3b7 |
553 | } |
554 | |
e92eab8b |
555 | $allow_thread_sort = $old_value; |
556 | |
d81e351b |
557 | |
70c4fd84 |
558 | do_hook('search_bottom'); |
56e0b3b7 |
559 | sqimap_logout ($imapConnection); |
29eb5486 |
560 | echo '</body></html>'; |
99d2a184 |
561 | |
91954f9e |
562 | ?> |