Converted some ereg_replace() into str_replace().
[squirrelmail.git] / src / search.php
index ed92be5e85d7a2173d7d65f9e43b07483764882e..7eb98a183faa78e51be51356758c4bff51f4fb4d 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+   /* $Id$ */
+
    session_start();
 
    if(!isset($logged_in)) {
       exit;
    }
    if(!isset($username) || !isset($key)) {
-      set_up_language($squirrelmail_language, true);
-      echo _("You need a valid user and password to access this page!");
+      include ("../themes/default_theme.php");
+      include ("../functions/display_messages.php");
+      printf('<html><BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
+              $color[8], $color[4], $color[7], $color[7], $color[7]);
+      plain_error_message(_("You need a valid user and password to access this page!")
+                          . "<br><a href=\"../src/login.php\">"
+                          . _("Click here to log back in.") . "</a>.", $color);
+      echo "</body></html>";
       exit;
    }
 
+   if (!isset($strings_php))
+      include("../functions/strings.php");
    if (!isset($i18n_php))
       include("../functions/i18n.php");
    if (!isset($config_php))
       include("../config/config.php");
-   if (!isset($strings_php))
-      include("../functions/strings.php");
    if (!isset($page_header_php))
       include("../functions/page_header.php");
    if (!isset($imap_php))
@@ -48,7 +57,7 @@
 
    $boxes = sqimap_mailbox_list($imapConnection);
    for ($i = 0; $i < count($boxes); $i++) {
-      if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
+         if (!in_array("noselect", $boxes[$i]["flags"])) {
          $box = $boxes[$i]["unformatted"];
          $box2 = replace_spaces($boxes[$i]["formatted"]);
          if ($mailbox == $box)
@@ -60,6 +69,8 @@
    echo "         </SELECT></SMALL></TT>";
    echo "       </TD>\n";
    echo "        <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);
    echo "       <TD ALIGN=\"RIGHT\" WIDTH=33%>\n";
    echo "         <SELECT NAME=\"where\">";
    
-   if ($where == "BODY") echo "           <OPTION VALUE=\"BODY\" SELECTED>"._("Body")."\n";
+   if (isset($where) && $where == "BODY") echo "           <OPTION VALUE=\"BODY\" SELECTED>"._("Body")."\n";
    else echo "           <OPTION VALUE=\"BODY\">"._("Body")."\n";
    
-   if ($where == "TEXT") echo "           <OPTION VALUE=\"TEXT\" SELECTED>"._("Everywhere")."\n";
+   if (isset($where) && $where == "TEXT") echo "           <OPTION VALUE=\"TEXT\" SELECTED>"._("Everywhere")."\n";
    else echo "           <OPTION VALUE=\"TEXT\">"._("Everywhere")."\n";
    
-   if ($where == "SUBJECT") echo "           <OPTION VALUE=\"SUBJECT\" SELECTED>"._("Subject")."\n";
+   if (isset($where) && $where == "SUBJECT") echo "           <OPTION VALUE=\"SUBJECT\" SELECTED>"._("Subject")."\n";
    else echo "           <OPTION VALUE=\"SUBJECT\">"._("Subject")."\n";
    
-   if ($where == "FROM") echo "           <OPTION VALUE=\"FROM\" SELECTED>"._("From")."\n";
+   if (isset($where) && $where == "FROM") echo "           <OPTION VALUE=\"FROM\" SELECTED>"._("From")."\n";
    else echo "           <OPTION VALUE=\"FROM\">"._("From")."\n";
    
-   if ($where == "CC") echo "           <OPTION VALUE=\"Cc\" SELECTED>"._("Cc")."\n";
+   if (isset($where) && $where == "CC") echo "           <OPTION VALUE=\"Cc\" SELECTED>"._("Cc")."\n";
    else echo "           <OPTION VALUE=\"CC\">"._("Cc")."\n";
    
-   if ($where == "TO") echo "           <OPTION VALUE=\"TO\" SELECTED>"._("To")."\n";
+   if (isset($where) && $where == "TO") echo "           <OPTION VALUE=\"TO\" SELECTED>"._("To")."\n";
    else echo "           <OPTION VALUE=\"TO\">"._("To")."\n";
    
    echo "         </SELECT>\n";
    echo "</FORM>";
    echo "</td></tr></table>";
    do_hook("search_after_form");
-   if ($where && $what) {   
+   if (isset($where) && $where && isset($what) && $what) {   
       sqimap_mailbox_select($imapConnection, $mailbox);
       sqimap_search($imapConnection, $where, $what, $mailbox, $color);
-      sqimap_mailbox_close($imapConnection);
    }
    do_hook("search_bottom");
    sqimap_logout ($imapConnection);