c61bb006 |
1 | <?php |
245a6892 |
2 | |
35586184 |
3 | /** |
134e4174 |
4 | * search.php |
5 | * |
134e4174 |
6 | * IMAP search page |
7 | * |
8 | * Subfolder search idea from Patch #806075 by Thomas Pohl xraven at users.sourceforge.net. Thanks Thomas! |
9 | * |
4b4abf93 |
10 | * @author Alex Lemaresquier - Brainstorm <alex at brainstorm.fr> |
47ccfad4 |
11 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
134e4174 |
13 | * @version $Id$ |
14 | * @package squirrelmail |
3f294f60 |
15 | * @subpackage search |
134e4174 |
16 | * @link http://www.ietf.org/rfc/rfc3501.txt |
134e4174 |
17 | */ |
2d367c68 |
18 | |
30967a1e |
19 | /** |
202bcbcc |
20 | * Include the SquirrelMail initialization file. |
134e4174 |
21 | */ |
202bcbcc |
22 | require('../include/init.php'); |
86725763 |
23 | |
7d60bda5 |
24 | /** SquirrelMail required files. |
134e4174 |
25 | */ |
202bcbcc |
26 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
27 | require_once(SM_PATH . 'functions/imap_messages.php'); |
28 | require_once(SM_PATH . 'functions/imap_general.php'); |
29 | require_once(SM_PATH . 'functions/mime.php'); |
30 | require_once(SM_PATH . 'functions/mailbox_display.php'); //getButton() |
31 | require_once(SM_PATH . 'functions/forms.php'); |
32 | require_once(SM_PATH . 'functions/date.php'); |
c61bb006 |
33 | |
7d60bda5 |
34 | /** Prefs array ordinals. Must match $recent_prefkeys and $saved_prefkeys |
134e4174 |
35 | */ |
7d60bda5 |
36 | define('ASEARCH_WHERE', 0); |
37 | define('ASEARCH_MAILBOX', 1); |
38 | define('ASEARCH_WHAT', 2); |
39 | define('ASEARCH_UNOP', 3); |
40 | define('ASEARCH_BIOP', 4); |
41 | define('ASEARCH_EXCLUDE', 5); |
42 | define('ASEARCH_SUB', 6); |
5b6abe97 |
43 | define('ASEARCH_MAX', 7); |
44 | |
45 | /** Name of session var |
134e4174 |
46 | */ |
5b6abe97 |
47 | define('ASEARCH_CRITERIA', 'criteria'); |
7d60bda5 |
48 | |
49 | /** Builds a href with params |
134e4174 |
50 | * @param string $params optional parameters to GET |
51 | */ |
7d60bda5 |
52 | function asearch_get_href($params = '') |
53 | { |
8cc8ec79 |
54 | $href = 'search.php'; |
55 | if ($params != '') |
56 | $href .= '?' . $params; |
57 | return $href; |
7d60bda5 |
58 | } |
59 | |
60 | /** Builds a [link] |
134e4174 |
61 | * @param string $href (reference) |
62 | * @param string $text |
63 | * @param string $title |
64 | */ |
94375458 |
65 | function asearch_get_link(&$href, $text, $title = '') |
7d60bda5 |
66 | { |
8cc8ec79 |
67 | if ($title != '') |
68 | $title = ' title="' . $title . '"'; |
69 | return '<a href="' . $href . '"' . $title . '>' . $text . '</a>'; |
7d60bda5 |
70 | } |
71 | |
72 | /** Builds a toggle [link] |
134e4174 |
73 | * @param integer $value |
74 | * @param string $action |
75 | * @param array $text_array |
76 | * @param array $title_array |
77 | */ |
94375458 |
78 | function asearch_get_toggle_link($value, $action, $text_array, $title_array = array()) |
7d60bda5 |
79 | { |
aef9ca1e |
80 | $asearch_nz=asearch_nz($title_array[$value]); |
81 | $asearch_get_href=asearch_get_href($action . '=' . (int)$value); |
82 | return asearch_get_link($asearch_get_href, $text_array[$value], $asearch_nz); |
7d60bda5 |
83 | } |
84 | |
40fbe929 |
85 | /** |
134e4174 |
86 | * @param string $a |
87 | * @param string $b |
88 | * @return bool strcoll()-like result |
89 | */ |
6b37252b |
90 | function asearch_unhtml_strcoll($a, $b) |
91 | { |
8cc8ec79 |
92 | return strcoll(asearch_unhtmlentities($a), asearch_unhtmlentities($b)); |
6b37252b |
93 | } |
40fbe929 |
94 | |
91c27aee |
95 | |
40fbe929 |
96 | /** |
134e4174 |
97 | * @param string $mailbox mailbox name utf7 encoded inc. special case INBOX |
98 | * @return string mailbox name ready to display (utf7 decoded or localized INBOX) |
99 | */ |
6b37252b |
100 | function imap_get_mailbox_display($mailbox) |
101 | { |
8cc8ec79 |
102 | if (strtoupper($mailbox) == 'INBOX') |
103 | return _("INBOX"); |
104 | return imap_utf7_decode_local($mailbox); |
6b37252b |
105 | } |
56e0b3b7 |
106 | |
40fbe929 |
107 | /** |
134e4174 |
108 | * @param string $mailbox mailbox name or special case 'All Folders' |
109 | * @return string mailbox name ready to display (utf7 decoded or localized 'All Folders') |
110 | */ |
6b37252b |
111 | function asearch_get_mailbox_display($mailbox) |
112 | { |
8cc8ec79 |
113 | if ($mailbox == 'All Folders') |
114 | return _("All Folders"); |
115 | return imap_get_mailbox_display($mailbox); |
6b37252b |
116 | } |
0b97a708 |
117 | |
40fbe929 |
118 | /** |
134e4174 |
119 | * @param array $color color array |
120 | * @param string $txt text to display |
121 | * @return string title ready to display |
122 | */ |
7d60bda5 |
123 | function asearch_get_title_display(&$color, $txt) |
6b37252b |
124 | { |
8cc8ec79 |
125 | return '<b><big>' . $txt . '</big></b>'; |
6b37252b |
126 | } |
40fbe929 |
127 | /** |
134e4174 |
128 | * @param array $color color array |
129 | * @param string $txt text to display |
130 | * @return string error text ready to display |
131 | */ |
7d60bda5 |
132 | function asearch_get_error_display(&$color, $txt) |
6b37252b |
133 | { |
8cc8ec79 |
134 | return '<font color="' . $color[2] . '">' . '<b><big>' . $txt . '</big></b></font>'; |
0b97a708 |
135 | } |
6b37252b |
136 | |
40fbe929 |
137 | /** |
134e4174 |
138 | * @param array $input_array array to serialize |
139 | * @return string a string containing a byte-stream representation of value that can be stored anywhere |
140 | */ |
7d60bda5 |
141 | function asearch_serialize(&$input_array) |
6b37252b |
142 | { |
8cc8ec79 |
143 | global $search_advanced; |
144 | if ($search_advanced) |
145 | return serialize($input_array); |
146 | return $input_array[0]; |
0b97a708 |
147 | } |
6b37252b |
148 | |
40fbe929 |
149 | /** |
134e4174 |
150 | * @param string $input_string string to unserialize |
151 | * @return array |
152 | */ |
6b37252b |
153 | function asearch_unserialize($input_string) |
154 | { |
8cc8ec79 |
155 | global $search_advanced; |
156 | if ($search_advanced) |
157 | return unserialize($input_string); |
158 | return array($input_string); |
0b97a708 |
159 | } |
6b37252b |
160 | |
40fbe929 |
161 | /** |
134e4174 |
162 | * @param string $key the pref key |
163 | * @param integer $index the pref key index |
164 | * @param string $default default value |
165 | * @return string pref value |
166 | */ |
7d60bda5 |
167 | function asearch_getPref(&$key, $index, $default = '') |
6b37252b |
168 | { |
8cc8ec79 |
169 | global $data_dir, $username, $search_advanced; |
170 | return getPref($data_dir, $username, $key . ($index + !$search_advanced), $default); |
0b97a708 |
171 | } |
6b37252b |
172 | |
40fbe929 |
173 | /** |
134e4174 |
174 | * @param string $key the pref key |
175 | * @param integer $index the pref key index |
176 | * @param string $value pref value to set |
177 | * @return bool status |
178 | */ |
7d60bda5 |
179 | function asearch_setPref(&$key, $index, $value) |
6b37252b |
180 | { |
8cc8ec79 |
181 | global $data_dir, $username, $search_advanced; |
182 | return setPref($data_dir, $username, $key . ($index + !$search_advanced), $value); |
0b97a708 |
183 | } |
6b37252b |
184 | |
40fbe929 |
185 | /** |
134e4174 |
186 | * @param string $key the pref key |
187 | * @param integer $index the pref key index |
188 | * @return bool status |
189 | */ |
7d60bda5 |
190 | function asearch_removePref(&$key, $index) |
6b37252b |
191 | { |
8cc8ec79 |
192 | global $data_dir, $username, $search_advanced; |
193 | return removePref($data_dir, $username, $key . ($index + !$search_advanced)); |
0b97a708 |
194 | } |
0b97a708 |
195 | |
7d60bda5 |
196 | /** Sanity checks, done before running the imap command and before calling push_recent |
134e4174 |
197 | */ |
7d60bda5 |
198 | function asearch_check_query(&$where_array, &$what_array, &$exclude_array) |
6b37252b |
199 | { |
8cc8ec79 |
200 | global $imap_asearch_opcodes; |
05f5b952 |
201 | |
8cc8ec79 |
202 | if (empty($where_array)) |
203 | return _("Please enter something to search for"); |
204 | if (count($exclude_array) == count($where_array)) |
205 | return _("There must be at least one criteria to search for"); |
206 | for ($crit_num = 0; $crit_num < count($where_array); $crit_num++) { |
207 | $where = $where_array[$crit_num]; |
208 | $what = $what_array[$crit_num]; |
209 | if (!(($what == '') ^ ($imap_asearch_opcodes[$where] != ''))) |
210 | return _("Error in criteria argument"); |
211 | } |
212 | return ''; |
56e0b3b7 |
213 | } |
214 | |
7d60bda5 |
215 | /** Read the recent searches from the prefs |
134e4174 |
216 | */ |
7d60bda5 |
217 | function asearch_read_recent() |
6b37252b |
218 | { |
8cc8ec79 |
219 | global $recent_prefkeys, $search_memory; |
6b37252b |
220 | |
8cc8ec79 |
221 | $recent_array = array(); |
222 | $recent_num = 0; |
223 | for ($pref_num = 0; $pref_num < $search_memory; $pref_num++) { |
224 | foreach ($recent_prefkeys as $prefkey) { |
225 | $pref = asearch_getPref($prefkey, $pref_num); |
134e4174 |
226 | /* if (!empty($pref))*/ |
8cc8ec79 |
227 | $recent_array[$prefkey][$recent_num] = $pref; |
228 | } |
229 | if (empty($recent_array[$recent_prefkeys[0]][$recent_num])) { |
230 | foreach ($recent_prefkeys as $key) { |
231 | array_pop($recent_array[$key]); |
232 | } |
134e4174 |
233 | // break; //Disabled to support old search code broken prefs |
8cc8ec79 |
234 | } |
235 | else |
236 | $recent_num++; |
237 | } |
238 | return $recent_array; |
56e0b3b7 |
239 | } |
23a9084b |
240 | |
7d60bda5 |
241 | /** Read the saved searches from the prefs |
134e4174 |
242 | */ |
7d60bda5 |
243 | function asearch_read_saved() |
6b37252b |
244 | { |
8cc8ec79 |
245 | global $saved_prefkeys; |
246 | |
247 | $saved_array = array(); |
248 | $saved_key = $saved_prefkeys[0]; |
249 | for ($saved_count = 0; ; $saved_count++) { |
250 | $pref = asearch_getPref($saved_key, $saved_count); |
251 | if (empty($pref)) |
252 | break; |
253 | } |
254 | for ($saved_num = 0; $saved_num < $saved_count; $saved_num++) { |
255 | foreach ($saved_prefkeys as $key) { |
256 | $saved_array[$key][$saved_num] = asearch_getPref($key, $saved_num); |
257 | } |
258 | } |
259 | return $saved_array; |
6b37252b |
260 | } |
261 | |
7d60bda5 |
262 | /** Save a recent search to the prefs |
134e4174 |
263 | */ |
7d60bda5 |
264 | function asearch_save_recent($recent_index) |
6b37252b |
265 | { |
8cc8ec79 |
266 | global $recent_prefkeys, $saved_prefkeys; |
267 | |
268 | $saved_array = asearch_read_saved(); |
269 | $saved_index = count($saved_array[$saved_prefkeys[0]]); |
270 | $recent_array = asearch_read_recent(); |
271 | $n = 0; |
272 | foreach ($recent_prefkeys as $key) { |
273 | $recent_slice = array_slice($recent_array[$key], $recent_index, 1); |
274 | if (!empty($recent_slice[0])) |
275 | asearch_setPref($saved_prefkeys[$n], $saved_index, $recent_slice[0]); |
276 | else |
277 | asearch_removePref($saved_prefkeys[$n], $saved_index); |
278 | $n++; |
279 | } |
6b37252b |
280 | } |
281 | |
7d60bda5 |
282 | /** Write a recent search to prefs |
134e4174 |
283 | */ |
7d60bda5 |
284 | function asearch_write_recent(&$recent_array) |
6b37252b |
285 | { |
8cc8ec79 |
286 | global $recent_prefkeys, $search_memory; |
6b37252b |
287 | |
8cc8ec79 |
288 | $recent_count = min($search_memory, count($recent_array[$recent_prefkeys[0]])); |
289 | for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) { |
290 | foreach ($recent_prefkeys as $key) { |
291 | asearch_setPref($key, $recent_num, $recent_array[$key][$recent_num]); |
292 | } |
293 | } |
294 | for (; $recent_num < $search_memory; $recent_num++) { |
295 | foreach ($recent_prefkeys as $key) { |
296 | asearch_removePref($key, $recent_num); |
297 | } |
298 | } |
6b37252b |
299 | } |
300 | |
7d60bda5 |
301 | /** Remove a recent search from prefs |
134e4174 |
302 | */ |
7d60bda5 |
303 | function asearch_forget_recent($forget_index) |
6b37252b |
304 | { |
8cc8ec79 |
305 | global $recent_prefkeys; |
6b37252b |
306 | |
8cc8ec79 |
307 | $recent_array = asearch_read_recent(); |
308 | foreach ($recent_prefkeys as $key) { |
309 | array_splice($recent_array[$key], $forget_index, 1); |
310 | } |
311 | asearch_write_recent($recent_array); |
6b37252b |
312 | } |
313 | |
7d60bda5 |
314 | /** Find a recent search in the prefs (used to avoid saving duplicates) |
134e4174 |
315 | */ |
7d60bda5 |
316 | function asearch_find_recent(&$recent_array, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
317 | { |
8cc8ec79 |
318 | global $recent_prefkeys, $search_advanced; |
319 | |
320 | $where_string = asearch_serialize($where_array); |
321 | $mailbox_string = asearch_serialize($mailbox_array); |
322 | $what_string = asearch_serialize($what_array); |
323 | $unop_string = asearch_serialize($unop_array); |
324 | if ($search_advanced) { |
325 | $biop_string = asearch_serialize($biop_array); |
326 | $exclude_string = asearch_serialize($exclude_array); |
327 | $sub_string = asearch_serialize($sub_array); |
328 | } |
329 | $recent_count = count($recent_array[$recent_prefkeys[ASEARCH_WHERE]]); |
330 | for ($recent_num = 0; $recent_num < $recent_count; $recent_num++) { |
331 | if (isset($recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num])) { |
332 | if ( |
333 | $where_string == $recent_array[$recent_prefkeys[ASEARCH_WHERE]][$recent_num] && |
334 | $mailbox_string == $recent_array[$recent_prefkeys[ASEARCH_MAILBOX]][$recent_num] && |
335 | $what_string == $recent_array[$recent_prefkeys[ASEARCH_WHAT]][$recent_num] && |
336 | $unop_string == $recent_array[$recent_prefkeys[ASEARCH_UNOP]][$recent_num] && |
337 | ((!$search_advanced) || |
338 | ($biop_string == $recent_array[$recent_prefkeys[ASEARCH_BIOP]][$recent_num] && |
339 | $exclude_string == $recent_array[$recent_prefkeys[ASEARCH_EXCLUDE]][$recent_num] && |
340 | $sub_string == $recent_array[$recent_prefkeys[ASEARCH_SUB]][$recent_num])) |
341 | ) |
342 | return $recent_num; |
343 | } |
344 | } |
345 | return -1; |
6b37252b |
346 | } |
347 | |
7d60bda5 |
348 | /** Push a recent search into the prefs |
134e4174 |
349 | */ |
7d60bda5 |
350 | function asearch_push_recent(&$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
351 | { |
8cc8ec79 |
352 | global $recent_prefkeys, $search_memory; |
324ac3c5 |
353 | //global $what; // Hack to access issued search from read_body.php |
354 | $what = 1; |
355 | /** |
356 | * Update search history and store it in the session so we can retrieve the |
357 | * issued search when returning from an external page like read_body.php |
358 | */ |
359 | $criteria[$what] = array($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
8cc8ec79 |
360 | sqsession_register($criteria, ASEARCH_CRITERIA); |
361 | if ($search_memory > 0) { |
362 | $recent_array = asearch_read_recent(); |
363 | $recent_found = asearch_find_recent($recent_array, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
134e4174 |
364 | if ($recent_found >= 0) { // Remove identical recent |
8cc8ec79 |
365 | foreach ($recent_prefkeys as $key) { |
366 | array_splice($recent_array[$key], $recent_found, 1); |
367 | } |
368 | } |
369 | $input = array($where_array, $mailbox_array, $what_array, $unop_array, $biop_array, $exclude_array, $sub_array); |
370 | $i = 0; |
371 | foreach ($recent_prefkeys as $key) { |
372 | array_unshift($recent_array[$key], asearch_serialize($input[$i])); |
373 | $i++; |
374 | } |
375 | asearch_write_recent($recent_array); |
376 | } |
6b37252b |
377 | } |
378 | |
7d60bda5 |
379 | /** Edit a recent search |
134e4174 |
380 | * @global array mailbox_array searched mailboxes |
381 | */ |
7d60bda5 |
382 | function asearch_edit_recent($index) |
6b37252b |
383 | { |
8cc8ec79 |
384 | global $recent_prefkeys, $search_advanced; |
385 | global $where_array, $mailbox_array, $what_array, $unop_array; |
386 | global $biop_array, $exclude_array, $sub_array; |
7d60bda5 |
387 | |
8cc8ec79 |
388 | $where_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHERE], $index)); |
389 | $mailbox_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_MAILBOX], $index)); |
390 | $what_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_WHAT], $index)); |
391 | $unop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_UNOP], $index)); |
392 | if ($search_advanced) { |
393 | $biop_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_BIOP], $index)); |
394 | $exclude_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_EXCLUDE], $index)); |
395 | $sub_array = asearch_unserialize(asearch_getPref($recent_prefkeys[ASEARCH_SUB], $index)); |
396 | } |
6b37252b |
397 | } |
398 | |
958becc9 |
399 | /** Get last search criteria from session or prefs |
134e4174 |
400 | * FIX ME, try to avoid globals |
401 | */ |
324ac3c5 |
402 | function asearch_edit_last($index) { |
8cc8ec79 |
403 | if (sqGetGlobalVar(ASEARCH_CRITERIA, $criteria, SQ_SESSION)) { |
404 | global $where_array, $mailbox_array, $what_array, $unop_array; |
405 | global $biop_array, $exclude_array, $sub_array; |
324ac3c5 |
406 | $mailbox_array = $criteria[$index][0]; |
407 | $biop_array = $criteria[$index][1]; |
408 | $unop_array = $criteria[$index][2]; |
409 | $where_array = $criteria[$index][3]; |
410 | $what_array = $criteria[$index][4]; |
411 | $exclude_array = $criteria[$index][5]; |
412 | $sub_array = $criteria[$index][6]; |
413 | unset($criteria[$index]); |
414 | //sqsession_unregister(ASEARCH_CRITERIA); |
415 | } else { |
8cc8ec79 |
416 | global $search_memory; |
324ac3c5 |
417 | if ($search_memory > 0) { |
8cc8ec79 |
418 | asearch_edit_recent(0); |
324ac3c5 |
419 | } |
8cc8ec79 |
420 | } |
6b37252b |
421 | } |
422 | |
7d60bda5 |
423 | /** Edit a saved search |
134e4174 |
424 | */ |
7d60bda5 |
425 | function asearch_edit_saved($index) |
6b37252b |
426 | { |
8cc8ec79 |
427 | global $saved_prefkeys, $search_advanced; |
428 | global $where_array, $mailbox_array, $what_array, $unop_array; |
429 | global $biop_array, $exclude_array, $sub_array; |
7d60bda5 |
430 | |
8cc8ec79 |
431 | $where_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHERE], $index)); |
432 | $mailbox_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_MAILBOX], $index)); |
433 | $what_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_WHAT], $index)); |
434 | $unop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_UNOP], $index)); |
435 | if ($search_advanced) { |
436 | $biop_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_BIOP], $index)); |
437 | $exclude_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_EXCLUDE], $index)); |
438 | $sub_array = asearch_unserialize(asearch_getPref($saved_prefkeys[ASEARCH_SUB], $index)); |
439 | } |
6b37252b |
440 | } |
441 | |
7d60bda5 |
442 | /** Write a saved search to the prefs |
134e4174 |
443 | */ |
7d60bda5 |
444 | function asearch_write_saved(&$saved_array) |
6b37252b |
445 | { |
8cc8ec79 |
446 | global $saved_prefkeys; |
6b37252b |
447 | |
8cc8ec79 |
448 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
449 | for ($saved_num=0; $saved_num < $saved_count; $saved_num++) { |
450 | foreach ($saved_prefkeys as $key) { |
451 | asearch_setPref($key, $saved_num, $saved_array[$key][$saved_num]); |
452 | } |
453 | } |
454 | foreach ($saved_prefkeys as $key) { |
455 | asearch_removePref($key, $saved_count); |
456 | } |
6b37252b |
457 | } |
458 | |
7d60bda5 |
459 | /** Delete a saved search from the prefs |
134e4174 |
460 | */ |
7d60bda5 |
461 | function asearch_delete_saved($saved_index) |
6b37252b |
462 | { |
8cc8ec79 |
463 | global $saved_prefkeys; |
6b37252b |
464 | |
8cc8ec79 |
465 | $saved_array = asearch_read_saved(); |
466 | $asearch_keys = $saved_prefkeys; |
467 | foreach ($asearch_keys as $key) { |
468 | array_splice($saved_array[$key], $saved_index, 1); |
469 | } |
470 | asearch_write_saved($saved_array); |
6b37252b |
471 | } |
472 | |
7d60bda5 |
473 | /** Translate the input date to imap date to local date display, |
134e4174 |
474 | * so the user can know if the date is wrong or illegal |
475 | * @return string locally formatted date or error text |
476 | */ |
7d60bda5 |
477 | function asearch_get_date_display(&$what) |
6b37252b |
478 | { |
8cc8ec79 |
479 | $what_parts = sqimap_asearch_parse_date($what); |
480 | if (count($what_parts) == 4) { |
481 | if (checkdate($what_parts[2], $what_parts[1], $what_parts[3])) |
482 | return date_intl(_("M j, Y"), mktime(0,0,0,$what_parts[2],$what_parts[1],$what_parts[3])); |
483 | //return $what_parts[1] . ' ' . getMonthName($what_parts[2]) . ' ' . $what_parts[3]; |
484 | return _("(Illegal date)"); |
485 | } |
486 | return _("(Wrong date)"); |
6b37252b |
487 | } |
488 | |
7d60bda5 |
489 | /** Translate the query to rough natural display |
134e4174 |
490 | * @return string rough natural query ready to display |
491 | */ |
7d60bda5 |
492 | function asearch_get_query_display(&$color, &$mailbox_array, &$biop_array, &$unop_array, &$where_array, &$what_array, &$exclude_array, &$sub_array) |
6b37252b |
493 | { |
8cc8ec79 |
494 | global $imap_asearch_biops_in, $imap_asearch_biops, $imap_asearch_unops, $imap_asearch_options; |
495 | global $imap_asearch_opcodes; |
496 | |
497 | $last_mailbox = $mailbox_array[0]; |
498 | if (empty($last_mailbox)) |
499 | $last_mailbox = 'INBOX'; |
500 | $query_display = ''; |
501 | for ($crit_num=0; $crit_num < count($where_array); $crit_num++) { |
502 | if ((!isset($exclude_array[$crit_num])) || (!$exclude_array[$crit_num])) { |
503 | $cur_mailbox = $mailbox_array[$crit_num]; |
504 | if (empty($cur_mailbox)) |
505 | $cur_mailbox = 'INBOX'; |
506 | $biop = asearch_nz($biop_array[$crit_num]); |
507 | if (($query_display == '') || ($cur_mailbox != $last_mailbox)) { |
fa62b054 |
508 | $mailbox_display = ' <b>' . htmlspecialchars(asearch_get_mailbox_display($cur_mailbox)) . '</b>'; |
8cc8ec79 |
509 | if ($query_display == '') |
510 | $biop_display = _("In"); |
511 | else |
512 | $biop_display = $imap_asearch_biops_in[$biop]; |
513 | $last_mailbox = $cur_mailbox; |
514 | } |
515 | else { |
516 | $mailbox_display = ''; |
517 | $biop_display = $imap_asearch_biops[$biop]; |
518 | } |
519 | $unop = $unop_array[$crit_num]; |
520 | $unop_display = $imap_asearch_unops[$unop]; |
521 | if ($unop_display != '') |
522 | $unop_display .= ' '; |
523 | $where = $where_array[$crit_num]; |
524 | $where_display = $unop_display . asearch_nz($imap_asearch_options[$where], $where); |
525 | $what_type = $imap_asearch_opcodes[$where]; |
526 | $what = $what_array[$crit_num]; |
134e4174 |
527 | if ($what_type) { /* Check opcode parameter */ |
8cc8ec79 |
528 | if ($what == '') |
529 | $what_display = ' ' . asearch_get_error_display($color, _("(Missing argument)")); |
530 | else { |
531 | if ($what_type == 'adate') |
532 | $what_display = asearch_get_date_display($what); |
533 | else |
534 | $what_display = htmlspecialchars($what); |
535 | $what_display = ' <b>' . $what_display . '</b>'; |
536 | } |
537 | } |
538 | else { |
539 | if ($what) |
540 | $what_display = ' ' . asearch_get_error_display($color, _("(Spurious argument)")); |
541 | else |
542 | $what_display = ''; |
543 | } |
544 | if ($mailbox_display != '') |
545 | $query_display .= ' <u><i>' . $biop_display . '</i></u>' . $mailbox_display . ' <u><i>' . $where_display . '</i></u>' . $what_display; |
546 | else |
547 | $query_display .= ' <u><i>' . $biop_display . ' ' . $where_display . '</i></u>' . $what_display; |
548 | } |
549 | } |
550 | return $query_display; |
6b37252b |
551 | } |
552 | |
91c27aee |
553 | /** |
554 | * Creates button |
555 | * |
556 | * @deprecated see form functions available in 1.5.1 and 1.4.3. |
557 | * @param string $type |
558 | * @param string $name |
559 | * @param string $value |
560 | * @param string $js |
561 | * @param bool $enabled |
562 | */ |
563 | function getButton($type, $name, $value, $js = '', $enabled = TRUE) { |
564 | $disabled = ( $enabled ? '' : 'disabled ' ); |
565 | $js = ( $js ? $js.' ' : '' ); |
566 | return '<input '.$disabled.$js. |
567 | 'type="'.$type. |
568 | '" name="'.$name. |
569 | '" value="'.$value . |
570 | '" style="padding: 0px; margin: 0px" />'; |
571 | } |
572 | |
573 | |
7d60bda5 |
574 | /** Handle the alternate row colors |
134e4174 |
575 | * @return string color value |
576 | */ |
7d60bda5 |
577 | function asearch_get_row_color(&$color, $row_num) |
6b37252b |
578 | { |
579 | /*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/ |
8cc8ec79 |
580 | $color_string = $color[4]; |
581 | if ($GLOBALS['alt_index_colors']) { |
582 | if (($row_num % 2) == 0) { |
583 | if (!isset($color[12])) |
584 | $color[12] = '#EAEAEA'; |
585 | $color_string = $color[12]; |
586 | } |
587 | } |
588 | return $color_string; |
6b37252b |
589 | } |
590 | |
7d60bda5 |
591 | /** Print a whole query array, recent or saved |
134e4174 |
592 | */ |
7d60bda5 |
593 | function asearch_print_query_array(&$boxes, &$query_array, &$query_keys, &$action_array, $title, $show_pref) |
6b37252b |
594 | { |
8cc8ec79 |
595 | global $color; |
596 | global $data_dir, $username; |
597 | global $use_icons, $icon_theme; |
598 | |
599 | $show_flag = getPref($data_dir, $username, $show_pref, 0) & 1; |
600 | $use_icons_flag = ($use_icons) && ($icon_theme != 'none'); |
601 | if ($use_icons_flag) |
602 | $text_array = array('<img src="' . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />', |
603 | '<img src="' . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />'); |
604 | else |
605 | $text_array = array('-', '+'); |
606 | $toggle_link = asearch_get_toggle_link(!$show_flag, $show_pref, $text_array, array(_("Fold"), _("Unfold"))); |
607 | if (!$use_icons_flag) |
608 | $toggle_link = '<small>[' . $toggle_link . ']</small>'; |
609 | |
610 | echo "<br />\n"; |
611 | echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"'); |
612 | echo html_tag('tr', |
613 | html_tag('td', $toggle_link, 'center', $color[5], 'width="5%"') |
614 | . html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=4')); |
615 | if ($show_flag) { |
616 | $main_key = $query_keys[ASEARCH_WHERE]; |
617 | $query_count = count($query_array[$main_key]); |
618 | for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) { |
619 | if (!empty($query_array[$main_key][$query_num])) { |
620 | echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num)); |
621 | |
622 | unset($search_array); |
623 | foreach ($query_keys as $query_key) { |
624 | $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]); |
625 | } |
626 | $where_array = $search_array[ASEARCH_WHERE]; |
627 | $mailbox_array = $search_array[ASEARCH_MAILBOX]; |
628 | $what_array = $search_array[ASEARCH_WHAT]; |
629 | $unop_array = $search_array[ASEARCH_UNOP]; |
630 | $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array()); |
631 | $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array()); |
632 | $sub_array = asearch_nz($search_array[ASEARCH_SUB], array()); |
633 | $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
634 | |
635 | echo html_tag('td', $query_num + 1, 'right'); |
636 | echo html_tag('td', $query_display, 'center', '', 'width="80%"'); |
637 | foreach ($action_array as $action => $action_display) { |
638 | echo html_tag('td', '<a href="' . asearch_get_href('submit=' . $action . '&rownum=' . $query_num) . '">' . $action_display . '</a>', 'center'); |
639 | } |
640 | |
641 | echo '</tr>' . "\n"; |
642 | $row_num++; |
643 | } |
644 | } |
645 | } |
646 | echo '</table>' . "\n"; |
6b37252b |
647 | } |
648 | |
7d60bda5 |
649 | /** Print the saved array |
134e4174 |
650 | */ |
7d60bda5 |
651 | function asearch_print_saved(&$boxes) |
6b37252b |
652 | { |
8cc8ec79 |
653 | global $saved_prefkeys; |
6b37252b |
654 | |
8cc8ec79 |
655 | $saved_array = asearch_read_saved(); |
656 | if (isset($saved_array[$saved_prefkeys[0]])) { |
657 | $saved_count = count($saved_array[$saved_prefkeys[0]]); |
658 | if ($saved_count > 0) { |
674a2ca2 |
659 | $saved_actions = array('edit_saved' => _("Edit"), 'search_saved' => _("Search"), 'delete_saved' => _("Delete")); |
8cc8ec79 |
660 | asearch_print_query_array($boxes, $saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"), 'search_show_saved'); |
661 | } |
662 | } |
70c4fd84 |
663 | } |
6c8388a9 |
664 | |
7d60bda5 |
665 | /** |
134e4174 |
666 | * Print the recent array |
667 | */ |
7d60bda5 |
668 | function asearch_print_recent(&$boxes) |
6b37252b |
669 | { |
8cc8ec79 |
670 | global $recent_prefkeys, $search_memory; |
6b37252b |
671 | |
8cc8ec79 |
672 | $recent_array = asearch_read_recent(); |
673 | if (isset($recent_array[$recent_prefkeys[0]])) { |
674 | $recent_count = count($recent_array[$recent_prefkeys[0]]); |
675 | if (min($recent_count, $search_memory) > 0) { |
676 | $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget")); |
677 | asearch_print_query_array($boxes, $recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"), 'search_show_recent'); |
678 | } |
679 | } |
56e0b3b7 |
680 | } |
681 | |
7d60bda5 |
682 | /** Build an <option> statement |
134e4174 |
683 | */ |
920ec5ec |
684 | function asearch_opt($val, $sel, $tit) |
6b37252b |
685 | { |
e1728a7a |
686 | return '<option value="' . $val . '"' . ($sel == $val ? ' selected="selected"' : '') . '>' . $tit . '</option>' . "\n"; |
6b37252b |
687 | } |
688 | |
7d60bda5 |
689 | /** Build a <select> statement from an array |
134e4174 |
690 | */ |
6b37252b |
691 | function asearch_opt_array($var_name, $opt_array, $cur_val) |
692 | { |
8cc8ec79 |
693 | $output = '<select name="' . $var_name . '">' . "\n"; |
694 | foreach($opt_array as $val => $display) |
695 | $output .= asearch_opt($val, $cur_val, asearch_nz($display, $val)); |
696 | $output .= '</select>' . "\n"; |
697 | return $output; |
6b37252b |
698 | } |
699 | |
7d60bda5 |
700 | /** Verify that a mailbox exists |
134e4174 |
701 | * @return bool mailbox exists |
702 | */ |
7d60bda5 |
703 | function asearch_mailbox_exists($mailbox, &$boxes) |
920ec5ec |
704 | { |
8cc8ec79 |
705 | foreach ($boxes as $box) { |
706 | if ($box['unformatted'] == $mailbox) |
707 | return TRUE; |
708 | } |
709 | return FALSE; |
920ec5ec |
710 | } |
711 | |
5b6abe97 |
712 | /** Build the mailbox select |
134e4174 |
713 | */ |
7d60bda5 |
714 | function asearch_get_form_mailbox($imapConnection, &$boxes, $mailbox, $row_num = 0) |
6b37252b |
715 | { |
324ac3c5 |
716 | if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) { |
fa62b054 |
717 | $missing = asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . htmlspecialchars(asearch_get_mailbox_display($mailbox))); |
324ac3c5 |
718 | } else { |
8cc8ec79 |
719 | $missing = ''; |
324ac3c5 |
720 | } |
8cc8ec79 |
721 | return '<select name="mailbox[' . $row_num . ']">' |
722 | . $missing |
723 | . asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']') |
724 | . sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL) |
725 | . '</select>'; |
7d60bda5 |
726 | } |
727 | |
5b6abe97 |
728 | /** Build the Include subfolders checkbox |
134e4174 |
729 | */ |
7d60bda5 |
730 | function asearch_get_form_sub($sub, $row_num = 0) |
731 | { |
582d0621 |
732 | return addCheckBox('sub[' . $row_num .']', $sub); |
7d60bda5 |
733 | } |
734 | |
5b6abe97 |
735 | /** Build the 2 unop and where selects |
134e4174 |
736 | */ |
7d60bda5 |
737 | function asearch_get_form_location($unop, $where, $row_num = 0) |
738 | { |
8cc8ec79 |
739 | global $imap_asearch_unops, $imap_asearch_options; |
7d60bda5 |
740 | |
8cc8ec79 |
741 | return asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop) |
742 | . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where); |
7d60bda5 |
743 | } |
744 | |
5b6abe97 |
745 | /** Build the what text input |
134e4174 |
746 | */ |
7d60bda5 |
747 | function asearch_get_form_what($what, $row_num = 0) |
748 | { |
582d0621 |
749 | return addInput('what[' . $row_num . ']', $what, '35'); |
7d60bda5 |
750 | } |
751 | |
5b6abe97 |
752 | /** Build the Exclude criteria checkbox |
134e4174 |
753 | */ |
7d60bda5 |
754 | function asearch_get_form_exclude($exclude, $row_num = 0) |
755 | { |
582d0621 |
756 | return addCheckBox('exclude['.$row_num.']', $exclude); |
7d60bda5 |
757 | } |
758 | |
759 | /** Print one advanced form row |
134e4174 |
760 | */ |
7d60bda5 |
761 | function asearch_print_form_row($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
762 | { |
8cc8ec79 |
763 | global $imap_asearch_biops_in; |
764 | global $color; |
6b37252b |
765 | |
8cc8ec79 |
766 | echo html_tag('tr', '', '', $color[4]); |
6b37252b |
767 | |
7d60bda5 |
768 | //Binary operator |
8cc8ec79 |
769 | echo html_tag('td', $row_num ? |
770 | asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop) |
134e4174 |
771 | : '<b>' . _("In") . '</b>', 'center') . "\n"; |
7d60bda5 |
772 | |
773 | //Mailbox list and Include Subfolders |
8cc8ec79 |
774 | echo html_tag('td', |
775 | asearch_get_form_mailbox($imapConnection, $boxes, $mailbox, $row_num) |
776 | . _("and subfolders:") . asearch_get_form_sub($sub, $row_num), 'center') . "\n"; |
6b37252b |
777 | |
7d60bda5 |
778 | //Unary operator and Search location |
8cc8ec79 |
779 | echo html_tag('td', asearch_get_form_location($unop, $where, $row_num), 'center') . "\n"; |
6b37252b |
780 | |
7d60bda5 |
781 | //Text input |
8cc8ec79 |
782 | echo html_tag('td', asearch_get_form_what($what, $row_num), 'center') . "\n"; |
7d60bda5 |
783 | |
784 | //Exclude criteria |
8cc8ec79 |
785 | echo html_tag('td', _("Exclude Criteria:") . asearch_get_form_exclude($exclude, $row_num), 'center') . "\n"; |
6b37252b |
786 | |
8cc8ec79 |
787 | echo "</tr>\n"; |
6b37252b |
788 | } |
789 | |
7d60bda5 |
790 | /** Print the advanced search form |
134e4174 |
791 | */ |
7d60bda5 |
792 | function asearch_print_form($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
6b37252b |
793 | { |
8cc8ec79 |
794 | global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html; |
795 | global $color; |
6b37252b |
796 | |
7d60bda5 |
797 | //Search Form |
8cc8ec79 |
798 | echo "<br />\n"; |
799 | echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n"; |
800 | |
801 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
802 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5')); |
803 | $row_count = count($where_array); |
804 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
805 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
806 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
807 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
808 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
809 | $what = asearch_nz($what_array[$row_num]); |
810 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
811 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
812 | asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
813 | } |
814 | echo '</table>' . "\n"; |
6b37252b |
815 | |
7d60bda5 |
816 | //Submit buttons |
8cc8ec79 |
817 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
818 | echo html_tag('tr', |
e1728a7a |
819 | html_tag('td', getButton('submit', 'submit', $search_button_html), 'center') . "\n" |
820 | . html_tag('td', getButton('submit', 'submit', $add_criteria_button_html), 'center') . "\n" |
821 | . html_tag('td', getButton('submit', 'submit', $del_all_button_html), 'center') . "\n" |
822 | . html_tag('td', getButton('submit', 'submit', $del_excluded_button_html), 'center') . "\n" |
8cc8ec79 |
823 | ); |
824 | echo '</table>' . "\n"; |
825 | echo '</form>' . "\n"; |
6b37252b |
826 | } |
827 | |
7d60bda5 |
828 | /** Print one basic form row |
134e4174 |
829 | */ |
7d60bda5 |
830 | function asearch_print_form_row_basic($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num) |
831 | { |
8cc8ec79 |
832 | global $search_button_html; |
833 | global $color; |
7d60bda5 |
834 | |
8cc8ec79 |
835 | echo html_tag('tr', '', '', $color[4]); |
7d60bda5 |
836 | |
837 | //Mailbox list |
8cc8ec79 |
838 | echo html_tag('td', '<b>' . _("In") . '</b> ' . asearch_get_form_mailbox($imapConnection, $boxes, $mailbox), 'center') . "\n"; |
7d60bda5 |
839 | |
840 | //Unary operator and Search location |
8cc8ec79 |
841 | echo html_tag('td', asearch_get_form_location($unop, $where), 'center') . "\n"; |
7d60bda5 |
842 | |
843 | //Text input |
8cc8ec79 |
844 | echo html_tag('td', asearch_get_form_what($what), 'center') . "\n"; |
7d60bda5 |
845 | |
846 | //Submit button |
e1728a7a |
847 | echo html_tag('td', getButton('submit', 'submit', $search_button_html), 'center') . "\n"; |
7d60bda5 |
848 | |
8cc8ec79 |
849 | echo "</tr>\n"; |
7d60bda5 |
850 | } |
851 | |
852 | /** Print the basic search form |
134e4174 |
853 | */ |
7d60bda5 |
854 | function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array) |
855 | { |
8cc8ec79 |
856 | global $color; |
7d60bda5 |
857 | |
858 | //Search Form |
8cc8ec79 |
859 | echo "<br />\n"; |
860 | echo '<form action="' . asearch_get_href() . '" name="form_asearch">' . "\n"; |
861 | |
862 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"'); |
863 | //echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=4')); |
864 | $row_count = count($where_array); |
865 | for ($row_num = 0; $row_num < $row_count; $row_num++) { |
866 | $mailbox = asearch_nz($mailbox_array[$row_num]); |
867 | $biop = strip_tags(asearch_nz($biop_array[$row_num])); |
868 | $unop = strip_tags(asearch_nz($unop_array[$row_num])); |
869 | $where = strip_tags(asearch_nz($where_array[$row_num])); |
870 | $what = asearch_nz($what_array[$row_num]); |
871 | $exclude = strip_tags(asearch_nz($exclude_array[$row_num])); |
872 | $sub = strip_tags(asearch_nz($sub_array[$row_num])); |
873 | asearch_print_form_row_basic($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num); |
874 | } |
875 | echo '</table>' . "\n"; |
876 | echo '</form>' . "\n"; |
7d60bda5 |
877 | } |
878 | |
59a623e6 |
879 | |
40fbe929 |
880 | /** |
134e4174 |
881 | * @param array $boxes mailboxes array (reference) |
882 | * @return array selectable unformatted mailboxes names |
883 | */ |
40fbe929 |
884 | function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes) |
885 | { |
8cc8ec79 |
886 | $mboxes_array = array(); |
887 | $boxcount = count($boxes); |
888 | for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) { |
889 | if (!in_array('noselect', $boxes[$boxnum]['flags'])) |
890 | $mboxes_array[] = $boxes[$boxnum]['unformatted']; |
891 | } |
892 | return $mboxes_array; |
40fbe929 |
893 | } |
894 | |
0d672ac0 |
895 | /* ------------------------ main ------------------------ */ |
7d60bda5 |
896 | /* get globals we will need */ |
6b37252b |
897 | sqgetGlobalVar('username', $username, SQ_SESSION); |
898 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
7d60bda5 |
899 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
900 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
6b37252b |
901 | |
ad2212db |
902 | if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) { |
139b3991 |
903 | $checkall = (int) $temp; |
ad2212db |
904 | } |
905 | |
324ac3c5 |
906 | /** |
907 | * Retrieve the mailbox cache from the session. |
908 | */ |
909 | sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION); |
910 | |
139b3991 |
911 | |
6b37252b |
912 | $search_button_html = _("Search"); |
913 | $search_button_text = asearch_unhtmlentities($search_button_html); |
914 | $add_criteria_button_html = _("Add New Criteria"); |
915 | $add_criteria_button_text = asearch_unhtmlentities($add_criteria_button_html); |
34a85c56 |
916 | $del_excluded_button_html = _("Remove Excluded Criteria"); |
6b37252b |
917 | $del_excluded_button_text = asearch_unhtmlentities($del_excluded_button_html); |
34a85c56 |
918 | $del_all_button_html = _("Remove All Criteria"); |
6b37252b |
919 | $del_all_button_text = asearch_unhtmlentities($del_all_button_html); |
920 | |
7d60bda5 |
921 | /** Maximum number of recent searches to handle |
134e4174 |
922 | * Default 0 |
923 | * @global integer $search_memory |
924 | */ |
7d60bda5 |
925 | $search_memory = getPref($data_dir, $username, 'search_memory', 0); |
926 | |
927 | /** Advanced search control |
134e4174 |
928 | * - 0 => allow basic interface only |
929 | * - 1 => allow advanced interface only |
930 | * - 2 => allow both |
931 | * Default 2 |
932 | */ |
5b6abe97 |
933 | $allow_advanced_search = asearch_nz($allow_advanced_search, 2); |
6b37252b |
934 | |
7d60bda5 |
935 | /** |
134e4174 |
936 | * Toggle advanced/basic search |
937 | */ |
324ac3c5 |
938 | if (sqgetGlobalVar('advanced', $search_advanced, SQ_GET)) { |
8cc8ec79 |
939 | setPref($data_dir, $username, 'search_advanced', $search_advanced & 1); |
324ac3c5 |
940 | } |
7d60bda5 |
941 | /** If 1, show advanced search interface |
134e4174 |
942 | * Default from allow_advanced_search pref |
943 | * @global integer $search_advanced |
944 | */ |
324ac3c5 |
945 | if ($allow_advanced_search > 1) { |
8cc8ec79 |
946 | $search_advanced = getPref($data_dir, $username, 'search_advanced', 0); |
324ac3c5 |
947 | } else { |
8cc8ec79 |
948 | $search_advanced = $allow_advanced_search; |
324ac3c5 |
949 | } |
7d60bda5 |
950 | if ($search_advanced) { |
951 | /** Set recent prefkeys according to $search_advanced |
134e4174 |
952 | * @global array $recent_prefkeys |
953 | */ |
8cc8ec79 |
954 | $recent_prefkeys = array('asearch_recent_where', 'asearch_recent_mailbox', 'asearch_recent_what', 'asearch_recent_unop', 'asearch_recent_biop', 'asearch_recent_exclude', 'asearch_recent_sub'); |
7d60bda5 |
955 | |
956 | /** Set saved prefkeys according to $search_advanced |
134e4174 |
957 | * @global array $saved_prefkeys |
958 | */ |
8cc8ec79 |
959 | $saved_prefkeys = array('asearch_saved_where', 'asearch_saved_mailbox', 'asearch_saved_what', 'asearch_saved_unop', 'asearch_saved_biop', 'asearch_saved_exclude', 'asearch_saved_sub'); |
7d60bda5 |
960 | |
961 | /*$asearch_prefkeys = array('where', 'mailbox', 'what', 'biop', 'unop', 'exclude', 'sub');*/ |
324ac3c5 |
962 | } else { |
8cc8ec79 |
963 | $recent_prefkeys = array('search_where', 'search_folder', 'search_what', 'search_unop'); |
964 | $saved_prefkeys = array('saved_where', 'saved_folder', 'saved_what', 'saved_unop'); |
7d60bda5 |
965 | } |
6b37252b |
966 | |
2d2f8bb8 |
967 | /** How we did enter the form |
134e4174 |
968 | * - unset : Enter key, or called from outside (eg read_body) |
969 | * - $search_button_text : Search button |
970 | * - 'Search_no_update' : Search but don't update recent |
971 | * - 'Search_last' : Same as no_update but reload and search last |
972 | * - 'Search_silent' : Same as no_update but only display results |
973 | * - $add_criteria_button_text : Add New Criteria button |
974 | * - $del_excluded_button_text : Remove Excluded Criteria button |
975 | * - $del_all_button_text : Remove All Criteria button |
976 | * - 'save_recent' |
977 | * - 'search_recent' |
978 | * - 'forget_recent' |
979 | * - 'edit_saved' |
980 | * - 'search_saved' |
981 | * - 'delete_saved' |
982 | * @global string $submit |
983 | */ |
e09e556f |
984 | $searchpressed = false; |
324ac3c5 |
985 | if (isset($_GET['submit'])) { |
8cc8ec79 |
986 | $submit = strip_tags($_GET['submit']); |
324ac3c5 |
987 | } |
e09e556f |
988 | |
2d2f8bb8 |
989 | /** Searched mailboxes |
134e4174 |
990 | * @global array $mailbox_array |
991 | */ |
6b37252b |
992 | if (isset($_GET['mailbox'])) { |
8cc8ec79 |
993 | $mailbox_array = $_GET['mailbox']; |
324ac3c5 |
994 | $targetmailbox = $_GET['mailbox']; |
995 | if (!is_array($mailbox_array)) { |
8cc8ec79 |
996 | $mailbox_array = array($mailbox_array); |
324ac3c5 |
997 | } |
998 | } else { |
8cc8ec79 |
999 | $mailbox_array = array(); |
d0dd72b5 |
1000 | $targetmailbox = array(); |
324ac3c5 |
1001 | } |
1002 | $aMailboxGlobalPref = array( |
1003 | MBX_PREF_SORT => 0, |
1004 | MBX_PREF_LIMIT => (int) $show_num, |
1005 | MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge, |
1006 | MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort') |
1007 | // MBX_PREF_FUTURE => (var) $future |
1008 | ); |
1009 | |
1010 | /** |
1011 | * system wide admin settings and incoming vars. |
1012 | */ |
1013 | $aConfig = array( |
f027a882 |
1014 | // 'allow_thread_sort' => $allow_thread_sort, |
1015 | // 'allow_server_sort' => $allow_server_sort, |
324ac3c5 |
1016 | 'user' => $username, |
91c27aee |
1017 | 'setindex' => 1 |
324ac3c5 |
1018 | ); |
6b37252b |
1019 | |
2d2f8bb8 |
1020 | /** Binary operators |
134e4174 |
1021 | * @global array $biop_array |
1022 | */ |
6b37252b |
1023 | if (isset($_GET['biop'])) { |
8cc8ec79 |
1024 | $biop_array = $_GET['biop']; |
1025 | if (!is_array($biop_array)) |
1026 | $biop_array = array($biop_array); |
324ac3c5 |
1027 | } else { |
8cc8ec79 |
1028 | $biop_array = array(); |
324ac3c5 |
1029 | } |
2d2f8bb8 |
1030 | /** Unary operators |
134e4174 |
1031 | * @global array $unop_array |
1032 | */ |
6b37252b |
1033 | if (isset($_GET['unop'])) { |
8cc8ec79 |
1034 | $unop_array = $_GET['unop']; |
1035 | if (!is_array($unop_array)) |
1036 | $unop_array = array($unop_array); |
324ac3c5 |
1037 | } else { |
8cc8ec79 |
1038 | $unop_array = array(); |
324ac3c5 |
1039 | } |
2d2f8bb8 |
1040 | /** Where to search |
134e4174 |
1041 | * @global array $where_array |
1042 | */ |
6b37252b |
1043 | if (isset($_GET['where'])) { |
8cc8ec79 |
1044 | $where_array = $_GET['where']; |
324ac3c5 |
1045 | if (!is_array($where_array)) { |
8cc8ec79 |
1046 | $where_array = array($where_array); |
324ac3c5 |
1047 | } |
1048 | } else { |
8cc8ec79 |
1049 | $where_array = array(); |
324ac3c5 |
1050 | } |
2d2f8bb8 |
1051 | /** What to search |
134e4174 |
1052 | * @global array $what_array |
1053 | */ |
6b37252b |
1054 | if (isset($_GET['what'])) { |
8cc8ec79 |
1055 | $what_array = $_GET['what']; |
324ac3c5 |
1056 | if (!is_array($what_array)) { |
8cc8ec79 |
1057 | $what_array = array($what_array); |
324ac3c5 |
1058 | } |
1059 | } else { |
8cc8ec79 |
1060 | $what_array = array(); |
324ac3c5 |
1061 | } |
2d2f8bb8 |
1062 | /** Whether to exclude this criteria from search |
134e4174 |
1063 | * @global array $exclude_array |
1064 | */ |
324ac3c5 |
1065 | if (isset($_GET['exclude'])) { |
8cc8ec79 |
1066 | $exclude_array = $_GET['exclude']; |
324ac3c5 |
1067 | } else { |
8cc8ec79 |
1068 | $exclude_array = array(); |
324ac3c5 |
1069 | } |
2d2f8bb8 |
1070 | /** Search within subfolders |
134e4174 |
1071 | * @global array $sub_array |
1072 | */ |
324ac3c5 |
1073 | if (isset($_GET['sub'])) { |
8cc8ec79 |
1074 | $sub_array = $_GET['sub']; |
324ac3c5 |
1075 | } else { |
8cc8ec79 |
1076 | $sub_array = array(); |
324ac3c5 |
1077 | } |
2d2f8bb8 |
1078 | /** Row number used by recent and saved stuff |
134e4174 |
1079 | */ |
324ac3c5 |
1080 | if (isset($_GET['rownum'])) { |
6b37252b |
1081 | $submit_rownum = strip_tags($_GET['rownum']); |
324ac3c5 |
1082 | } |
2d2f8bb8 |
1083 | /** Change global sort |
134e4174 |
1084 | */ |
324ac3c5 |
1085 | if (sqgetGlobalVar('srt', $temp, SQ_GET)) { |
1086 | $srt = (int) $temp; |
1087 | asearch_edit_last(1); |
91c27aee |
1088 | // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
324ac3c5 |
1089 | } |
1090 | if (sqgetGlobalVar('startMessage', $temp, SQ_GET)) { |
1091 | $startMessage = (int) $temp; |
1092 | asearch_edit_last(1); |
91c27aee |
1093 | // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
c2d47d51 |
1094 | } |
1095 | |
324ac3c5 |
1096 | if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) { |
1097 | $showall = (int) $temp; |
1098 | asearch_edit_last(1); |
91c27aee |
1099 | // asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
56e0b3b7 |
1100 | } |
91c27aee |
1101 | |
1102 | if ( sqgetGlobalVar('account', $temp, SQ_GET) ) { |
1103 | $iAccount = (int) $temp; |
1104 | } else { |
1105 | $iAccount = 0; |
1106 | } |
1107 | |
1108 | /** |
1109 | * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates |
1110 | */ |
1111 | $sTplDir = SM_PATH . 'templates/default/'; |
1112 | |
1113 | |
324ac3c5 |
1114 | /** |
1115 | * Incoming submit buttons from the message list with search results |
1116 | */ |
1117 | if (sqgetGlobalVar('moveButton', $moveButton, SQ_POST) || |
1118 | sqgetGlobalVar('expungeButton', $expungeButton, SQ_POST) || |
1119 | sqgetGlobalVar('delete', $markDelete, SQ_POST) || |
1120 | sqgetGlobalVar('undeleteButton', $undeleteButton, SQ_POST) || |
1121 | sqgetGlobalVar('markRead', $markRead, SQ_POST) || |
1122 | sqgetGlobalVar('markUnread', $markUnread, SQ_POST) || |
1123 | sqgetGlobalVar('markFlagged', $markFlagged, SQ_POST) || |
1124 | sqgetGlobalVar('markUnflagged', $markUnflagged, SQ_POST) || |
1125 | sqgetGlobalVar('attache', $attache, SQ_POST)) { |
1126 | asearch_edit_last(1); |
1127 | $submit = ''; |
1128 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
1129 | } |
1130 | |
1131 | |
6b37252b |
1132 | |
7d60bda5 |
1133 | /** Toggle show/hide saved searches |
134e4174 |
1134 | */ |
324ac3c5 |
1135 | if (sqgetGlobalVar('search_show_saved', $search_show_saved, SQ_GET)) { |
8cc8ec79 |
1136 | setPref($data_dir, $username, 'search_show_saved', $search_show_saved & 1); |
324ac3c5 |
1137 | } |
7d60bda5 |
1138 | /** Toggle show/hide recent searches |
134e4174 |
1139 | */ |
324ac3c5 |
1140 | if (sqgetGlobalVar('search_show_recent', $search_show_recent, SQ_GET)) { |
8cc8ec79 |
1141 | setPref($data_dir, $username, 'search_show_recent', $search_show_recent & 1); |
324ac3c5 |
1142 | } |
7d60bda5 |
1143 | // end of get globals |
6b37252b |
1144 | |
40fbe929 |
1145 | /** If TRUE, do not show search interface |
134e4174 |
1146 | * Default FALSE |
1147 | * @global bool $search_silent |
1148 | */ |
7d60bda5 |
1149 | $search_silent = FALSE; |
6b37252b |
1150 | |
1151 | /* See how the page was called and fire off correct function */ |
7d60bda5 |
1152 | if ((empty($submit)) && (!empty($where_array))) { |
8cc8ec79 |
1153 | /* This happens when the Enter key is used or called from outside */ |
1154 | $submit = $search_button_text; |
324ac3c5 |
1155 | /* Hack needed to handle coming back from read_body et als */ |
1156 | if (count($where_array) != count($unop_array)) { |
1157 | /** |
1158 | * Hack to use already existen where and what vars. |
1159 | * where now contains the initiator page of the messagelist |
1160 | * and in this case 'search'. what contains an index to access |
1161 | * the search history |
1162 | */ |
1163 | |
1164 | sqgetGlobalVar('what',$what,SQ_GET); |
1165 | asearch_edit_last($what); |
1166 | } |
56e0b3b7 |
1167 | } |
6b37252b |
1168 | |
1169 | if (!isset($submit)) { |
8cc8ec79 |
1170 | $submit = ''; |
324ac3c5 |
1171 | } else { |
8cc8ec79 |
1172 | switch ($submit) { |
324ac3c5 |
1173 | case $search_button_text: |
1174 | if (asearch_check_query($where_array, $what_array, $exclude_array) == '') { |
1175 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
1176 | } |
8cc8ec79 |
1177 | break; |
324ac3c5 |
1178 | case 'Search_silent': |
1179 | $search_silent = TRUE; |
8cc8ec79 |
1180 | /*nobreak;*/ |
324ac3c5 |
1181 | case 'Search_no_update': |
1182 | $submit = $search_button_text; |
8cc8ec79 |
1183 | break; |
324ac3c5 |
1184 | case $del_excluded_button_text: |
1185 | $delarray = array_keys($exclude_array); |
1186 | while (!empty($delarray)) { |
1187 | $delrow = array_pop($delarray); |
1188 | array_splice($mailbox_array, $delrow, 1); |
1189 | array_splice($biop_array, $delrow, 1); |
1190 | array_splice($unop_array, $delrow, 1); |
1191 | array_splice($where_array, $delrow, 1); |
1192 | array_splice($what_array, $delrow, 1); |
134e4174 |
1193 | /* array_splice($exclude_array, $delrow, 1);*/ /* There is still some php magic that eludes me */ |
324ac3c5 |
1194 | array_splice($sub_array, $delrow, 1); |
1195 | } |
1196 | $exclude_array = array(); |
8cc8ec79 |
1197 | break; |
324ac3c5 |
1198 | case $del_all_button_text: |
1199 | $mailbox_array = array(); |
1200 | $biop_array = array(); |
1201 | $unop_array = array(); |
1202 | $where_array = array(); |
1203 | $what_array = array(); |
1204 | $exclude_array = array(); |
1205 | $sub_array = array(); |
8cc8ec79 |
1206 | break; |
324ac3c5 |
1207 | case 'save_recent': |
1208 | asearch_save_recent($submit_rownum); |
8cc8ec79 |
1209 | break; |
324ac3c5 |
1210 | case 'search_recent': |
1211 | $submit = $search_button_text; |
1212 | asearch_edit_recent($submit_rownum); |
1213 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
8cc8ec79 |
1214 | break; |
134e4174 |
1215 | case 'edit_recent': /* no link to do this, yet */ |
324ac3c5 |
1216 | asearch_edit_recent($submit_rownum); |
8cc8ec79 |
1217 | break; |
324ac3c5 |
1218 | case 'forget_recent': |
1219 | asearch_forget_recent($submit_rownum); |
8cc8ec79 |
1220 | break; |
324ac3c5 |
1221 | case 'search_saved': |
1222 | $submit = $search_button_text; |
1223 | asearch_edit_saved($submit_rownum); |
1224 | asearch_push_recent($mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
8cc8ec79 |
1225 | break; |
324ac3c5 |
1226 | case 'edit_saved': |
1227 | asearch_edit_saved($submit_rownum); |
8cc8ec79 |
1228 | break; |
324ac3c5 |
1229 | case 'delete_saved': |
1230 | asearch_delete_saved($submit_rownum); |
8cc8ec79 |
1231 | break; |
1232 | } |
56e0b3b7 |
1233 | } |
23a9084b |
1234 | |
7d60bda5 |
1235 | //Texts in both basic and advanced form |
1236 | $imap_asearch_unops = array( |
8cc8ec79 |
1237 | '' => '', |
1238 | 'NOT' => _("Not") |
7d60bda5 |
1239 | ); |
1240 | |
1241 | if ($search_advanced) { |
8cc8ec79 |
1242 | //Texts in advanced form only |
1243 | $imap_asearch_options = array( |
1244 | //<message set>, |
1245 | //'ALL' is binary operator |
1246 | 'ANSWERED' => _("Answered"), |
1247 | 'BCC' => _("Bcc"), |
1248 | 'BEFORE' => _("Before"), |
1249 | 'BODY' => _("Message Body"), |
48027e89 |
1250 | 'CC' => _("Cc"), |
8cc8ec79 |
1251 | 'DELETED' => _("Deleted"), |
1252 | 'DRAFT' => _("Draft"), |
1253 | 'FLAGGED' => _("Flagged"), |
1254 | 'FROM' => _("Sent By"), |
1255 | 'HEADER' => _("Header Field"), |
1256 | 'KEYWORD' => _("Keyword"), |
1257 | 'LARGER' => _("Larger Than"), |
1258 | 'NEW' => _("New"), |
1259 | //'NOT' is unary operator |
1260 | 'OLD' => _("Old"), |
1261 | 'ON' => _("On"), |
1262 | //'OR' is binary operator |
1263 | 'RECENT' => _("Recent"), |
1264 | 'SEEN' => _("Seen"), |
1265 | 'SENTBEFORE' => _("Sent Before"), |
1266 | 'SENTON' => _("Sent On"), |
1267 | 'SENTSINCE' => _("Sent Since"), |
1268 | 'SINCE' => _("Since"), |
1269 | 'SMALLER' => _("Smaller Than"), |
1270 | 'SUBJECT' => _("Subject Contains"), |
1271 | 'TEXT' => _("Header and Body"), |
1272 | 'TO' => _("Sent To"), |
1273 | //'UID' => 'anum', |
134e4174 |
1274 | /* 'UNANSWERED' => '', |
8cc8ec79 |
1275 | 'UNDELETED' => '', |
1276 | 'UNDRAFT' => '', |
1277 | 'UNFLAGGED' => '', |
1278 | 'UNKEYWORD' => _("Unkeyword"), |
1279 | 'UNSEEN' => _("Unseen"),*/ |
1280 | ); |
1281 | |
1282 | $imap_asearch_biops_in = array( |
1283 | 'ALL' => _("And In"), |
1284 | 'OR' => _("Or In") |
1285 | ); |
1286 | |
1287 | $imap_asearch_biops = array( |
1288 | 'ALL' => _("And"), |
1289 | 'OR' => _("Or") |
1290 | ); |
324ac3c5 |
1291 | } else { |
8cc8ec79 |
1292 | //Texts in basic form only |
1293 | $imap_asearch_options = array( |
1294 | 'BCC' => _("Bcc"), |
1295 | 'BODY' => _("Body"), |
1296 | 'CC' => _("Cc"), |
1297 | 'FROM' => _("From"), |
1298 | 'SUBJECT' => _("Subject"), |
1299 | 'TEXT' => _("Everywhere"), |
1300 | 'TO' => _("To"), |
1301 | ); |
7d60bda5 |
1302 | } |
1303 | |
1304 | uasort($imap_asearch_options, 'asearch_unhtml_strcoll'); |
1305 | |
6b37252b |
1306 | /* open IMAP connection */ |
1307 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
324ac3c5 |
1308 | |
1309 | |
5b6abe97 |
1310 | /* get mailboxes once here */ |
6b37252b |
1311 | $boxes = sqimap_mailbox_list($imapConnection); |
99f3175e |
1312 | /* ensure we have a valid default mailbox name */ |
edda50ae |
1313 | $mailbox = asearch_nz($mailbox_array[0]); |
134e4174 |
1314 | if (($mailbox == '') || ($mailbox == 'None')) //Workaround for sm quirk IMHO (what if I really have a mailbox called None?) |
1315 | $mailbox = $boxes[0]['unformatted']; //Usually INBOX ;) |
99f3175e |
1316 | |
91c27aee |
1317 | |
1318 | /** |
1319 | * Handle form actions like flag / unflag, seen / unseen, delete |
1320 | */ |
1321 | if (sqgetGlobalVar('mailbox',$postMailbox,SQ_POST)) { |
1322 | if ($postMailbox) { |
1323 | /** |
1324 | * system wide admin settings and incoming vars. |
1325 | */ |
1326 | $aConfig = array( |
1327 | 'user' => $username, |
1328 | ); |
1329 | $aConfig['setindex'] = 1; // $what $where = 'search' |
1330 | /** |
1331 | * Set the max cache size to the number of mailboxes to avoid cache cleanups |
1332 | * when searching all mailboxes |
1333 | */ |
1334 | $aConfig['max_cache_size'] = count($boxes) +1; |
1335 | |
1336 | $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $postMailbox,$aConfig,array()); |
1337 | $sError = handleMessageListForm($imapConnection,$aMailbox); |
1338 | /* add the mailbox to the cache */ |
1339 | $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; |
1340 | |
1341 | if ($sError) { |
1342 | $note = $sError; |
1343 | } |
1344 | } |
1345 | } |
1346 | |
1347 | if (isset($aMailbox['FORWARD_SESSION'])) { |
1348 | /* add the mailbox to the cache */ |
1349 | $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; |
1350 | sqsession_register($mailbox_cache,'mailbox_cache'); |
1351 | |
1352 | if ($compose_new_win) { |
1353 | // write the session in order to make sure that the compose window has |
1354 | // access to the composemessages array which is stored in the session |
1355 | session_write_close(); |
8517e764 |
1356 | // restart the session. Do not use sqsession_is_active because the session_id |
1357 | // isn't empty after a session_write_close |
3a1de9f1 |
1358 | sqsession_start(); |
91c27aee |
1359 | |
1360 | if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { |
1361 | $compose_width = '640'; |
1362 | } |
1363 | if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { |
1364 | $compose_height = '550'; |
1365 | } |
1366 | // do not use &, it will break the query string and $session will not be detected!!! |
1367 | $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
1368 | '&session='.$aMailbox['FORWARD_SESSION']; |
1369 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", false); |
1370 | } else { |
1371 | // save mailboxstate |
1372 | sqsession_register($aMailbox,'aLastSelectedMailbox'); |
1373 | session_write_close(); |
1374 | // we have to redirect to the compose page |
1375 | $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
1376 | '&session='.$aMailbox['FORWARD_SESSION']; |
1377 | header("Location: $location"); |
1378 | exit; |
1379 | } |
324ac3c5 |
1380 | } else { |
8cc8ec79 |
1381 | displayPageHeader($color, $mailbox); |
91c27aee |
1382 | // $compose_uri = $base_uri.'src/compose.php?newmessage=1'; |
1383 | } |
1384 | |
1385 | if (isset($note)) { |
a6d3eff6 |
1386 | echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n"; |
324ac3c5 |
1387 | } |
91c27aee |
1388 | |
1389 | |
6b37252b |
1390 | do_hook('search_before_form'); |
d81e351b |
1391 | |
6b37252b |
1392 | if (!$search_silent) { |
8cc8ec79 |
1393 | //Add a link to the other search mode if allowed |
1394 | if ($allow_advanced_search > 1) |
1395 | $toggle_link = ' - <small>[' |
1396 | . asearch_get_toggle_link(!$search_advanced, 'advanced', array(_("Standard search"), _("Advanced search"))) |
1397 | . ']</small>'; |
1398 | else |
1399 | $toggle_link = ''; |
1400 | |
1401 | echo html_tag('table', |
1402 | html_tag('tr', "\n" |
1403 | . html_tag('td', asearch_get_title_display($color, _("Search")) . $toggle_link, 'center', $color[0]) |
1404 | ) , |
1405 | '', '', 'width="100%"') . "\n"; |
1406 | asearch_print_saved($boxes); |
1407 | asearch_print_recent($boxes); |
1408 | if (empty($where_array)) { |
1409 | global $sent_folder; |
1410 | |
1411 | $mailbox_array[0] = $mailbox; |
1412 | $biop_array[0] = ''; |
1413 | $unop_array[0] = ''; |
324ac3c5 |
1414 | if ($mailbox == $sent_folder) { |
8cc8ec79 |
1415 | $where_array[0] = 'TO'; |
324ac3c5 |
1416 | } else { |
8cc8ec79 |
1417 | $where_array[0] = 'FROM'; |
324ac3c5 |
1418 | } |
8cc8ec79 |
1419 | $what_array[0] = ''; |
1420 | $exclude_array[0] = ''; |
1421 | $sub_array[0] = ''; |
1422 | } |
1423 | //Display advanced or basic form |
1424 | if ($search_advanced) { |
1425 | if ($submit == $add_criteria_button_text) { |
1426 | $last_index = max(count($where_array) - 1, 0); |
1427 | $mailbox_array[] = asearch_nz($mailbox_array[$last_index]); |
1428 | $biop_array[] = asearch_nz($biop_array[$last_index]); |
1429 | $unop_array[] = asearch_nz($unop_array[$last_index]); |
1430 | $where_array[] = asearch_nz($where_array[$last_index]); |
1431 | $what_array[] = asearch_nz($what_array[$last_index]); |
1432 | $exclude_array[] = asearch_nz($exclude_array[$last_index]); |
1433 | $sub_array[] = asearch_nz($sub_array[$last_index]); |
1434 | } |
1435 | asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
324ac3c5 |
1436 | } else { |
8cc8ec79 |
1437 | asearch_print_form_basic($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array); |
324ac3c5 |
1438 | } |
6b37252b |
1439 | } |
1440 | |
88cb1b4d |
1441 | do_hook('search_after_form'); |
56e0b3b7 |
1442 | |
6b37252b |
1443 | if ($submit == $search_button_text) { |
a73ae1c2 |
1444 | $msgsfound = false; |
8cc8ec79 |
1445 | echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"'); |
1446 | echo html_tag('tr', html_tag('td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5])); |
1447 | 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])); |
1448 | echo '</table>' . "\n"; |
1449 | |
1450 | flush(); |
e09e556f |
1451 | $iMsgCnt = 0; |
8cc8ec79 |
1452 | $query_error = asearch_check_query($where_array, $what_array, $exclude_array); |
324ac3c5 |
1453 | if ($query_error != '') { |
8cc8ec79 |
1454 | echo '<br />' . html_tag('div', asearch_get_error_display($color, $query_error), 'center') . "\n"; |
324ac3c5 |
1455 | } else { |
8cc8ec79 |
1456 | $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes); |
324ac3c5 |
1457 | /** |
1458 | * Retrieve the search queries |
1459 | */ |
1460 | $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array); |
1461 | foreach($mboxes_mailbox as $mbx => $search) { |
324ac3c5 |
1462 | |
91c27aee |
1463 | /** |
1464 | * until there is no per mailbox option screen to set prefs we override |
1465 | * the mailboxprefs by the default ones |
1466 | */ |
1467 | |
1468 | $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$iAccount.'_'.$mbx); |
324ac3c5 |
1469 | if ($aMailboxPrefSer) { |
1470 | $aMailboxPref = unserialize($aMailboxPrefSer); |
91c27aee |
1471 | $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; |
324ac3c5 |
1472 | } else { |
91c27aee |
1473 | setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($default_mailbox_pref)); |
1474 | $aMailboxPref = $default_mailbox_pref; |
8cc8ec79 |
1475 | } |
324ac3c5 |
1476 | if (isset($srt) && $targetmailbox == $mbx) { |
1477 | $aMailboxPref[MBX_PREF_SORT] = (int) $srt; |
1478 | } |
91c27aee |
1479 | |
1480 | $trash_folder = (isset($trash_folder)) ? $trash_folder : false; |
1481 | $sent_folder = (isset($sent_folder)) ? $sent_folder : false; |
1482 | $draft_folder = (isset($draft_folder)) ? $draft_folder : false; |
1483 | |
324ac3c5 |
1484 | |
1485 | /** |
1486 | * until there is no per mailbox option screen to set prefs we override |
1487 | * the mailboxprefs by the default ones |
1488 | */ |
1489 | $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num; |
1490 | $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge; |
1491 | $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort'); |
91c27aee |
1492 | $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; |
1493 | |
1494 | /** |
1495 | * Replace From => To in case it concerns a draft or sent folder |
1496 | */ |
1497 | if (($mbx == $sent_folder || $mbx == $draft_folder) && |
1498 | !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) { |
1499 | $aNewOrder = array(); // nice var name ;) |
1500 | foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) { |
1501 | if ($iCol == SQM_COL_FROM) { |
1502 | $iCol = SQM_COL_TO; |
1503 | } |
1504 | $aNewOrder[] = $iCol; |
1505 | } |
1506 | $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder; |
f16dc830 |
1507 | setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref)); |
91c27aee |
1508 | } |
324ac3c5 |
1509 | |
324ac3c5 |
1510 | $aConfig['search'] = $search['search']; |
1511 | $aConfig['charset'] = $search['charset']; |
324ac3c5 |
1512 | |
324ac3c5 |
1513 | /** |
91c27aee |
1514 | * Set the max cache size to the number of mailboxes to avoid cache cleanups |
1515 | * when searching all mailboxes |
1516 | */ |
1517 | $aConfig['max_cache_size'] = count($mboxes_mailbox) +1; |
1518 | if (isset($startMessage) && $targetmailbox == $mbx) { |
1519 | $aConfig['offset'] = $startMessage; |
e09e556f |
1520 | } else { |
1521 | $aConfig['offset'] = 0; |
91c27aee |
1522 | } |
1523 | if (isset($showall) && $targetmailbox == $mbx) { |
1524 | $aConfig['showall'] = $showall; |
1525 | } else { |
1526 | if (isset($aConfig['showall'])) { |
1527 | unset($aConfig['showall']); |
1528 | } |
1529 | $showall = false; |
1530 | } |
1531 | |
1532 | /** |
1533 | * Set the config options for the messages list |
324ac3c5 |
1534 | */ |
91c27aee |
1535 | $aColumns = array(); |
1536 | foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) { |
1537 | $aColumns[$iCol] = array(); |
1538 | switch ($iCol) { |
1539 | case SQM_COL_SUBJ: |
1540 | if ($truncate_subject) { |
1541 | $aColumns[$iCol]['truncate'] = $truncate_subject; |
1542 | } |
1543 | break; |
1544 | case SQM_COL_FROM: |
1545 | case SQM_COL_TO: |
1546 | case SQM_COL_CC: |
1547 | case SQM_COL_BCC: |
1548 | if ($truncate_sender) { |
1549 | $aColumns[$iCol]['truncate'] = $truncate_sender; |
1550 | } |
1551 | break; |
324ac3c5 |
1552 | } |
1553 | } |
91c27aee |
1554 | |
1555 | |
1556 | $aProps = array( |
1557 | 'columns' => $aColumns, |
1558 | 'config' => array('alt_index_colors' => $alt_index_colors, |
1559 | 'highlight_list' => $message_highlight_list, |
1560 | 'fancy_index_highlite' => $fancy_index_highlite, |
1561 | 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true, |
1562 | 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', |
1563 | 'trash_folder' => $trash_folder, |
1564 | 'sent_folder' => $sent_folder, |
1565 | 'draft_folder' => $draft_folder, |
1566 | 'enablesort' => true, |
1567 | 'color' => $color |
1568 | ), |
1569 | 'mailbox' => $mbx, |
1570 | 'account' => (isset($iAccount)) ? $iAccount : 0, |
1571 | 'module' => 'read_body', |
1572 | 'email' => false); |
1573 | |
1574 | |
1575 | $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref); |
1576 | |
1577 | $iError = 0; |
1578 | $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError); |
e09e556f |
1579 | |
1580 | // in th future we can make use of multiple message sets, now set it to 1 for search. |
1581 | $iSetIndex = 1; |
1582 | if (isset($aMailbox['UIDSET'][$iSetIndex])) { |
1583 | $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]); |
1584 | } |
91c27aee |
1585 | if ($iError) { |
1586 | // error handling |
1587 | } else { |
1588 | /** |
1589 | * In the future, move this the the initialisation area |
1590 | */ |
1591 | sqgetGlobalVar('align',$align,SQ_SESSION); |
1592 | |
1593 | $oTemplate = new Template($sTplDir); |
1594 | |
1595 | if ($aMailbox['EXISTS'] > 0) { |
91c27aee |
1596 | if ($iError) { |
e09e556f |
1597 | // TODO |
1598 | echo "ERROR occured, errorhandler will be implemented very soon"; |
91c27aee |
1599 | } else { |
e09e556f |
1600 | foreach ($aTemplate as $k => $v) { |
1601 | $oTemplate->assign($k, $v); |
1602 | } |
29997535 |
1603 | |
e09e556f |
1604 | $oTemplate->assign('page_selector', $page_selector); |
1605 | $oTemplate->assign('page_selector_max', $page_selector_max); |
1606 | $oTemplate->assign('compact_paginator', $compact_paginator); |
1607 | $oTemplate->assign('javascript_on', $javascript_on); |
1608 | $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false); |
29997535 |
1609 | $oTemplate->assign('icon_theme_path', $icon_theme_path); |
e09e556f |
1610 | $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false); |
1611 | $oTemplate->assign('aOrder', array_keys($aColumns)); |
1612 | $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false); |
1613 | $oTemplate->assign('color', $color); |
1614 | $oTemplate->assign('align', $align); |
e09e556f |
1615 | |
1616 | $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']); |
1617 | if (strtoupper($mbx) == 'INBOX') { |
1618 | $mailbox_display = _("INBOX"); |
1619 | } else { |
1620 | $mailbox_display = imap_utf7_decode_local($mbx); |
1621 | } |
91c27aee |
1622 | |
fa62b054 |
1623 | echo '<br /><b><big>' . _("Folder:") . ' '. htmlspecialchars($mailbox_display) . ' </big></b>'; |
91c27aee |
1624 | |
e09e556f |
1625 | $oTemplate->display('message_list.tpl'); |
1626 | } |
91c27aee |
1627 | } |
a73ae1c2 |
1628 | } |
91c27aee |
1629 | |
324ac3c5 |
1630 | /* add the mailbox to the cache */ |
91c27aee |
1631 | $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; |
8cc8ec79 |
1632 | |
324ac3c5 |
1633 | } |
8cc8ec79 |
1634 | } |
e09e556f |
1635 | if(!$iMsgCnt) { |
a73ae1c2 |
1636 | echo '<br />' . html_tag('div', asearch_get_error_display($color, _("No Messages Found")), 'center') . "\n"; |
1637 | } |
56e0b3b7 |
1638 | } |
1639 | |
70c4fd84 |
1640 | do_hook('search_bottom'); |
6b37252b |
1641 | sqimap_logout($imapConnection); |
5c4ff7bf |
1642 | $oTemplate->display('footer.tpl'); |
324ac3c5 |
1643 | sqsession_register($mailbox_cache,'mailbox_cache'); |
a2b193bc |
1644 | |
fa62b054 |
1645 | ?> |