+ 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);
+ }
+ 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 one basic form row
+ */
+function asearch_print_form_row_basic($imapConnection, &$boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num)
+{
+ global $search_button_html;
+ global $color;
+
+ echo html_tag('tr', '', '', $color[4]);
+
+//Mailbox list
+ echo html_tag('td', '<b>' . _("In") . '</b> ' . asearch_get_form_mailbox($imapConnection, $boxes, $mailbox), 'center') . "\n";
+
+//Unary operator and Search location
+ echo html_tag('td', asearch_get_form_location($unop, $where), 'center') . "\n";
+
+//Text input
+ echo html_tag('td', asearch_get_form_what($what), 'center') . "\n";
+
+//Submit button
+ echo html_tag('td', getButton('submit', 'submit', $search_button_html), 'center') . "\n";
+
+ echo "</tr>\n";
+}
+
+/** Print the basic search form
+ */
+function asearch_print_form_basic($imapConnection, &$boxes, $mailbox_array, $biop_array, $unop_array, $where_array, $what_array, $exclude_array, $sub_array)
+{
+ 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=4'));
+ $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_basic($imapConnection, $boxes, $mailbox, $biop, $unop, $where, $what, $exclude, $sub, $row_num);
+ }
+ echo '</table>' . "\n";
+ echo '</form>' . "\n";
+}
+
+
+/**
+ * @param array $boxes mailboxes array (reference)
+ * @return array selectable unformatted mailboxes names
+ */
+function sqimap_asearch_get_selectable_unformatted_mailboxes(&$boxes)
+{
+ $mboxes_array = array();
+ $boxcount = count($boxes);
+ for ($boxnum = 0; $boxnum < $boxcount; $boxnum++) {
+ if (!in_array('noselect', $boxes[$boxnum]['flags']))
+ $mboxes_array[] = $boxes[$boxnum]['unformatted'];
+ }
+ return $mboxes_array;