+
+ if ($saved_count > 0) {
+ $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete"));
+ asearch_print_query_array($saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"));
+ }
+}
+
+/* print the recent array */
+function asearch_print_recent($data_dir, $username)
+{
+ global $recent_prefkeys;
+
+ $recent_array = asearch_read_recent($data_dir, $username);
+ if (isset($recent_array[$recent_prefkeys[0]])) {
+ $recent_count = count($recent_array[$recent_prefkeys[0]]);
+ } else {
+ $recent_count = 0;
+ }
+ $recent_max = min($recent_count, getPref($data_dir, $username, 'search_memory', 0));
+ if ($recent_max > 0) {
+ $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget"));
+ asearch_print_query_array($recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"));
+ }
+}
+
+/* build an <option> stuff */
+function asearch_opt( $val, $sel, $tit )
+{
+ return '<option value="' . $val . '"' . ($sel == $val ? ' selected' : '' ) . '>' . $tit . '</option>' . "\n";
+}
+
+/* build a <select> stuff from an array */
+function asearch_opt_array($var_name, $opt_array, $cur_val)
+{
+ $output = '<select name="' . $var_name . '">' . "\n";
+ foreach($opt_array as $val => $display)
+ $output .= asearch_opt($val, $cur_val, $display);
+ $output .= '</select>' . "\n";
+ return $output;
+}
+
+/* print one form row */
+function asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $rownum)
+{
+ global $imap_asearch_biops_in, $imap_asearch_unops, $imap_asearch_options;
+ global $color;
+
+ echo html_tag( 'tr', '', '', /*($rownum%2 ? $color[0] :*/ $color[4]/*)*/ );
+
+ echo html_tag( 'td', '', 'center' );
+/* Binary operator */
+ if ($rownum)
+ echo asearch_opt_array('biop[' . $rownum . ']', $imap_asearch_biops_in, $biop);
+ else
+ echo /*'<input type="hidden" name="biop[0]" value="">' .*/ '<b>' . _("In") . '</b>';
+ echo "</td>\n";
+
+ echo html_tag( 'td', '', 'center' );
+/* Mailbox list */
+ echo '<select name="mailbox[' . $rownum . ']">' . '<option value="All Folders"';
+ if ($mailbox == 'All Folders')
+ echo ' selected';
+ echo '>[ ' . asearch_get_mailbox_display('All Folders') . " ]</option>\n";
+ echo sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes);
+ echo '</select></td>' . "\n";
+
+/* Unary operator and Search location */
+ if (empty($where))
+ $where = 'FROM';
+ echo html_tag( 'td',
+ asearch_opt_array('unop[' . $rownum . ']', $imap_asearch_unops, $unop)
+ . asearch_opt_array('where[' . $rownum . ']', $imap_asearch_options, $where),
+ 'center');
+
+/* Text input */
+/* This is the original stuff. Except it doesn't work (eg commas are lost), why so much trouble?
+ $what_disp = str_replace(',', ' ', $what);
+ $what_disp = str_replace('\\\\', '\\', $what_disp);
+ $what_disp = str_replace('\\"', '"', $what_disp);
+ $what_disp = str_replace('"', '"', $what_disp);*/
+ $what_disp = htmlspecialchars($what, ENT_QUOTES);
+ echo html_tag( 'td', '<input type="text" size="35" name="what[' . $rownum . ']" value="' . $what_disp . '">', 'center' ) . "\n";
+
+/* Exclude criteria */
+ echo html_tag( 'td',
+ _("Exclude Criteria:") . '<input type=checkbox name="exclude[' . $rownum .']"' . ($exclude ? ' CHECKED' : '') . '>', 'center', '') . "\n";
+
+ echo "</tr>\n";
+}
+
+/* print the search form */
+function asearch_print_form($imapConnection, $boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $add_criteria)
+{
+ global $search_button_html, $add_criteria_button_html, $del_excluded_button_html, $del_all_button_html;
+ global $color;
+
+ /* Search Form */
+ echo "<br>\n";
+ echo '<form action="search.php" name="form_asearch">' . "\n";
+
+ echo html_tag( 'table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="1" border="0"' );
+ echo html_tag( 'tr', html_tag( 'td', asearch_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5'));
+ $row_count = count($where_array) + $add_criteria;
+ $mailbox = '';
+ for ($row_num = 0; $row_num < $row_count; $row_num++) {
+ /* Keep the last non-empty mailbox as default choice */
+ if (strip_tags(asearch_nz($mailbox_array[$row_num])) != '')
+ $mailbox = strip_tags($mailbox_array[$row_num]);
+ if ($mailbox == '')
+ $mailbox = $boxes[0]['unformatted'];
+ $biop = strip_tags(asearch_nz($biop_array[$row_num]));
+ $unop = strip_tags(asearch_nz($unop_array[$row_num]));
+ $where = strip_tags(asearch_nz($where_array[$row_num]));
+ $what = asearch_nz($what_array[$row_num]);
+ $exclude = strip_tags(asearch_nz($exclude_array[$row_num]));
+ asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $row_num);
+ }
+ echo '</table>' . "\n";
+
+/* Submit buttons */
+ echo html_tag('table', '', 'center', $color[9], 'width="100%" cellpadding="1" cellspacing="0" border="0"' );
+ echo html_tag('tr',
+ html_tag('td', getButton('SUBMIT', 'submit', $search_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $add_criteria_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $del_all_button_html), 'center') . "\n"
+ . html_tag('td', getButton('SUBMIT', 'submit', $del_excluded_button_html), 'center') . "\n"
+ );
+ echo '</table>' . "\n";
+ echo '</form>' . "\n";
+}
+
+/* print the $msgs messages from $mailbox mailbox */
+/* this is almost the original code */
+function asearch_print_mailbox_msgs($msgs, $mailbox, $cnt, $imapConnection, $where, $what, $usecache = false, $newsort = false)
+{
+ global $sort, $color;
+
+ if ($cnt > 0) {
+ $msort = calc_msort($msgs, $sort);
+ $showbox = asearch_get_mailbox_display($mailbox);
+ echo html_tag( 'div', '<b><big>' . _("Folder:") . ' '. $showbox.'</big></b>','center') . "\n";
+
+ $msg_cnt_str = get_msgcnt_str(1, $cnt, $cnt);
+ $toggle_all = get_selectall_link(1, $sort);
+
+ echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
+
+ echo '<tr><td>';
+ mail_message_listing_beginning($imapConnection, $mailbox, $sort, $msg_cnt_str, $toggle_all, 1);
+ echo '</td></tr>';
+
+ echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
+
+ echo '<tr><td>';
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
+ echo ' <tr><td>';
+
+ echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
+ echo ' <tr><td>';
+ printHeader($mailbox, 6, $color, false);
+ displayMessageArray($imapConnection, $cnt, 1, $msort, $mailbox, $sort, $color, $cnt, $where, $what);
+ echo ' </td></tr>';
+ echo ' </table>';
+ echo ' </td></tr>';
+ echo ' </table>';
+ mail_message_listing_end($cnt, '', $msg_cnt_str, $color);
+ echo '</td></tr>';
+
+ echo '</table>';
+ }