made sorting method persistant using session management
[squirrelmail.git] / src / addrbook_search.php
index 9202b1375ab8292b5a05725020d5c601fd8a1b71..c707bd5c3e1f9b1936c12a579d552b7f17b770fd 100644 (file)
@@ -6,10 +6,10 @@
     **
     **/
 
+   session_start();
+
    if(!isset($logged_in)) {
-      echo _("You must ");
-      echo _("login");
-      echo _(" first.");
+      echo _("You must login first.");
       exit;
    }
    if(!isset($username) || !isset($key)) {
@@ -66,7 +66,7 @@
 
    // Create search form 
    if($show == "form") {
-      printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=GET>\n",
+      printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
             $PHP_SELF);
       printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">");
       printf("<TR><TD NOWRAP VALIGN=middle>\n");
@@ -92,11 +92,14 @@ function to_address($addr) {
   var prefix    = "";
   var pwintype = typeof parent.opener.document.compose;
 
+  $addr = $addr.replace(/ {1,35}$/, "");
+
   if(pwintype != "undefined" ) {
     if ( parent.opener.document.compose.send_to.value ) {
       prefix = ", ";
       parent.opener.document.compose.send_to.value = 
-        parent.opener.document.compose.send_to.value + ", " + $addr;      
+        parent.opener.document.compose.send_to.value + ", " + $addr;
+        
     } else {
       parent.opener.document.compose.send_to.value = $addr;
     }
@@ -107,6 +110,8 @@ function cc_address($addr) {
   var prefix    = "";
   var pwintype = typeof parent.opener.document.compose;
 
+  $addr = $addr.replace(/ {1,35}$/, "");
+
   if(pwintype != "undefined" ) {
     if ( parent.opener.document.compose.send_to_cc.value ) {
       prefix = ", ";
@@ -121,6 +126,8 @@ function cc_address($addr) {
 function bcc_address($addr) {
   var prefix    = "";
   var pwintype = typeof parent.opener.document.compose;
+  
+  $addr = $addr.replace(/ {1,35}$/, "");
 
   if(pwintype != "undefined" ) {
     if ( parent.opener.document.compose.bcc.value ) {
@@ -144,6 +151,13 @@ function bcc_address($addr) {
       $res = $abook->s_search($query);
 
       if(!is_array($res)) {
+        printf("<P ALIGN=center><BR>%s:<br>%s</P>\n</BODY></HTML>\n",
+               _("Your search failed with the following error(s)"),
+               $abook->error);
+        exit;
+      }
+
+      if(sizeof($res) == 0) {
         printf("<P ALIGN=center><BR>%s.</P>\n</BODY></HTML>\n",
                _("No persons matching your search was found"));
         exit;
@@ -151,11 +165,19 @@ function bcc_address($addr) {
 
       // List search results
       $line = 0;
-      print "<table border=0 width=100%>";
-      print "<tr bgcolor=\"$color[9]\"><TH align=left>&nbsp;<TH align=left>Name<TH align=left>E-mail<TH align=left>Info<TH align=left>Source</tr>\n";
+      print "<table border=0 width=\"98%\" align=center>";
+      printf("<tr bgcolor=\"$color[9]\"><TH align=left>&nbsp;".
+             "<TH align=left>&nbsp;%s<TH align=left>&nbsp;%s".
+            "<TH align=left>&nbsp;%s<TH align=left width=\"10%%\">".
+            "&nbsp;%s</tr>\n",
+             _("Name"), _("E-mail"), _("Info"), _("Source"));
 
       while(list($key, $row) = each($res)) {
-        printf("<tr%s nowrap><td nowrap><a href=\"javascript:to_address('%s');\">To</A> | <a href=\"javascript:cc_address('%s');\">Cc</A><td nowrap>%s&nbsp;<td nowrap>%s&nbsp;<td nowrap>%s&nbsp;<td nowrap>%s</tr>\n", 
+        printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
+               "<a href=\"javascript:to_address('%s');\">To</A> | ".
+               "<a href=\"javascript:cc_address('%s');\">Cc</A>".
+               "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;%s&nbsp;".
+               "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;%s</tr>\n", 
                ($line % 2) ? " bgcolor=\"$color[0]\"" : "", $row["email"],
                $row["email"], $row["name"], $row["email"], $row["label"], 
                $row["source"]);