Search call back adjusted to fit new format
[squirrelmail.git] / src / search.php
index d385c90b5c7b05321e49c43f421113d430a92dea..2c615bc833d978797e5fd1efe5e8d79e5cc76718 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
 /**
- * right_main.php
+ * search.php
  *
- * Copyright (c) 1999-2001 The Squirrelmail Development Team
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * $Id$
@@ -16,76 +16,114 @@ require_once('../functions/array.php');
 
 function s_opt( $val, $sel, $tit ) {
     echo "            <option value=\"$val\"";
-    if ( $sel ) {
-        echo 'selected';
+    if ( $sel == $val ) {
+        echo ' selected';
     }
     echo  ">$tit</option>\n";
 }
 
-displayPageHeader($color, $mailbox);
+/* ------------------------ main ------------------------ */
+
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+$boxes = sqimap_mailbox_list($imapConnection);
+
+if( $mailbox == 'None' ) {
+    $mailbox = $boxes[0]['unformatted'];
+}
+
+displayPageHeader($color, $mailbox);
+
+if( !isset( $search_memory ) ) {
+    $search_memory = 0;
+}
 
 do_hook('search_before_form');
 echo "<br>\n".
-    "      <table width=95% align=center cellpadding=2 cellspacing=0 border=0>\n".
-    "      <tr><td bgcolor=\"$color[0]\">\n".
-    "          <center><b>"._("Search")."</b></center>\n".
-    "      </td></tr>\n".
-    '      <tr><td align=center>'.
-
-    "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
-    "   <TABLE WIDTH=\"75%\">\n".
-    "     <TR>\n".
-    "       <TD WIDTH=\"33%\">\n".
-    '         <TT><SMALL><SELECT NAME="mailbox">';
+     "      <table width=\"95%\" align=center cellpadding=2 cellspacing=0 border=0>\n".
+     "      <tr><td bgcolor=\"$color[0]\">\n".
+     "          <center><b>"._("Search")."</b></center>\n".
+     "      </td></tr>\n".
+     '      <tr><td align=center>';
 
-$boxes = sqimap_mailbox_list($imapConnection);
-for ($i = 0; $i < count($boxes); $i++) {
-    if (!in_array('noselect', $boxes[$i]['flags'])) {
-        $box = $boxes[$i]['unformatted'];
-        $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
-        if ($mailbox == $box) {
-            echo "         <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
+for ( $form = 0; $form <= $search_memory; $form++ ) {
+
+    $frm = "$form";
+    $what = "what$frm";
+    $where = "where$frm";
+    
+    if( $search_memory > 0 ) {
+        if ( $$what == '' ) {
+            $$what = getPref($data_dir, $username, "search_what$frm", '' );
+            $$where = getPref($data_dir, $username, "search_where$frm", '' );
         } else {
-            echo "         <OPTION VALUE=\"$box\">$box2</OPTION>\n";
-        }   
+            setpref( $data_dir, $username, "search_what$frm", $$what );
+            setpref( $data_dir, $username, "search_where$frm", $$where );
+        }
     }
-}
-echo '         </SELECT></SMALL></TT>'.
-     "       </TD>\n".
-     "        <TD ALIGN=\"CENTER\" WIDTH=\"33%\">\n";
-if (!isset($what)) {
-   $what = '';
-}
-$what_disp = ereg_replace(',', ' ', $what);
-$what_disp = str_replace('\\\\', '\\', $what_disp);
-$what_disp = str_replace('\\"', '"', $what_disp);
-$what_disp = str_replace('"', '&quot;', $what_disp);
-echo "          <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"what\" VALUE=\"$what_disp\">\n".
-            '</TD>'.
-           "<TD ALIGN=\"RIGHT\" WIDTH=\"33%\">\n".
-             '<SELECT NAME="where">';
-
-s_opt( 'BODY', ($where == 'BODY'), _("Body") );
-s_opt( 'TEXT', ($where == 'TEXT'), _("Everywhere") );
-s_opt( 'SUBJECT', ($where == 'SUBJECT'), _("Subject") );
-s_opt( 'FROM', ($where == 'FROM'), _("From") );
-s_opt( 'CC', ($where == 'CC'), _("Cc") );
-s_opt( 'TO', ($where == 'TO'), _("To") );
-
-echo "         </SELECT>\n" .
-     "        </TD>\n".
-     "       <TD COLSPAN=\"3\" ALIGN=\"CENTER\">\n".
-     "         <INPUT TYPE=\"submit\" VALUE=\""._("Search")."\">\n".
-     "       </TD>\n".
-     "     </TR>\n".
-     "   </TABLE>\n".
-     "</FORM>".
-     "</td></tr></table>";
+    echo "   <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
+    if( !($form == 0 && $search_memory > 0) ) {
+
+        echo "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
+             "<input type=hidden name=pos value=\"$frm\">".
+             "     <TR>\n".
+             "       <TD WIDTH=\"33%\">\n".
+             '         <TT><SMALL><SELECT NAME="mailbox">';
+        
+        for ($i = 0; $i < count($boxes); $i++) {
+            if (!in_array('noselect', $boxes[$i]['flags'])) {
+                $box = $boxes[$i]['unformatted'];
+                $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
+                if ($mailbox == $box) {
+                    echo "         <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
+                } else {
+                    echo "         <OPTION VALUE=\"$box\">$box2</OPTION>\n";
+                }   
+            }
+        }
+        echo '         </SELECT></SMALL></TT>'.
+             "       </TD>\n".
+             "        <TD ALIGN=\"CENTER\" WIDTH=\"33%\">\n";
+        if (!isset($$what)) {
+           $$what = '';
+        }
+        $what_disp = str_replace(',', ' ', $$what);
+        $what_disp = str_replace('\\\\', '\\', $what_disp);
+        $what_disp = str_replace('\\"', '"', $what_disp);
+        $what_disp = str_replace('"', '&quot;', $what_disp);
+        echo "          <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"what$frm\" VALUE=\"$what_disp\">\n".
+                    '</TD>'.
+                   "<TD ALIGN=\"RIGHT\" WIDTH=\"33%\">\n".
+                     "<SELECT NAME=\"where$frm\">";
+        
+        s_opt( 'BODY', $$where, _("Body") );
+        s_opt( 'TEXT', $$where, _("Everywhere") );
+        s_opt( 'SUBJECT', $$where, _("Subject") );
+        s_opt( 'FROM', $$where, _("From") );
+        s_opt( 'CC', $$where, _("Cc") );
+        s_opt( 'TO', $$where, _("To") );
+        
+        echo "         </SELECT>\n" .
+             "        </TD>\n".
+             "       <TD COLSPAN=\"3\" ALIGN=\"CENTER\">\n".
+             "         <INPUT TYPE=\"submit\" VALUE=\""._("Search")."\">\n".
+             "       </TD>\n".
+             "     </TR>\n".
+             '</FORM>';
+    }         
+    echo "   </TABLE>\n";
+}     
+
+echo "</td></tr></table>";
 do_hook("search_after_form");
-if (isset($where) && $where && isset($what) && $what) {
+if( !isset( $pos ) ) {
+    $pos = $frm;
+}
+$what = "what$pos";
+$where = "where$pos";
+
+if (isset($$where) && $$where && isset($$what) && $$what) {
     sqimap_mailbox_select($imapConnection, $mailbox);
-    sqimap_search($imapConnection, $where, $what, $mailbox, $color);
+    sqimap_search($imapConnection, $$where, $$what, $mailbox, $color);
 }
 do_hook("search_bottom");
 sqimap_logout ($imapConnection);