c61bb006 |
1 | <?php |
245a6892 |
2 | |
35586184 |
3 | /** |
a5ee5ac2 |
4 | * search.php |
35586184 |
5 | * |
82d304a0 |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
40fbe929 |
9 | * IMAP search page |
10 | * |
30967a1e |
11 | * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas! |
12 | * |
13 | * @version $Id$ |
8f6f9ba5 |
14 | * @package squirrelmail |
313fd1f4 |
15 | * @link http://www.ietf.org/rfc/rfc3501.txt |
40fbe929 |
16 | * @author Alex Lemaresquier - Brainstorm - alex at brainstorm.fr |
35586184 |
17 | */ |
2d367c68 |
18 | |
30967a1e |
19 | /** |
20 | * Path for SquirrelMail required files. |
21 | * @ignore |
22 | */ |
86725763 |
23 | define('SM_PATH','../'); |
24 | |
40fbe929 |
25 | /** SquirrelMail required files. */ |
08185f2a |
26 | require_once(SM_PATH . 'include/validate.php'); |
b2e7eb53 |
27 | require_once(SM_PATH . 'functions/strings.php'); |
6b37252b |
28 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
86725763 |
29 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
b65c5db0 |
30 | require_once(SM_PATH . 'functions/imap_messages.php'); |
0ca9a6ec |
31 | require_once(SM_PATH . 'functions/mime.php'); |
b2e7eb53 |
32 | require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton()... |
c61bb006 |
33 | |
40fbe929 |
34 | /** |
35 | * @param string $a |
36 | * @param string $b |
37 | * @return bool strcoll()-like result |
38 | */ |
6b37252b |
39 | function asearch_unhtml_strcoll($a, $b) |
40 | { |
41 | return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b)); |
42 | } |
40fbe929 |
43 | |
44 | /** |
45 | * @param string $mailbox mailbox name |
46 | * @return string mailbox name ready to display |
47 | */ |
6b37252b |
48 | function imap_get_mailbox_display($mailbox) |
49 | { |
3dffe83f |
50 | if (strtoupper($mailbox) == 'INBOX') |
6b37252b |
51 | return _("INBOX"); |
52 | return imap_utf7_decode_local($mailbox); |
53 | } |
56e0b3b7 |
54 | |
40fbe929 |
55 | /** |
56 | * @param string $mailbox mailbox name |
57 | * @return string mailbox name ready to display |
58 | */ |
6b37252b |
59 | function asearch_get_mailbox_display($mailbox) |
60 | { |
61 | if ($mailbox == 'All Folders') |
62 | return _("All Folders"); |
63 | return imap_get_mailbox_display($mailbox); |
64 | } |
0b97a708 |
65 | |
40fbe929 |
66 | /** |
67 | * @param array $color color array |
68 | * @param string $txt text to display |
69 | * @return string title ready to display |
70 | */ |
05f5b952 |
71 | function asearch_get_title_display($color, $txt) |
6b37252b |
72 | { |
73 | return '<b><big>' . $txt . '</big></b>'; |
74 | } |
0b97a708 |
75 | |
40fbe929 |
76 | /** |
77 | * @param array $color color array |
78 | * @param string $txt text to display |
79 | * @return string error text ready to display |
80 | */ |
05f5b952 |
81 | function asearch_get_error_display($color, $txt) |
6b37252b |
82 | { |
05f5b952 |
83 | return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>'; |
0b97a708 |
84 | } |
6b37252b |
85 | |
40fbe929 |
86 | /** |
87 | * @param array $input_array array to serialize |
88 | * @return string a string containing a byte-stream representation of value that can be stored anywhere |
89 | */ |
6b37252b |
90 | function asearch_serialize($input_array) |
91 | { |
6b37252b |
92 | return serialize($input_array); |
0b97a708 |
93 | } |
6b37252b |
94 | |
40fbe929 |
95 | /** |
96 | * @param string $input_string string to unserialize |
97 | * @return array |
98 | */ |
6b37252b |
99 | function asearch_unserialize($input_string) |
100 | { |
6b37252b |
101 | return unserialize($input_string); |
0b97a708 |
102 | } |
6b37252b |
103 | |
40fbe929 |
104 | /** |
105 | * @param string $data_dir prefs data dir or dsn |
106 | * @param string $username the username |
107 | * @param string $key the pref key |
108 | * @param integer $index the pref key index |
109 | * @param string $default default value |
110 | * @return string pref value |
111 | */ |
6b37252b |
112 | function asearch_getPref($data_dir, $username, $key, $index, $default = '') |
113 | { |
114 | return getPref($data_dir, $username, $key . $index, $default); |
0b97a708 |
115 | } |
6b37252b |
116 | |
40fbe929 |
117 | /** |
118 | * @param string $data_dir prefs data dir or dsn |
119 | * @param string $username the username |
120 | * @param string $key the pref key |
121 | * @param integer $index the pref key index |
122 | * @param string $value pref value to set |
123 | * @return bool status |
124 | */ |
6b37252b |
125 | function asearch_setPref($data_dir, $username, $key, $index, $value) |
126 | { |
127 | return setPref($data_dir, $username, $key . $index, $value); |
0b97a708 |
128 | } |
6b37252b |
129 | |
40fbe929 |
130 | /** |
131 | * @param string $data_dir prefs data dir or dsn |
132 | * @param string $username the username |
133 | * @param string $key the pref key |
134 | * @param integer $index the pref key index |
135 | * @return bool status |
136 | */ |
6b37252b |
137 | function asearch_removePref($data_dir, $username, $key, $index) |
138 | { |
139 | return removePref($data_dir, $username, $key . $index); |
0b97a708 |
140 | } |
0b97a708 |
141 | |
40fbe929 |
142 | /** Sanity checks, done before running the imap command and before push_recent */ |
05f5b952 |
143 | function asearch_check_query($where_array, $what_array, $exclude_array) |
6b37252b |
144 | { |
05f5b952 |
145 | global $imap_asearch_opcodes; |
146 | |
6b37252b |
147 | if (empty($where_array)) |
148 | return _("Please enter something to search for"); |
149 | if (count($exclude_array) == count($where_array)) |
150 | return _("There must be at least one criteria to search for"); |
05f5b952 |
151 | for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) { |
152 | $where = $where_array[$crit_num]; |
153 | $what = $what_array[$crit_num]; |
154 | if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != ''))) |
155 | return _("Error in criteria argument"); |
156 | } |
6b37252b |
157 | return ''; |
56e0b3b7 |
158 | } |
159 | |
40fbe929 |
160 | /** Read the recent searches */ |
6b37252b |
161 | function asearch_read_recent($data_dir, $username) |
162 | { |
163 | global $recent_prefkeys; |
164 | |
165 | $recent_array = array(); |
166 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
167 | for ($recent_num = 0; $recent_num < $recent_max; $recent_num++) { |
168 | foreach ($recent_prefkeys as $prefkey) { |
169 | $pref = asearch_getPref($data_dir, $username, $prefkey, $recent_num); |
170 | /* if (!empty($pref))*/ |
171 | $recent_array[$prefkey][$recent_num] = $pref; |
172 | } |
173 | if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) { |
174 | foreach ($recent_prefkeys as $key) { |
175 | array_pop($recent_array[$key]); |
176 | } |
177 | break; |
178 | } |
179 | } |
180 | return $recent_array; |
56e0b3b7 |
181 | } |
23a9084b |
182 | |
40fbe929 |
183 | /** Get the saved searches */ |
6b37252b |
184 | function asearch_read_saved($data_dir, $username) |
185 | { |
186 | global $saved_prefkeys; |
187 | |
188 | $saved_array = array(); |
189 | $saved_key = $saved_prefkeys[0]; |
190 | for ($saved_count = 0; ; $saved_count++) { |
191 | $pref = asearch_getPref($data_dir, $username, $saved_key, $saved_count); |
192 | if (empty($pref)) |
193 | break; |
194 | } |
195 | for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) { |
196 | foreach ($saved_prefkeys as $key) { |
197 | $saved_array[$key][$saved_num] = asearch_getPref($data_dir, $username, $key, $saved_num); |
198 | } |
199 | } |
200 | return $saved_array; |
201 | } |
202 | |
40fbe929 |
203 | /** Save a recent search */ |
6b37252b |
204 | function asearch_save_recent($data_dir, $username, $recent_index) |
205 | { |
206 | global $recent_prefkeys, $saved_prefkeys; |
207 | |
208 | $saved_array = asearch_read_saved($data_dir, $username); |
209 | $saved_index = count($saved_array[$saved_prefkeys[0]]); |
210 | $recent_array = asearch_read_recent($data_dir, $username); |
211 | $n = 0; |
212 | foreach ($recent_prefkeys as $key) { |
213 | $recent_slice = array_slice($recent_array[$key], $recent_index, 1); |
214 | if (!empty($recent_slice[0])) |
215 | asearch_setPref($data_dir, $username, $saved_prefkeys[$n], $saved_index, $recent_slice[0]); |
216 | else |
217 | asearch_removePref($data_dir, $username, $saved_prefkeys[$n], $saved_index); |
218 | $n++; |
219 | } |
220 | } |
221 | |
40fbe929 |
222 | /** Write a recent search */ |
6b37252b |
223 | function asearch_write_recent($data_dir, $username, $recent_array) |
224 | { |
225 | global $recent_prefkeys; |
226 | |
227 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
228 | $recent_count = min($recent_max, count($recent_array[$recent_prefkeys[0]])); |
229 | for ($recent_num=0; $recent_num < $recent_count; $recent_num++) { |
230 | foreach ($recent_prefkeys as $key) { |
231 | asearch_setPref($data_dir, $username, $key, $recent_num, $recent_array[$key][$recent_num]); |
232 | } |
233 | } |
234 | for (; $recent_num < $recent_max; $recent_num++) { |
235 | foreach ($recent_prefkeys as $key) { |
236 | asearch_removePref($data_dir, $username, $key, $recent_num); |
237 | } |
238 | } |
239 | } |
240 | |
40fbe929 |
241 | /** Forget a recent search */ |
6b37252b |
242 | function asearch_forget_recent($data_dir, $username, $forget_index) |
243 | { |
244 | global $recent_prefkeys; |
245 | |
246 | $recent_array = asearch_read_recent($data_dir, $username); |
247 | foreach ($recent_prefkeys as $key) { |
248 | array_splice($recent_array[$key], $forget_index, 1); |
249 | } |
250 | asearch_write_recent($data_dir, $username, $recent_array); |
251 | } |
252 | |
40fbe929 |
253 | /** Find a recent search */ |
254 | function asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
255 | { |
256 | global $recent_prefkeys; |
257 | |
258 | $mailbox_string = asearch_serialize($mailbox_array); |
259 | $biop_string = asearch_serialize($biop_array); |
260 | $unop_string = asearch_serialize($unop_array); |
261 | $where_string = asearch_serialize($where_array); |
262 | $what_string = asearch_serialize($what_array); |
263 | $exclude_string = asearch_serialize($exclude_array); |
40fbe929 |
264 | $sub_string = asearch_serialize($sub_array); |
6b37252b |
265 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
266 | for ($recent_num=0; $recent_num<$recent_count; $recent_num++) { |
267 | if (isset($recent_array[$recent_prefkeys[0]][$recent_num])) { |
268 | if ( |
269 | $mailbox_string == $recent_array['asearch_recent_mailbox'][$recent_num] && |
270 | $biop_string == $recent_array['asearch_recent_biop'][$recent_num] && |
271 | $unop_string == $recent_array['asearch_recent_unop'][$recent_num] && |
272 | $where_string == $recent_array['asearch_recent_where'][$recent_num] && |
273 | $what_string == $recent_array['asearch_recent_what'][$recent_num] && |
40fbe929 |
274 | $exclude_string == $recent_array['asearch_recent_exclude'][$recent_num] && |
275 | $sub_string == $recent_array['asearch_recent_sub'][$recent_num] |
6b37252b |
276 | ) |
c2d47d51 |
277 | return $recent_num; |
6b37252b |
278 | } |
279 | } |
c2d47d51 |
280 | return -1; |
6b37252b |
281 | } |
282 | |
40fbe929 |
283 | /** Push a recent search */ |
284 | function asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
285 | { |
286 | global $recent_prefkeys; |
287 | |
288 | $recent_max = getPref($data_dir, $username, 'search_memory', 0); |
289 | if ($recent_max > 0) { |
290 | $recent_array = asearch_read_recent($data_dir, $username); |
40fbe929 |
291 | $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
292 | if ($recent_found >= 0) { // Remove identical recent |
6b37252b |
293 | foreach ($recent_prefkeys as $key) { |
c2d47d51 |
294 | array_splice($recent_array[$key], $recent_found, 1); |
6b37252b |
295 | } |
c2d47d51 |
296 | } |
40fbe929 |
297 | $input = array($where_array, $mailbox_array, $what_array, $biop_array, $unop_array, $exclude_array, $sub_array); |
c2d47d51 |
298 | $i = 0; |
299 | foreach ($recent_prefkeys as $key) { |
300 | array_unshift($recent_array[$key], asearch_serialize($input[$i])); |
301 | $i++; |
302 | } |
303 | asearch_write_recent($data_dir, $username, $recent_array); |
6b37252b |
304 | } |
305 | } |
306 | |
40fbe929 |
307 | /** |
308 | * Edit a recent search |
2d2f8bb8 |
309 | * @global array mailbox_array searched mailboxes |
40fbe929 |
310 | */ |
6b37252b |
311 | function asearch_edit_recent($data_dir, $username, $index) |
312 | { |
40fbe929 |
313 | global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array; |
6b37252b |
314 | |
315 | $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_mailbox', $index)); |
316 | $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_biop', $index)); |
317 | $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_unop', $index)); |
318 | $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_where', $index)); |
319 | $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_what', $index)); |
320 | $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_exclude', $index)); |
40fbe929 |
321 | $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_recent_sub', $index)); |
6b37252b |
322 | } |
323 | |
40fbe929 |
324 | /** Edit the last recent search if the prefs permit it */ |
6b37252b |
325 | function asearch_edit_last($data_dir, $username) |
326 | { |
327 | if (getPref($data_dir, $username, 'search_memory', 0) > 0) |
328 | asearch_edit_recent($data_dir, $username, 0); |
329 | } |
330 | |
40fbe929 |
331 | /** Edit a saved search */ |
6b37252b |
332 | function asearch_edit_saved($data_dir, $username, $index) |
333 | { |
40fbe929 |
334 | global $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array; |
6b37252b |
335 | |
336 | $mailbox_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_mailbox', $index)); |
337 | $biop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_biop', $index)); |
338 | $unop_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_unop', $index)); |
339 | $where_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_where', $index)); |
340 | $what_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_what', $index)); |
341 | $exclude_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_exclude', $index)); |
40fbe929 |
342 | $sub_array = asearch_unserialize(asearch_getPref($data_dir, $username, 'asearch_saved_sub', $index)); |
6b37252b |
343 | } |
344 | |
40fbe929 |
345 | /** Write a saved searches */ |
6b37252b |
346 | function asearch_write_saved($data_dir, $username, $saved_array) |
347 | { |
348 | global $saved_prefkeys; |
349 | |
350 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
351 | for ($saved_num=0; $saved_num < $saved_count; $saved_num++) { |
352 | foreach ($saved_prefkeys as $key) { |
353 | asearch_setPref($data_dir, $username, $key, $saved_num, $saved_array[$key][$saved_num]); |
354 | } |
355 | } |
356 | foreach ($saved_prefkeys as $key) { |
357 | asearch_removePref($data_dir, $username, $key, $saved_count); |
358 | } |
359 | } |
360 | |
40fbe929 |
361 | /** Delete a saved search */ |
6b37252b |
362 | function asearch_delete_saved($data_dir, $username, $saved_index) |
363 | { |
364 | global $saved_prefkeys; |
365 | |
366 | $saved_array = asearch_read_saved($data_dir, $username); |
367 | $asearch_keys = $saved_prefkeys; |
368 | foreach ($asearch_keys as $key) { |
369 | array_splice($saved_array[$key], $saved_index, 1); |
370 | } |
371 | asearch_write_saved($data_dir, $username, $saved_array); |
372 | } |
373 | |
40fbe929 |
374 | /** Translate the input date to imap date to local date display, so the user can know if the date is wrong or illegal */ |
6b37252b |
375 | function asearch_get_date_display($what) |
376 | { |
377 | $what_parts = sqimap_asearch_parse_date($what); |
378 | if (count($what_parts) == 4) { |
379 | if (checkdate($what_parts[2], $what_parts[1], $what_parts[3])) { |
edda50ae |
380 | $what_display = date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3])); |
6b37252b |
381 | /*$what_display = $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3];*/ |
382 | } |
383 | else |
384 | $what_display = _("(Illegal date)"); |
385 | } |
386 | else |
387 | $what_display = _("(Wrong date)"); |
388 | return $what_display; |
389 | } |
390 | |
40fbe929 |
391 | /** Translate the query to rough natural display */ |
392 | function asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
393 | { |
394 | global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options; |
395 | global $imap_asearch_opcodes; |
396 | |
397 | $last_mailbox = $mailbox_array[0]; |
398 | if (empty($last_mailbox)) |
399 | $last_mailbox = 'INBOX'; |
05f5b952 |
400 | $query_display = ''; |
401 | for ($crit_num=0; $crit_num < count($where_array); $crit_num++) { |
402 | if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) { |
403 | $cur_mailbox = $mailbox_array[$crit_num]; |
6b37252b |
404 | if (empty($cur_mailbox)) |
405 | $cur_mailbox = 'INBOX'; |
05f5b952 |
406 | $biop = asearch_nz($biop_array[$crit_num]); |
407 | if (($query_display == '') || ($cur_mailbox != $last_mailbox)) { |
6b37252b |
408 | $mailbox_display = ' <B>' . asearch_get_mailbox_display($cur_mailbox) . '</B>'; |
05f5b952 |
409 | if ($query_display == '') |
6b37252b |
410 | $biop_display = _("In"); |
411 | else |
412 | $biop_display = $imap_asearch_biops_in[$biop]; |
413 | $last_mailbox = $cur_mailbox; |
414 | } |
415 | else { |
416 | $mailbox_display = ''; |
417 | $biop_display = $imap_asearch_biops[$biop]; |
418 | } |
419 | $biop_display = ' <U><I>' . $biop_display . '</I></U>'; |
05f5b952 |
420 | $unop = $unop_array[$crit_num]; |
6b37252b |
421 | $unop_display = $imap_asearch_unops[$unop]; |
05f5b952 |
422 | $where = $where_array[$crit_num]; |
6b37252b |
423 | $where_display = $imap_asearch_options[$where]; |
424 | if ($unop_display != '') |
425 | $where_display = ' <U><I>' . $unop_display . ' ' . $where_display . '</I></U>'; |
426 | else |
427 | $where_display = ' <U><I>' . $where_display . '</I></U>'; |
428 | $what_type = $imap_asearch_opcodes[$where]; |
05f5b952 |
429 | $what = $what_array[$crit_num]; |
430 | if ($what_type) { /* Check opcode parameter */ |
431 | if ($what == '') |
432 | $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)")); |
6b37252b |
433 | else { |
05f5b952 |
434 | if ($what_type == 'adate') |
435 | $what_display = asearch_get_date_display($what); |
6b37252b |
436 | else |
a722a461 |
437 | $what_display = htmlspecialchars($what); |
05f5b952 |
438 | $what_display = ' <B>' . $what_display . '</B>'; |
6b37252b |
439 | } |
6b37252b |
440 | } |
05f5b952 |
441 | else { |
442 | if ($what) |
443 | $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)")); |
444 | else |
445 | $what_display = ''; |
446 | } |
447 | $query_display .= ' ' . $biop_display . $mailbox_display . $where_display . $what_display; |
6b37252b |
448 | } |
449 | } |
05f5b952 |
450 | return $query_display; |
6b37252b |
451 | } |
452 | |
40fbe929 |
453 | /** Handle the alternate row colors */ |
6b37252b |
454 | function asearch_get_row_color($color, $row_num) |
455 | { |
456 | /*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/ |
457 | $color_string = $color[4]; |
458 | if ($GLOBALS['alt_index_colors']) { |
459 | if (($row_num % 2) == 0) { |
460 | if (!isset($color[12])) |
461 | $color[12] = '#EAEAEA'; |
462 | $color_string = $color[12]; |
463 | } |
464 | } |
465 | return $color_string; |
466 | } |
467 | |
40fbe929 |
468 | /** Print a whole query array, recent or saved */ |
6b37252b |
469 | function asearch_print_query_array($query_array, $query_keys, $action_array, $title) |
470 | { |
471 | global $color; |
472 | |
473 | echo "<br>\n"; |
920ec5ec |
474 | echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"'); |
475 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=5')); |
6b37252b |
476 | $main_key = $query_keys[0]; |
477 | $query_count = count($query_array[$main_key]); |
478 | for ($query_num=0, $row_num=0; $query_num<$query_count; $query_num++) { |
479 | if (!empty($query_array[$main_key][$query_num])) { |
480 | echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num)); |
481 | |
482 | unset($search_array); |
483 | foreach ($query_keys as $query_key) { |
484 | $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]); |
485 | } |
486 | $mailbox_array = $search_array[1]; |
487 | $biop_array = $search_array[3]; |
488 | $unop_array = $search_array[4]; |
489 | $where_array = $search_array[0]; |
490 | $what_array = $search_array[2]; |
491 | $exclude_array = $search_array[5]; |
40fbe929 |
492 | $sub_array = $search_array[6]; |
493 | $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
6b37252b |
494 | |
920ec5ec |
495 | echo html_tag('td', $query_num+1, 'right'); |
496 | echo html_tag('td', $query_display, 'center', '', 'width="80%"'); |
6b37252b |
497 | foreach ($action_array as $action => $action_display) { |
498 | echo html_tag('td', '<a href=search.php?submit=' . $action . '&rownum=' . $query_num . '>' . $action_display . '</a>', 'center'); |
499 | } |
500 | |
501 | echo '</tr>' . "\n"; |
502 | $row_num++; |
503 | } |
504 | } |
505 | echo '</table>' . "\n"; |
506 | } |
507 | |
40fbe929 |
508 | /** Print the saved array */ |
6b37252b |
509 | function asearch_print_saved($data_dir, $username) |
510 | { |
511 | global $saved_prefkeys; |
512 | |
513 | $saved_array = asearch_read_saved($data_dir, $username); |
05f5b952 |
514 | if (isset($saved_array[$saved_prefkeys[0]])) { |
515 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
516 | if ($saved_count > 0) { |
517 | $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete")); |
518 | asearch_print_query_array($saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches")); |
519 | } |
6b37252b |
520 | } |
70c4fd84 |
521 | } |
6c8388a9 |
522 | |
40fbe929 |
523 | /** Print the recent array */ |
6b37252b |
524 | function asearch_print_recent($data_dir, $username) |
525 | { |
526 | global $recent_prefkeys; |
527 | |
528 | $recent_array = asearch_read_recent($data_dir, $username); |
05f5b952 |
529 | if (isset($recent_array[$recent_prefkeys[0]])) { |
530 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
531 | $recent_max = min($recent_count, getPref($data_dir, $username, 'search_memory', 0)); |
532 | if ($recent_max > 0) { |
533 | $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget")); |
534 | asearch_print_query_array($recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches")); |
535 | } |
6b37252b |
536 | } |
56e0b3b7 |
537 | } |
538 | |
40fbe929 |
539 | /** Build an <option> statement */ |
920ec5ec |
540 | function asearch_opt($val, $sel, $tit) |
6b37252b |
541 | { |
f8984459 |
542 | return '<option value="' . $val . '"' . ($sel == $val ? ' selected' : '') . '>' . $tit . '</option>' . "\n"; |
6b37252b |
543 | } |
544 | |
40fbe929 |
545 | /** Build a <select> statement from an array */ |
6b37252b |
546 | function asearch_opt_array($var_name, $opt_array, $cur_val) |
547 | { |
548 | $output = '<select name="' . $var_name . '">' . "\n"; |
549 | foreach($opt_array as $val => $display) |
550 | $output .= asearch_opt($val, $cur_val, $display); |
551 | $output .= '</select>' . "\n"; |
552 | return $output; |
553 | } |
554 | |
40fbe929 |
555 | /** Verify that a mailbox exists */ |
920ec5ec |
556 | function asearch_mailbox_exists($mailbox, $boxes) |
557 | { |
558 | foreach ($boxes as $box) { |
559 | if ($box['unformatted'] == $mailbox) |
560 | return TRUE; |
561 | } |
562 | return FALSE; |
563 | } |
564 | |
40fbe929 |
565 | /** Print one form row */ |
566 | function asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
6b37252b |
567 | { |
568 | global $imap_asearch_biops_in, $imap_asearch_unops, $imap_asearch_options; |
569 | global $color; |
570 | |
920ec5ec |
571 | echo html_tag('tr', '', '', $color[4]); |
6b37252b |
572 | |
920ec5ec |
573 | echo html_tag('td', '', 'center'); |
6b37252b |
574 | /* Binary operator */ |
05f5b952 |
575 | if ($row_num) |
576 | echo asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop); |
6b37252b |
577 | else |
578 | echo /*'<input type="hidden" name="biop[0]" value="">' .*/ '<b>' . _("In") . '</b>'; |
579 | echo "</td>\n"; |
580 | |
920ec5ec |
581 | echo html_tag('td', '', 'center'); |
6b37252b |
582 | /* Mailbox list */ |
920ec5ec |
583 | echo '<select name="mailbox[' . $row_num . ']">'; |
584 | if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) |
585 | echo asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . asearch_get_mailbox_display($mailbox)); |
586 | echo asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']'); |
40fbe929 |
587 | echo sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL); |
588 | echo '</select>' . "\n"; |
589 | |
590 | /* Include Subfolders */ |
64c9e87e |
591 | echo _("and subfolders:") . |
592 | addCheckBox('sub[' . $row_num .']', $sub) . '</td>' . "\n"; |
6b37252b |
593 | |
594 | /* Unary operator and Search location */ |
920ec5ec |
595 | echo html_tag('td', |
05f5b952 |
596 | asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop) |
597 | . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where), |
6b37252b |
598 | 'center'); |
599 | |
600 | /* Text input */ |
64c9e87e |
601 | echo html_tag('td', addInput('what['.$row_num.']', $what, '35'), 'center') . "\n"; |
6b37252b |
602 | |
603 | /* Exclude criteria */ |
920ec5ec |
604 | echo html_tag('td', |
c4de3c92 |
605 | _("Exclude Criteria:") . sm_print_r($exclude) . |
606 | addCheckBox('exclude['.$row_num.']', $exclude), 'center', '') . "\n"; |
6b37252b |
607 | |
608 | echo "</tr>\n"; |
609 | } |
610 | |
40fbe929 |
611 | /** Print the search form */ |
612 | function asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
613 | { |
614 | global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html; |
615 | global $color; |
616 | |
617 | /* Search Form */ |
5a383256 |
618 | echo "<br>\n"; |
6b37252b |
619 | echo '<form action="search.php" name="form_asearch">' . "\n"; |
620 | |
920ec5ec |
621 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
622 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5')); |
edda50ae |
623 | $row_count = count($where_array); |
6b37252b |
624 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
edda50ae |
625 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
6b37252b |
626 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
627 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
edda50ae |
628 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
6b37252b |
629 | $what = asearch_nz($what_array[$row_num]); |
630 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
40fbe929 |
631 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
632 | asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
6b37252b |
633 | } |
634 | echo '</table>' . "\n"; |
635 | |
636 | /* Submit buttons */ |
920ec5ec |
637 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
6b37252b |
638 | echo html_tag('tr', |
639 | html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n" |
640 | . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n" |
641 | . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n" |
642 | . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n" |
643 | ); |
644 | echo '</table>' . "\n"; |
645 | echo '</form>' . "\n"; |
646 | } |
647 | |
40fbe929 |
648 | /** Print the $msgs messages from $mailbox mailbox */ |
c2d47d51 |
649 | function asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, $cnt, $sort, $color, $where, $what) |
6b37252b |
650 | { |
cf6cb8b1 |
651 | if ($cnt > 0) { |
c2d47d51 |
652 | global $allow_server_sort, $allow_thread_sort, $thread_sort_messages; |
653 | |
654 | $thread_sort_messages = 0; |
655 | if ($allow_thread_sort) { |
656 | global $data_dir, $username; |
657 | $thread_sort_messages = getPref($data_dir, $username, 'thread_' . $mailbox); |
658 | $msort = $msgs; |
659 | $real_sort = 6; |
660 | } |
661 | elseif ($allow_server_sort) { |
662 | $msort = $msgs; |
663 | $real_sort = 6; |
664 | } |
665 | else { |
666 | $msort = calc_msort($msgs, $sort); |
667 | $real_sort = $sort; |
668 | } |
669 | $mailbox_display = asearch_get_mailbox_display($mailbox); |
70f1b6b5 |
670 | |
6b37252b |
671 | $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt); |
f8984459 |
672 | $paginator_str = '<b><big>' . _("Folder:") . ' '. $mailbox_display . ' </big></b>'; |
70f1b6b5 |
673 | |
313fd1f4 |
674 | echo '<br><table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
0fd2f513 |
675 | |
6b37252b |
676 | echo '<tr><td>'; |
f43704ce |
677 | mail_message_listing_beginning($imapConnection, NULL, $mailbox, $real_sort, $msg_cnt_str, $paginator_str, 1, 1); |
6b37252b |
678 | echo '</td></tr>'; |
70f1b6b5 |
679 | |
6b37252b |
680 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
70f1b6b5 |
681 | |
6b37252b |
682 | echo '<tr><td>'; |
683 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
684 | echo ' <tr><td>'; |
70f1b6b5 |
685 | |
6b37252b |
686 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
687 | echo ' <tr><td>'; |
c2d47d51 |
688 | printHeader($mailbox, $sort, $color, !$thread_sort_messages); |
689 | displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $real_sort, $color, $cnt, $where, $what); |
6b37252b |
690 | echo ' </td></tr>'; |
691 | echo ' </table>'; |
692 | echo ' </td></tr>'; |
693 | echo ' </table>'; |
694 | mail_message_listing_end($cnt, '', $msg_cnt_str, $color); |
695 | echo '</td></tr>'; |
70f1b6b5 |
696 | |
6b37252b |
697 | echo '</table>'; |
698 | } |
59a623e6 |
699 | } |
700 | |
40fbe929 |
701 | /** |
702 | * @param array $boxes mailboxes array (reference) |
703 | * @return array selectable unformatted mailboxes names |
704 | */ |
705 | function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes) |
706 | { |
707 | $mboxes_array = array(); |
708 | $boxcount = count($boxes); |
709 | for ($boxnum=0; $boxnum<$boxcount; $boxnum++) { |
710 | if (!in_array('noselect', $boxes[$boxnum]['flags'])) |
711 | $mboxes_array[] = $boxes[$boxnum]['unformatted']; |
712 | } |
713 | return $mboxes_array; |
714 | } |
715 | |
0d672ac0 |
716 | /* ------------------------ main ------------------------ */ |
6b37252b |
717 | /* get globals we may need */ |
6b37252b |
718 | sqgetGlobalVar('username', $username, SQ_SESSION); |
719 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
bfc5b989 |
720 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); /* we really need this? */ |
e5cbf2f9 |
721 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); /* do we really need this? */ |
c1cb7ba4 |
722 | |
40fbe929 |
723 | $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_biop', 'asearch_recent_unop', 'asearch_recent_exclude', 'asearch_recent_sub'); |
724 | $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_biop', 'asearch_saved_unop', 'asearch_saved_exclude', 'asearch_saved_sub'); |
725 | /*$asearch_keys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/ |
6b37252b |
726 | |
727 | $search_button_html = _("Search"); |
728 | $search_button_text = asearch_unhtmlentities($search_button_html); |
729 | $add_criteria_button_html = _("Add New Criteria"); |
730 | $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html); |
34a85c56 |
731 | $del_excluded_button_html = _("Remove Excluded Criteria"); |
6b37252b |
732 | $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html); |
34a85c56 |
733 | $del_all_button_html = _("Remove All Criteria"); |
6b37252b |
734 | $del_all_button_text = asearch_unhtmlentities($del_all_button_html); |
735 | |
736 | $imap_asearch_options = array( |
737 | /* <message set>, */ |
738 | /*'ALL' is binary operator */ |
739 | 'ANSWERED' => _("Answered"), |
740 | 'BCC' => _("Bcc"), |
741 | 'BEFORE' => _("Before"), |
742 | 'BODY' => _("Message Body"), |
743 | 'CC' => _("CC"), |
744 | 'DELETED' => _("Deleted"), |
745 | 'DRAFT' => _("Draft"), |
746 | 'FLAGGED' => _("Flagged"), |
747 | 'FROM' => _("Sent By"), |
748 | 'HEADER' => _("Header Field"), |
749 | 'KEYWORD' => _("Keyword"), |
750 | 'LARGER' => _("Larger Than"), |
751 | 'NEW' => _("New"), |
752 | /*'NOT' is unary operator */ |
753 | 'OLD' => _("Old"), |
754 | 'ON' => _("On"), |
755 | /*'OR' is binary operator */ |
756 | 'RECENT' => _("Recent"), |
757 | 'SEEN' => _("Seen"), |
758 | 'SENTBEFORE' => _("Sent Before"), |
759 | 'SENTON' => _("Sent On"), |
760 | 'SENTSINCE' => _("Sent Since"), |
761 | 'SINCE' => _("Since"), |
762 | 'SMALLER' => _("Smaller Than"), |
763 | 'SUBJECT' => _("Subject Contains"), |
764 | 'TEXT' => _("Header and Body"), |
765 | 'TO' => _("Sent To"), |
766 | /*'UID' => 'anum',*/ |
767 | /*'UNANSWERED' => '', |
768 | 'UNDELETED' => '', |
769 | 'UNDRAFT' => '', |
770 | 'UNFLAGGED' => '', |
771 | 'UNKEYWORD' => _("Unkeyword"), |
772 | 'UNSEEN' => _("Unseen"),*/ |
773 | ); |
774 | uasort($imap_asearch_options, 'asearch_unhtml_strcoll'); |
775 | |
776 | $imap_asearch_unops = array( |
777 | '' => '', |
778 | 'NOT' => _("Not") |
779 | ); |
780 | |
781 | $imap_asearch_biops_in = array( |
782 | 'ALL' => _("And In"), |
783 | 'OR' => _("Or In") |
784 | ); |
785 | |
786 | $imap_asearch_biops = array( |
787 | 'ALL' => _("And"), |
788 | 'OR' => _("Or") |
789 | ); |
790 | |
2d2f8bb8 |
791 | /** How we did enter the form |
792 | * - unset : Enter key, or called from outside (eg read_body) |
793 | * - $search_button_text : Search button |
794 | * - 'Search_no_update' : Search but don't update recent |
795 | * - 'Search_last' : Same as no_update but reload and search last |
796 | * - 'Search_silent' : Same as no_update but only display results |
797 | * - $add_criteria_button_text : Add New Criteria button |
798 | * - $del_excluded_button_text : Remove Excluded Criteria button |
799 | * - $del_all_button_text : Remove All Criteria button |
800 | * - 'save_recent' |
801 | * - 'search_recent' |
802 | * - 'forget_recent' |
803 | * - 'edit_saved' |
804 | * - 'search_saved' |
805 | * - 'delete_saved' |
806 | * @global string $submit |
807 | */ |
6b37252b |
808 | if (isset($_GET['submit'])) |
809 | $submit = strip_tags($_GET['submit']); |
810 | |
2d2f8bb8 |
811 | /** Searched mailboxes |
812 | * @global array $mailbox_array |
813 | */ |
6b37252b |
814 | if (isset($_GET['mailbox'])) { |
815 | $mailbox_array = $_GET['mailbox']; |
816 | if (!is_array($mailbox_array)) |
817 | $mailbox_array = array($mailbox_array); |
56e0b3b7 |
818 | } |
6b37252b |
819 | else |
820 | $mailbox_array = array(); |
821 | |
2d2f8bb8 |
822 | /** Binary operators |
823 | * @global array $biop_array |
824 | */ |
6b37252b |
825 | if (isset($_GET['biop'])) { |
826 | $biop_array = $_GET['biop']; |
827 | if (!is_array($biop_array)) |
828 | $biop_array = array($biop_array); |
c1cb7ba4 |
829 | } |
6b37252b |
830 | else |
831 | $biop_array = array(); |
c1cb7ba4 |
832 | |
2d2f8bb8 |
833 | /** Unary operators |
834 | * @global array $unop_array |
835 | */ |
6b37252b |
836 | if (isset($_GET['unop'])) { |
837 | $unop_array = $_GET['unop']; |
838 | if (!is_array($unop_array)) |
839 | $unop_array = array($unop_array); |
548a552a |
840 | } |
6b37252b |
841 | else |
842 | $unop_array = array(); |
843 | |
2d2f8bb8 |
844 | /** Where to search |
845 | * @global array $where_array |
846 | */ |
6b37252b |
847 | if (isset($_GET['where'])) { |
848 | $where_array = $_GET['where']; |
849 | if (!is_array($where_array)) |
850 | $where_array = array($where_array); |
851 | } |
852 | else |
853 | $where_array = array(); |
854 | |
2d2f8bb8 |
855 | /** What to search |
856 | * @global array $what_array |
857 | */ |
6b37252b |
858 | if (isset($_GET['what'])) { |
859 | $what_array = $_GET['what']; |
860 | if (!is_array($what_array)) |
861 | $what_array = array($what_array); |
862 | } |
863 | else |
864 | $what_array = array(); |
865 | |
2d2f8bb8 |
866 | /** Whether to exclude this criteria from search |
867 | * @global array $exclude_array |
868 | */ |
6b37252b |
869 | if (isset($_GET['exclude'])) |
870 | $exclude_array = $_GET['exclude']; |
871 | else |
872 | $exclude_array = array(); |
873 | |
2d2f8bb8 |
874 | /** Search within subfolders |
875 | * @global array $sub_array |
876 | */ |
40fbe929 |
877 | if (isset($_GET['sub'])) |
878 | $sub_array = $_GET['sub']; |
879 | else |
880 | $sub_array = array(); |
881 | |
2d2f8bb8 |
882 | /** Row number used by recent and saved stuff |
883 | */ |
c2d47d51 |
884 | if (isset($_GET['rownum'])) |
6b37252b |
885 | $submit_rownum = strip_tags($_GET['rownum']); |
c2d47d51 |
886 | |
2d2f8bb8 |
887 | /** Change global sort |
888 | */ |
c2d47d51 |
889 | if (sqgetGlobalVar('newsort', $newsort, SQ_GET)) { |
890 | setPref($data_dir, $username, 'sort', $newsort); |
891 | $sort = $newsort; |
892 | sqsession_register($sort, 'sort'); |
893 | asearch_edit_last($data_dir, $username); |
894 | } |
895 | |
2d2f8bb8 |
896 | /** Change mailbox threading |
897 | */ |
c2d47d51 |
898 | if (sqgetGlobalVar('set_thread', $set_thread, SQ_GET)) { |
899 | setPref($data_dir, $username, 'thread_' . $mailbox_array[0], ($set_thread == 1) ? 1 : 0 ); |
900 | asearch_edit_last($data_dir, $username); |
56e0b3b7 |
901 | } |
6b37252b |
902 | |
903 | /* end of get globals */ |
904 | |
40fbe929 |
905 | /** If TRUE, do not show search interface |
906 | * @global bool $search_silent |
907 | */ |
6b37252b |
908 | $search_silent = FALSE; /* Default is normal behaviour */ |
909 | |
910 | /* See how the page was called and fire off correct function */ |
911 | if ((!isset($submit) || empty($submit)) && !empty($where_array)) { |
912 | /* This happens when the Enter key is used or called from outside */ |
913 | $submit = $search_button_text; |
914 | if (count($where_array) != count($unop_array)) /* Hack needed to handle coming back from read_body et als */ |
915 | asearch_edit_last($data_dir, $username); |
56e0b3b7 |
916 | } |
6b37252b |
917 | |
918 | if (!isset($submit)) { |
919 | $submit = ''; |
56e0b3b7 |
920 | } |
6b37252b |
921 | else { |
922 | switch ($submit) { |
923 | case $search_button_text: |
05f5b952 |
924 | if (asearch_check_query($where_array, $what_array, $exclude_array) == '') |
40fbe929 |
925 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
6b37252b |
926 | break; |
927 | case 'Search_silent': |
928 | $search_silent = TRUE; |
929 | /*nobreak;*/ |
930 | case 'Search_no_update': |
931 | $submit = $search_button_text; |
932 | break; |
933 | case $del_excluded_button_text: |
934 | $delarray = array_keys($exclude_array); |
935 | while (!empty($delarray)) { |
936 | $delrow = array_pop($delarray); |
937 | array_splice($mailbox_array, $delrow, 1); |
938 | array_splice($biop_array, $delrow, 1); |
939 | array_splice($unop_array, $delrow, 1); |
940 | array_splice($where_array, $delrow, 1); |
941 | array_splice($what_array, $delrow, 1); |
942 | /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */ |
40fbe929 |
943 | array_splice($sub_array, $delrow, 1); |
6b37252b |
944 | } |
945 | $exclude_array = array(); |
946 | break; |
947 | case $del_all_button_text: |
948 | $mailbox_array = array(); |
949 | $biop_array = array(); |
950 | $unop_array = array(); |
951 | $where_array = array(); |
952 | $what_array = array(); |
953 | $exclude_array = array(); |
40fbe929 |
954 | $sub_array = array(); |
6b37252b |
955 | break; |
956 | case 'save_recent': |
957 | asearch_save_recent($data_dir, $username, $submit_rownum); |
958 | break; |
959 | case 'search_recent': |
960 | $submit = $search_button_text; |
c2d47d51 |
961 | asearch_edit_recent($data_dir, $username, $submit_rownum); |
40fbe929 |
962 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
963 | break; |
6b37252b |
964 | case 'edit_recent': /* no link to do this, yet */ |
965 | asearch_edit_recent($data_dir, $username, $submit_rownum); |
966 | break; |
967 | case 'forget_recent': |
968 | asearch_forget_recent($data_dir, $username, $submit_rownum); |
969 | break; |
970 | case 'search_saved': |
971 | $submit = $search_button_text; |
c2d47d51 |
972 | asearch_edit_saved($data_dir, $username, $submit_rownum); |
40fbe929 |
973 | asearch_push_recent($data_dir, $username, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
974 | break; |
6b37252b |
975 | case 'edit_saved': |
976 | asearch_edit_saved($data_dir, $username, $submit_rownum); |
977 | break; |
978 | case 'delete_saved': |
979 | asearch_delete_saved($data_dir, $username, $submit_rownum); |
980 | break; |
981 | } |
56e0b3b7 |
982 | } |
23a9084b |
983 | |
6b37252b |
984 | /* open IMAP connection */ |
985 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
986 | /* get mailbox names once here */ |
987 | $boxes = sqimap_mailbox_list($imapConnection); |
99f3175e |
988 | /* ensure we have a valid default mailbox name */ |
edda50ae |
989 | $mailbox = asearch_nz($mailbox_array[0]); |
990 | if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?) |
991 | $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;) |
99f3175e |
992 | |
6b37252b |
993 | if (isset($composenew) && $composenew) { |
994 | $comp_uri = "../src/compose.php?mailbox=" . urlencode($mailbox) . |
995 | "&session=$composesession&attachedmessages=true&"; |
996 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
56e0b3b7 |
997 | } |
6b37252b |
998 | else |
999 | displayPageHeader($color, $mailbox); |
184ef883 |
1000 | |
6b37252b |
1001 | do_hook('search_before_form'); |
d81e351b |
1002 | |
6b37252b |
1003 | if (!$search_silent) { |
920ec5ec |
1004 | echo html_tag('table', |
1005 | html_tag('tr', "\n" . |
1006 | html_tag('td', asearch_get_title_display($color, _("Search")), 'center', $color[0]) |
6b37252b |
1007 | ) , |
1008 | '', '', 'width="100%"') . "\n"; |
1009 | asearch_print_saved($data_dir, $username); |
1010 | asearch_print_recent($data_dir, $username); |
edda50ae |
1011 | if (empty($where_array)) { |
40fbe929 |
1012 | global $sent_folder; |
1013 | |
edda50ae |
1014 | $mailbox_array[0] = $mailbox; |
1015 | $biop_array[0] = ''; |
1016 | $unop_array[0] = ''; |
40fbe929 |
1017 | if ($mailbox == $sent_folder) |
1018 | $where_array[0] = 'TO'; |
1019 | else |
1020 | $where_array[0] = 'FROM'; |
edda50ae |
1021 | $what_array[0] = ''; |
1022 | $exclude_array[0] = ''; |
40fbe929 |
1023 | $sub_array[0] = ''; |
edda50ae |
1024 | } |
1025 | if ($submit == $add_criteria_button_text) { |
1026 | $last_index = max(count($where_array) - 1, 0); |
1027 | $mailbox_array[] = asearch_nz($mailbox_array[$last_index]); |
1028 | $biop_array[] = asearch_nz($biop_array[$last_index]); |
1029 | $unop_array[] = asearch_nz($unop_array[$last_index]); |
1030 | $where_array[] = asearch_nz($where_array[$last_index]); |
1031 | $what_array[] = asearch_nz($what_array[$last_index]); |
1032 | $exclude_array[] = asearch_nz($exclude_array[$last_index]); |
40fbe929 |
1033 | $sub_array[] = asearch_nz($sub_array[$last_index]); |
edda50ae |
1034 | } |
40fbe929 |
1035 | asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
6b37252b |
1036 | } |
1037 | |
d81e351b |
1038 | /********************************************************************* |
1039 | * Check to see if we can use cache or not. Currently the only time * |
1040 | * when you will not use it is when a link on the left hand frame is * |
1041 | * used. Also check to make sure we actually have the array in the * |
1042 | * registered session data. :) * |
1043 | *********************************************************************/ |
edda50ae |
1044 | if (!isset($use_mailbox_cache)) |
d81e351b |
1045 | $use_mailbox_cache = 0; |
d81e351b |
1046 | |
88cb1b4d |
1047 | do_hook('search_after_form'); |
56e0b3b7 |
1048 | |
6b37252b |
1049 | if ($submit == $search_button_text) { |
920ec5ec |
1050 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
1051 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5])); |
40fbe929 |
1052 | echo html_tag('tr', html_tag('td', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array), 'center', $color[4])); |
313fd1f4 |
1053 | echo '</table>' . "\n"; |
05f5b952 |
1054 | |
2303858b |
1055 | flush(); |
1056 | |
05f5b952 |
1057 | $query_error = asearch_check_query($where_array, $what_array, $exclude_array); |
6b37252b |
1058 | if ($query_error != '') |
920ec5ec |
1059 | echo '<br>' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n"; |
6b37252b |
1060 | else { |
c2d47d51 |
1061 | |
40fbe929 |
1062 | // Disable thread sort for now if there is more than one mailbox or at least one 'All Folders' |
c2d47d51 |
1063 | global $allow_thread_sort; |
1064 | $old_allow_thread_sort = $allow_thread_sort; |
40fbe929 |
1065 | $allow_thread_sort = ((count(array_unique($mailbox_array)) <= 1) && (!in_array('All Folders', $mailbox_array))); |
6b37252b |
1066 | |
40fbe929 |
1067 | $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes); |
1068 | $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array); |
6b37252b |
1069 | if (empty($mboxes_msgs)) |
920ec5ec |
1070 | echo '<br>' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n"; |
6b37252b |
1071 | else { |
1072 | foreach($mboxes_msgs as $mailbox => $msgs) { |
1073 | sqimap_mailbox_select($imapConnection, $mailbox); |
1074 | $msgs = fillMessageArray($imapConnection, $msgs, count($msgs)); |
1075 | /* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */ |
1076 | /* $where = asearch_serialize($where_array); |
1077 | $what = asearch_serialize($what_array);*/ |
1078 | $where = $where_array[0]; |
1079 | $what = $what_array[0]; |
c2d47d51 |
1080 | asearch_print_mailbox_msgs($imapConnection, $mailbox, $msgs, count($msgs), $sort, $color, urlencode($where), urlencode($what)); |
6b37252b |
1081 | } |
1082 | } |
1083 | |
c2d47d51 |
1084 | $allow_thread_sort = $old_allow_thread_sort; // Restore thread sort |
59a623e6 |
1085 | } |
56e0b3b7 |
1086 | } |
1087 | |
70c4fd84 |
1088 | do_hook('search_bottom'); |
6b37252b |
1089 | sqimap_logout($imapConnection); |
dcc1cc82 |
1090 | echo '</body></html>'; |
99d2a184 |
1091 | |
dcc1cc82 |
1092 | ?> |