Add index.html to Development subdir, rename README.russian_apache to
[squirrelmail.git] / src / addressbook.php
index 1a88eb23ed0fc9d47953afe6d4b6d0c156decfb2..753cd2ca054ac9655f62a37b938ec2aec498eb40 100644 (file)
@@ -3,13 +3,14 @@
 /**
  * addressbook.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * Manage personal address book.
  *
  * @version $Id$
  * @package squirrelmail
+ * @subpackage addressbook
  */
 
 /**
@@ -44,9 +45,15 @@ sqgetGlobalVar('doedit',    $doedit,    SQ_POST);
 /* Get sorting order */
 $abook_sort_order = get_abook_sort();
 
-/* Open addressbook, with error messages on but without LDAP (the *
- * second "true"). Don't need LDAP here anyway                    */
-$abook = addressbook_init(true, true);
+/* Create page header before addressbook_init in order to  display error messages correctly. */
+displayPageHeader($color, 'None');
+
+/* Open addressbook with error messages on.
+ remote backends (LDAP) are enabled because they can be used. (list_addr function)
+*/
+$abook = addressbook_init(true, false);
+
+// FIXME: do we have to stop use of address book, when localbackend is not present.
 if($abook->localbackend == 0) {
     plain_error_message(
             _("No personal address book is defined. Contact administrator."),
@@ -54,7 +61,6 @@ if($abook->localbackend == 0) {
     exit();
 }
 
-displayPageHeader($color, 'None');
 
 $defdata   = array();
 $formerror = '';
@@ -63,7 +69,6 @@ $showaddrlist = true;
 $defselected  = array();
 $form_url = 'addressbook.php';
 
-
 /* Handle user's actions */
 if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') {
 
@@ -143,7 +148,6 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
              * Update/modify address                       *
              ***********************************************/
             if (!empty($editaddr)) {
-
                 /* Stage one: Copy data into form */
                 if (isset($sel) && sizeof($sel) > 0) {
                     if(sizeof($sel) > 1) {
@@ -162,40 +166,40 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                             addHidden('doedit', '1').
                             '</form>';
                     }
-                } else {
-
+                } elseif ($doedit == 1) {
                     /* Stage two: Write new data */
-                    if ($doedit = 1) {
-                        $newdata = $editaddr;
-                        $r = $abook->modify($oldnick, $newdata, $backend);
-
-                        /* Handle error messages */
-                        if (!$r) {
-                            /* Display error */
-                            echo html_tag( 'table',
-                                    html_tag( 'tr',
-                                        html_tag( 'td',
-                                            "\n". '<strong><font color="' . $color[2] .
-                                            '">' . _("ERROR") . ': ' . $abook->error . '</font></strong>' ."\n",
-                                            'center' )
-                                        ),
-                                    'center', '', 'width="100%"' );
-
-                            /* Display the "new address" form again */
-                            abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$newdata);
-                            echo addHidden('oldnick', $oldnick).
-                                addHidden('backend', $backend).
-                                addHidden('doedit',  '1').
-                                "\n" . '</form>';
-                            $abortform = true;
-                        }
-                    } else {
+                    $newdata = $editaddr;
+                    $r = $abook->modify($oldnick, $newdata, $backend);
 
-                        /* Should not get here... */
-                        plain_error_message(_("Unknown error"), $color);
+                    /* Handle error messages */
+                    if (!$r) {
+                        /* Display error */
+                        echo html_tag( 'table',
+                                       html_tag( 'tr',
+                                                 html_tag( 'td',
+                                                           "\n". '<strong><font color="' . $color[2] .
+                                                           '">' . _("ERROR") . ': ' . $abook->error . '</font></strong>' ."\n",
+                                                           'center' )
+                                                 ),
+                                       'center', '', 'width="100%"' );
+
+                        /* Display the "new address" form again */
+                        abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$newdata);
+                        echo addHidden('oldnick', $oldnick).
+                            addHidden('backend', $backend).
+                            addHidden('doedit',  '1').
+                            "\n" . '</form>';
                         $abortform = true;
                     }
-                }
+                } else {
+                    /**
+                     * $editaddr is set, but $sel (address selection in address listing)
+                     * and $doedit (address edit form) are not set.
+                     * Assume that user clicked on "Edit address" without selecting any address.
+                     */
+                    $formerror = _("Please select address that you want to edit");
+                    $showaddrlist = true;
+                } /* end of edit stage detection */
             } /* !empty($editaddr)                  - Update/modify address */
         } /* (!empty($deladdr)) && sizeof($sel) > 0 - Delete address(es) */
     } /* !empty($addaddr['nickname'])               - Add new address */
@@ -267,10 +271,10 @@ if ($showaddrlist) {
                                 html_tag( 'th', _("Nickname") .
                                     show_abook_sort_button($abook_sort_order, _("sort by nickname"), 0, 1),
                                     'left', '', 'width="1%"' ) . "\n" .
-                                html_tag( 'th', _("Name") . 
+                                html_tag( 'th', _("Name") .
                                     show_abook_sort_button($abook_sort_order, _("sort by name"), 2, 3),
                                     'left', '', 'width="1%"' ) . "\n" .
-                                html_tag( 'th', _("E-mail") . 
+                                html_tag( 'th', _("E-mail") .
                                     show_abook_sort_button($abook_sort_order, _("sort by email"), 4, 5),
                                     'left', '', 'width="1%"' ) . "\n" .
                                 html_tag( 'th', _("Info") .
@@ -319,9 +323,9 @@ if ($showaddrlist) {
                             '&nbsp;' ,
                             'center', '', 'valign="top" width="1%"' );
                 }
-                echo html_tag( 'td', '&nbsp;' . $row['nickname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" nowrap' ) . 
-                    html_tag( 'td', '&nbsp;' . $row['lastname'] . ' ' . $row['firstname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" nowrap' ) .
-                    html_tag( 'td', '', 'left', '', 'valign="top" width="1%" nowrap' ) . '&nbsp;';
+                echo html_tag( 'td', '&nbsp;' . $row['nickname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) .
+                    html_tag( 'td', '&nbsp;' . $row['lastname'] . ' ' . $row['firstname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) .
+                    html_tag( 'td', '', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) . '&nbsp;';
             } else {
                 echo html_tag( 'tr', '', '', $tr_bgcolor);
                 if ($abook->backends[$row['backend']]->writeable) {
@@ -335,9 +339,9 @@ if ($showaddrlist) {
                             '&nbsp;' ,
                             'center', '', 'valign="top" width="1%"' );
                 }
-                echo html_tag( 'td', '&nbsp;' . $row['nickname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" nowrap' ) .
-                    html_tag( 'td', '&nbsp;' . $row['name'] . '&nbsp;', 'left', '', 'valign="top" width="1%" nowrap' ) .
-                    html_tag( 'td', '', 'left', '', 'valign="top" width="1%" nowrap' ) . '&nbsp;';
+                echo html_tag( 'td', '&nbsp;' . $row['nickname'] . '&nbsp;', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) .
+                    html_tag( 'td', '&nbsp;' . $row['name'] . '&nbsp;', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) .
+                    html_tag( 'td', '', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) . '&nbsp;';
             }
             $email = $abook->full_address($row);
             echo makeComposeLink('src/compose.php?send_to='.rawurlencode($email),
@@ -376,4 +380,4 @@ echo "<!-- start of addressbook_bottom hook-->\n";
 do_hook('addressbook_bottom');
 echo "\n<!-- end of addressbook_bottom hook-->\n";
 ?>
-</body></html>
+</body></html>
\ No newline at end of file