+/**
+ * Creates button
+ *
+ * @deprecated see form functions available in 1.5.1 and 1.4.3.
+ * @param string $type
+ * @param string $name
+ * @param string $value
+ * @param string $js
+ * @param bool $enabled
+ */
+function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
+ $disabled = ( $enabled ? '' : 'disabled ' );
+ $js = ( $js ? $js.' ' : '' );
+ return '<input '.$disabled.$js.
+ 'type="'.$type.
+ '" name="'.$name.
+ '" value="'.$value .
+ '" style="padding: 0px; margin: 0px" />';
+}
+
+
+/** Handle the alternate row colors
+ * @return string color value
+ */
+function asearch_get_row_color(&$color, $row_num)
+{
+/*$color_string = ($row_num%2 ? $color[0] : $color[4]);*/
+ $color_string = $color[4];
+ if ($GLOBALS['alt_index_colors']) {
+ if (($row_num % 2) == 0) {
+ if (!isset($color[12]))
+ $color[12] = '#EAEAEA';
+ $color_string = $color[12];
+ }
+ }
+ return $color_string;
+}
+
+/** Print a whole query array, recent or saved
+ */
+function asearch_print_query_array(&$boxes, &$query_array, &$query_keys, &$action_array, $title, $show_pref)
+{
+ global $color;
+ global $data_dir, $username;
+ global $use_icons, $icon_theme;
+
+ $show_flag = getPref($data_dir, $username, $show_pref, 0) & 1;
+ $use_icons_flag = ($use_icons) && ($icon_theme != 'none');
+ if ($use_icons_flag)
+ $text_array = array('<img src="' . SM_PATH . 'images/minus.png" border="0" height="7" width="7" />',
+ '<img src="' . SM_PATH . 'images/plus.png" border="0" height="7" width="7" />');
+ else
+ $text_array = array('-', '+');
+ $toggle_link = asearch_get_toggle_link(!$show_flag, $show_pref, $text_array, array(_("Fold"), _("Unfold")));
+ if (!$use_icons_flag)
+ $toggle_link = '<small>[' . $toggle_link . ']</small>';
+
+ echo "<br />\n";
+ echo html_tag('table', '', 'center', $color[9], 'width="95%" cellpadding="1" cellspacing="1" border="0"');
+ echo html_tag('tr',
+ html_tag('td', $toggle_link, 'center', $color[5], 'width="5%"')
+ . html_tag('td', asearch_get_title_display($color, $title), 'center', $color[5], 'colspan=4'));
+ if ($show_flag) {
+ $main_key = $query_keys[ASEARCH_WHERE];
+ $query_count = count($query_array[$main_key]);
+ for ($query_num = 0, $row_num = 0; $query_num < $query_count; $query_num++) {
+ if (!empty($query_array[$main_key][$query_num])) {
+ echo html_tag('tr', '', '', asearch_get_row_color($color, $row_num));
+
+ unset($search_array);
+ foreach ($query_keys as $query_key) {
+ $search_array[] = asearch_unserialize($query_array[$query_key][$query_num]);
+ }
+ $where_array = $search_array[ASEARCH_WHERE];
+ $mailbox_array = $search_array[ASEARCH_MAILBOX];
+ $what_array = $search_array[ASEARCH_WHAT];
+ $unop_array = $search_array[ASEARCH_UNOP];
+ $biop_array = asearch_nz($search_array[ASEARCH_BIOP], array());
+ $exclude_array = asearch_nz($search_array[ASEARCH_EXCLUDE], array());
+ $sub_array = asearch_nz($search_array[ASEARCH_SUB], array());
+ $query_display = asearch_get_query_display($color, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array);
+
+ echo html_tag('td', $query_num + 1, 'right');
+ echo html_tag('td', $query_display, 'center', '', 'width="80%"');
+ foreach ($action_array as $action => $action_display) {
+ echo html_tag('td', '<a href="' . asearch_get_href('submit=' . $action . '&rownum=' . $query_num) . '">' . $action_display . '</a>', 'center');
+ }
+
+ echo '</tr>' . "\n";
+ $row_num++;
+ }
+ }
+ }
+ echo '</table>' . "\n";
+}
+
+/** Print the saved array
+ */
+function asearch_print_saved(&$boxes)
+{
+ global $saved_prefkeys;
+
+ $saved_array = asearch_read_saved();
+ if (isset($saved_array[$saved_prefkeys[0]])) {
+ $saved_count = count($saved_array[$saved_prefkeys[0]]);
+ if ($saved_count > 0) {
+ $saved_actions = array('edit_saved' => _("edit"), 'search_saved' => _("search"), 'delete_saved' => _("delete"));
+ asearch_print_query_array($boxes, $saved_array, $saved_prefkeys, $saved_actions, _("Saved Searches"), 'search_show_saved');
+ }
+ }
+}
+
+/**
+ * Print the recent array
+ */
+function asearch_print_recent(&$boxes)
+{
+ global $recent_prefkeys, $search_memory;
+
+ $recent_array = asearch_read_recent();
+ if (isset($recent_array[$recent_prefkeys[0]])) {
+ $recent_count = count($recent_array[$recent_prefkeys[0]]);
+ if (min($recent_count, $search_memory) > 0) {
+ $recent_actions = array('save_recent' => _("save"), 'search_recent' => _("search"), 'forget_recent' => _("forget"));
+ asearch_print_query_array($boxes, $recent_array, $recent_prefkeys, $recent_actions, _("Recent Searches"), 'search_show_recent');
+ }
+ }
+}
+
+/** Build an <option> statement
+ */
+function asearch_opt($val, $sel, $tit)
+{
+ return '<option value="' . $val . '"' . ($sel == $val ? ' selected="selected"' : '') . '>' . $tit . '</option>' . "\n";
+}
+
+/** Build a <select> statement 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, asearch_nz($display, $val));
+ $output .= '</select>' . "\n";
+ return $output;
+}
+
+/** Verify that a mailbox exists
+ * @return bool mailbox exists
+ */
+function asearch_mailbox_exists($mailbox, &$boxes)
+{
+ foreach ($boxes as $box) {
+ if ($box['unformatted'] == $mailbox)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/** Build the mailbox select
+ */
+function asearch_get_form_mailbox($imapConnection, &$boxes, $mailbox, $row_num = 0)
+{
+ if (($mailbox != 'All Folders') && (!asearch_mailbox_exists($mailbox, $boxes))) {
+ $missing = asearch_opt($mailbox, $mailbox, '[' . _("Missing") . '] ' . asearch_get_mailbox_display($mailbox));
+ } else {
+ $missing = '';
+ }
+ return '<select name="mailbox[' . $row_num . ']">'
+ . $missing
+ . asearch_opt('All Folders', $mailbox, '[' . asearch_get_mailbox_display('All Folders') . ']')
+ . sqimap_mailbox_option_list($imapConnection, array(strtolower($mailbox)), 0, $boxes, NULL)
+ . '</select>';
+}
+
+/** Build the Include subfolders checkbox
+ */
+function asearch_get_form_sub($sub, $row_num = 0)
+{
+ return function_exists('addCheckBox') ? addCheckBox('sub[' . $row_num .']', $sub)
+ : '<input type="checkbox" name="sub[' . $row_num .']"' . ($sub ? ' checked="checked"' : '') . ' />';
+}
+
+/** Build the 2 unop and where selects
+ */
+function asearch_get_form_location($unop, $where, $row_num = 0)
+{
+ global $imap_asearch_unops, $imap_asearch_options;
+
+ return asearch_opt_array('unop[' . $row_num . ']', $imap_asearch_unops, $unop)
+ . asearch_opt_array('where[' . $row_num . ']', $imap_asearch_options, $where);
+}
+
+/** Build the what text input
+ */
+function asearch_get_form_what($what, $row_num = 0)
+{
+ return function_exists('addInput') ? addInput('what[' . $row_num . ']', $what, '35')
+ : '<input type="text" size="35" name="what[' . $row_num . ']" value="' . htmlspecialchars($what) . '" />';
+}
+
+/** Build the Exclude criteria checkbox
+ */
+function asearch_get_form_exclude($exclude, $row_num = 0)
+{
+ return function_exists('addCheckBox') ? addCheckBox('exclude['.$row_num.']', $exclude)
+ : '<input type="checkbox" name="exclude[' . $row_num .']"' . ($exclude ? ' checked="checked"' : '') . ' />';
+}
+
+/** Print one advanced form row
+ */
+function asearch_print_form_row($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num)
+{
+ global $imap_asearch_biops_in;
+ global $color;
+
+ echo html_tag('tr', '', '', $color[4]);
+
+//Binary operator
+ echo html_tag('td', $row_num ?
+ asearch_opt_array('biop[' . $row_num . ']', $imap_asearch_biops_in, $biop)
+ : '<b>' . _("In") . '</b>', 'center') . "\n";
+
+//Mailbox list and Include Subfolders
+ echo html_tag('td',
+ asearch_get_form_mailbox($imapConnection, $boxes, $mailbox, $row_num)
+ . _("and subfolders:") . asearch_get_form_sub($sub, $row_num), 'center') . "\n";
+
+//Unary operator and Search location
+ echo html_tag('td', asearch_get_form_location($unop, $where, $row_num), 'center') . "\n";
+
+//Text input
+ echo html_tag('td', asearch_get_form_what($what, $row_num), 'center') . "\n";
+
+//Exclude criteria
+ echo html_tag('td', _("Exclude Criteria:") . asearch_get_form_exclude($exclude, $row_num), 'center') . "\n";
+
+ echo "</tr>\n";
+}
+
+/** Print the advanced search form
+ */
+function asearch_print_form($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
+{
+ 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="' . asearch_get_href() . '" 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_get_title_display($color, _("Search Criteria")), 'center', $color[5], 'colspan=5'));
+ $row_count = count($where_array);
+ for ($row_num = 0; $row_num < $row_count; $row_num++) {
+ $mailbox = asearch_nz($mailbox_array[$row_num]);
+ $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]));
+ $sub = strip_tags(asearch_nz($sub_array[$row_num]));
+ asearch_print_form_row($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num);