fixed a warning and the return key submits the form properly now.
[squirrelmail.git] / src / addrbook_search.php
index fa5fa5705499e324b0c76f6f06fd3bce5398d0c9..7ac55f605d8fb3aa24ee633dc677507431557afc 100644 (file)
  * $Id$
  */
 
-/*****************************************************************/
-/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!!           ***/
-/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION.             ***/
-/***    + Base level indent should begin at left margin, as    ***/
-/***      the require_once below looks.                        ***/
-/***    + All identation should consist of four space blocks   ***/
-/***    + Tab characters are evil.                             ***/
-/***    + all comments should use "slash-star ... star-slash"  ***/
-/***      style -- no pound characters, no slash-slash style   ***/
-/***    + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD      ***/
-/***      ALWAYS USE { AND } CHARACTERS!!!                     ***/
-/***    + Please use ' instead of ", when possible. Note "     ***/
-/***      should always be used in _( ) function calls.        ***/
-/*** Thank you for your help making the SM code more readable. ***/
-/*****************************************************************/
-
 require_once('../src/validate.php');
+require_once('../functions/strings.php');
 
 /* Function to include JavaScript code */
 function insert_javascript() {
@@ -120,19 +105,20 @@ function display_result($res, $includesource = true) {
     echo "</TR>\n";
     
     while (list($undef, $row) = each($res)) {
-        echo '<tr' . (($line % 2) ? " bgcolor=\"$color[0]\"" : '') .
-             ' nowrap><td valign=top nowrap align=center width="5%">' .
+        echo '<tr';
+        if ($line % 2) { echo ' bgcolor="' . $color[0] . '"'; }
+        echo ' nowrap><td valign=top nowrap align=center width="5%">' .
              '<small><a href="javascript:to_address(' . 
                                        "'" . $row['email'] . "');\">To</A> | " .
              '<a href="javascript:cc_address(' . 
-                                       "'" . $row["email'] . "');\">Cc</A> | " .
+                                       "'" . $row['email'] . "');\">Cc</A> | " .
              '<a href="javascript:bcc_address(' . 
-                                 "'" . $row["email'] . "');\">Bcc</A></small>" .
+                                 "'" . $row['email'] . "');\">Bcc</A></small>" .
              '<td nowrap valign=top>&nbsp;' .
-                                 $row['name'] . '&nbsp;<td nowrap valign=top>' .
-             '&nbsp;<a href="javascript:to_and_close(' .
-                 "'" . $row["email'] . "');\">" . $row["email'] . '</A>&nbsp;' .
-             '<td valign=top>&nbsp;' . $row['label'] . '&nbsp;';
+                                 $row['name'] . '<td valign=top>' .
+             '<a href="javascript:to_and_close(' .
+                 "'" . $row['email'] . "');\">" . $row['email'] . '</A>' .
+             '<td valign=top nowrap>' . $row['label'];
         if ($includesource) {
             echo '<td nowrap valign=top>&nbsp;' . $row['source'];
         }
@@ -154,9 +140,10 @@ displayHtmlHeader();
 /* Initialize vars */
 if (!isset($query)) { $query = ''; }
 if (!isset($show))  { $show  = ''; }
+if (!isset($backend)) { $backend = ''; }
 
 /* Choose correct colors for top and bottom frame */
-if ($show == 'form') {
+if ($show == 'form' && !isset($listall)) {
     echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
                'LINK="' . $color[6] . '" VLINK="'   . $color[6] . '" ' .
                                         'ALINK="'   . $color[6] . '" ' .
@@ -179,14 +166,14 @@ if (empty($query) && empty($show) && empty($listall)) {
 $abook = addressbook_init();
 
 /* Create search form */
-if ($show == 'form') {
-    echo '<FORM NAME=sform TARGET=abookres ACTION="' . $PHP_SELF .
+if ($show == 'form' && empty($listall)) {
+    echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'. 
          '" METHOD="POST">' . "\n" .
          '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">' .
-         '<TR><TD NOWRAP VALIGN=middle>' . "\n" .
+         '<TR><TD NOWRAP VALIGN=middle align=left width=10%>' . "\n" .
          '  <STRONG>' . _("Search for") . "</STRONG>\n" .
-         '  <INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
-         "\" SIZE=26>\n",
+         '  </TD><TD align=left><INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
+         "\" SIZE=28>\n";
 
     /* List all backends to allow the user to choose where to search */
     if ($abook->numbackends > 1) {
@@ -201,17 +188,17 @@ if ($show == 'form') {
         echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
     }
         
-    echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
+    echo '</TD></TR><TR><TD></TD><TD align=left>'.
+                                       '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
          '&nbsp;|&nbsp;<INPUT TYPE=submit VALUE="' . _("List all") .
          '" NAME=listall>' . "\n" .
-         '</TD><TD ALIGN=right>' . "\n" .
-         '<INPUT TYPE=button VALUE=" . _("Close window") .
+         '&nbsp;|&nbsp;<INPUT TYPE=button VALUE="' . _("Close") .
          '" onclick="parent.close();">' . "\n" .
          '</TD></TR></TABLE></FORM>' . "\n";
 } else {
 
     /* Show personal addressbook */
-    if ($show == 'blank' || !empty($listall)) {
+    if ($show == 'blank' && empty($listall)) {
 
         if($backend != -1 || $show == 'blank') {
             if ($show == 'blank') {
@@ -220,6 +207,7 @@ if ($show == 'form') {
             $res = $abook->list_addr($backend);
 
             if(is_array($res)) {
+                usort($res,'alistcmp');
                 display_result($res, false);
             } else {
                 echo '<P ALIGN=center><STRONG>' .
@@ -229,13 +217,17 @@ if ($show == 'form') {
             }
         } else {
             $res = $abook->list_addr();
+            usort($res,'alistcmp');
             display_result($res, true);
         }
 
     } else {
+        if( !empty( $listall ) ){
+          $query = '*';
+        }
 
         /* Do the search */
-        if (!empty($query) && empty($listall)) {
+        if (!empty($query)) {
     
             if($backend == -1) {
                 $res = $abook->s_search($query);