- echo html_tag( 'table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"' );
- echo html_tag( 'tr', html_tag( 'td', asearch_get_title_display($color, _("Search Results")), 'center', $color[5]));
- echo html_tag( 'tr', html_tag( 'td', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array), 'center', $color[4]));
- echo '</table><br>' . "\n";
-
- $query_error = asearch_check_query($where_array, $what_array, $exclude_array);
- if ($query_error != '')
- echo '<br>' . html_tag( 'div', asearch_get_error_display($color, $query_error), 'center' ) . "\n";
- else {
- $old_allow_thread_sort = 0;
- if ($allow_thread_sort == TRUE) {
- $old_allow_thread_sort = $allow_thread_sort;
- $allow_thread_sort = FALSE;
- }
-
- $boxcount = count($boxes);
- for ($boxnum=0; $boxnum<$boxcount; $boxnum++) {
- if (!in_array('noselect', $boxes[$boxnum]['flags']))
- $mboxes_array[] = $boxes[$boxnum]['unformatted'];
- }
-
- $mboxes_msgs = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $mboxes_array);
- if (empty($mboxes_msgs))
- echo '<br>' . html_tag( 'div', asearch_get_error_display($color, _("No Messages Found")), 'center' ) . "\n";
- else {
- foreach($mboxes_msgs as $mailbox => $msgs) {
- sqimap_mailbox_select($imapConnection, $mailbox);
- $msgs = fillMessageArray($imapConnection, $msgs, count($msgs));
-/* For now just keep the first criteria to make the regular search happy if the user tries to come back to search */
-/* $where = asearch_serialize($where_array);
- $what = asearch_serialize($what_array);*/
- $where = $where_array[0];
- $what = $what_array[0];
- asearch_print_mailbox_msgs($msgs, $mailbox, count($msgs), $imapConnection, urlencode($where), urlencode($what), false, false);
- }
- }
-
- $allow_thread_sort = $old_allow_thread_sort;
- }
-}
-
-
-do_hook('search_bottom');
+ $msgsfound = false;
+
+ $err = asearch_check_query($where_array, $what_array, $exclude_array);
+
+ $oTemplate->assign('query_has_error', $err!='');
+ $oTemplate->assign('query_error', $err=='' ? NULL : $err);
+ $oTemplate->assign('query', asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array));
+
+ $oTemplate->display('search_result_top.tpl');
+
+ flush();
+ $iMsgCnt = 0;
+ if ($err == '') {
+ $mboxes_array = sqimap_asearch_get_selectable_unformatted_mailboxes($boxes);
+ /**
+ * Retrieve the search queries
+ */
+ $mboxes_mailbox = sqimap_asearch($imapConnection, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array, $mboxes_array);
+ foreach($mboxes_mailbox as $mbx => $search) {
+
+ /**
+ * until there is no per mailbox option screen to set prefs we override
+ * the mailboxprefs by the default ones
+ */
+
+ $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$iAccount.'_'.$mbx);
+ if ($aMailboxPrefSer) {
+ $aMailboxPref = unserialize($aMailboxPrefSer);
+ $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
+ } else {
+ setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($default_mailbox_pref));
+ $aMailboxPref = $default_mailbox_pref;
+ }
+ if (isset($srt) && $targetmailbox == $mbx) {
+ $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
+ }
+
+ $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
+ $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
+ $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
+
+
+ /**
+ * until there is no per mailbox option screen to set prefs we override
+ * the mailboxprefs by the default ones
+ */
+ $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
+ $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
+ $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
+ $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
+
+ /**
+ * Replace From => To in case it concerns a draft or sent folder
+ */
+ if (($mbx == $sent_folder || $mbx == $draft_folder) &&
+ !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
+ $aNewOrder = array(); // nice var name ;)
+ foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
+ if ($iCol == SQM_COL_FROM) {
+ $iCol = SQM_COL_TO;
+ }
+ $aNewOrder[] = $iCol;
+ }
+ $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
+ setUserPref($username,'pref_'.$iAccount.'_'.$mbx,serialize($aMailboxPref));
+ }
+
+ $aConfig['search'] = $search['search'];
+ $aConfig['charset'] = $search['charset'];
+
+ /**
+ * Set the max cache size to the number of mailboxes to avoid cache cleanups
+ * when searching all mailboxes
+ */
+ $aConfig['max_cache_size'] = count($mboxes_mailbox) +1;
+ if (isset($startMessage) && $targetmailbox == $mbx) {
+ $aConfig['offset'] = $startMessage;
+ } else {
+ $aConfig['offset'] = 0;
+ }
+ if (isset($showall) && $targetmailbox == $mbx) {
+ $aConfig['showall'] = $showall;
+ } else {
+ if (isset($aConfig['showall'])) {
+ unset($aConfig['showall']);
+ }
+ $showall = false;
+ }
+
+ /**
+ * Set the config options for the messages list
+ */
+ $aColumns = array();
+ foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
+ $aColumns[$iCol] = array();
+ switch ($iCol) {
+ case SQM_COL_SUBJ:
+ if ($truncate_subject) {
+ $aColumns[$iCol]['truncate'] = $truncate_subject;
+ }
+ break;
+ case SQM_COL_FROM:
+ case SQM_COL_TO:
+ case SQM_COL_CC:
+ case SQM_COL_BCC:
+ if ($truncate_sender) {
+ $aColumns[$iCol]['truncate'] = $truncate_sender;
+ }
+ break;
+ }
+ }
+
+
+ $aProps = array(
+ 'columns' => $aColumns,
+ 'config' => array('alt_index_colors' => $alt_index_colors,
+ 'highlight_list' => $message_highlight_list,
+ 'fancy_index_highlite' => $fancy_index_highlite,
+ 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
+ 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '',
+ 'trash_folder' => $trash_folder,
+ 'sent_folder' => $sent_folder,
+ 'draft_folder' => $draft_folder,
+ 'enablesort' => true,
+ 'color' => $color
+ ),
+ 'mailbox' => $mbx,
+ 'account' => (isset($iAccount)) ? $iAccount : 0,
+ 'module' => 'read_body',
+ 'email' => false);
+
+
+ $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mbx,$aConfig,$aMailboxPref);
+
+ $iError = 0;
+ $aTemplate = showMessagesForMailbox($imapConnection, $aMailbox,$aProps, $iError);
+
+ // in th future we can make use of multiple message sets, now set it to 1 for search.
+ $iSetIndex = 1;
+ if (isset($aMailbox['UIDSET'][$iSetIndex])) {
+ $iMsgCnt += count($aMailbox['UIDSET'][$iSetIndex]);
+ }
+ if ($iError) {
+ // error handling
+ } else {
+ /**
+ * In the future, move this the the initialisation area
+ */
+ sqgetGlobalVar('align',$align,SQ_SESSION);
+
+ /**
+ * TODO: Clean up handling of message list once the template is cleaned up.
+ */
+ if ($aMailbox['EXISTS'] > 0) {
+ if ($iError) {
+ // TODO
+ echo "ERROR occured, errorhandler will be implemented very soon";
+ } else {
+ foreach ($aTemplate as $k => $v) {
+ $oTemplate->assign($k, $v);
+ }
+
+ $mailbox_display = asearch_get_mailbox_display($aMailbox['NAME']);
+ if (strtoupper($mbx) == 'INBOX') {
+ $mailbox_display = _("INBOX");
+ } else {
+ $mailbox_display = imap_utf7_decode_local($mbx);
+ }
+
+ $oTemplate->assign('mailbox_name', htmlspecialchars($mailbox_display));
+ $oTemplate->display('search_result_mailbox.tpl');
+
+ $oTemplate->assign('page_selector', $page_selector);
+ $oTemplate->assign('page_selector_max', $page_selector_max);
+ $oTemplate->assign('compact_paginator', $compact_paginator);
+ $oTemplate->assign('javascript_on', checkForJavascript());
+ $oTemplate->assign('base_uri', sqm_baseuri());
+ $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
+ $oTemplate->assign('icon_theme_path', $icon_theme_path);
+ $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
+ $oTemplate->assign('aOrder', array_keys($aColumns));
+ $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
+ $oTemplate->assign('color', $color);
+ $oTemplate->assign('align', $align);
+ $oTemplate->assign('checkall', $checkall);
+ $oTemplate->assign('preselected', $preselected);
+
+ global $show_personal_names;
+ $oTemplate->assign('show_personal_names', $show_personal_names);
+
+ global $accesskey_mailbox_toggle_selected, $accesskey_mailbox_thread;
+ $oTemplate->assign('accesskey_mailbox_toggle_selected', $accesskey_mailbox_toggle_selected);
+ $oTemplate->assign('accesskey_mailbox_thread', $accesskey_mailbox_thread);
+
+ $oTemplate->display('message_list.tpl');
+ }
+ }
+ }
+
+ /* add the mailbox to the cache */
+ $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
+
+ }
+ }
+ if(!$iMsgCnt) {
+ $oTemplate->display('search_result_empty.tpl');
+ }
+}
+
+do_hook('search_bottom', $null);