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