Create page header before addressbook_init in order to display error
[squirrelmail.git] / src / addressbook.php
index 994a7de68622ddf98a9aaeda39bf48b0021e4498..8fafa44a656a093b1d65dbbdc593e4313235f1fc 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
  */
 
 /**
@@ -20,11 +21,8 @@ define('SM_PATH','../');
 
 /** SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/global.php');
 require_once(SM_PATH . 'functions/display_messages.php');
 require_once(SM_PATH . 'functions/addressbook.php');
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/html.php');
 require_once(SM_PATH . 'functions/forms.php');
 
 /** lets get the global vars we may need */
@@ -47,95 +45,13 @@ sqgetGlobalVar('doedit',    $doedit,    SQ_POST);
 /* Get sorting order */
 $abook_sort_order = get_abook_sort();
 
-/**
- * Make an input field
- * @param string $label
- * @param string $field
- * @param string $name
- * @param string $size
- * @param array $values
- * @param string $add
- */
-function addressbook_inp_field($label, $field, $name, $size, $values, $add) {
-    global $color;
-    $value = ( isset($values[$field]) ? $values[$field] : '');
-
-    $td_str = addInput($name.'['.$field.']', $value, $size)
-        . $add ;
-
-    return html_tag( 'tr' ,
-            html_tag( 'td', $label . ':', 'right', $color[4]) .
-            html_tag( 'td', $td_str, 'left', $color[4])
-            )
-        . "\n";
-}
-
-/**
- * Output form to add and modify address data
- */
-function address_form($name, $submittext, $values = array()) {
-    global $color, $squirrelmail_language;
-
-    if ($squirrelmail_language == 'ja_JP') {
-        echo html_tag( 'table',
-                addressbook_inp_field(_("Nickname"),     'nickname', $name, 15, $values,
-                    ' <small>' . _("Must be unique") . '</small>') .
-                addressbook_inp_field(_("E-mail address"),  'email', $name, 45, $values, '') .
-                addressbook_inp_field(_("Last name"),    'lastname', $name, 45, $values, '') .
-                addressbook_inp_field(_("First name"),  'firstname', $name, 45, $values, '') .
-                addressbook_inp_field(_("Additional info"), 'label', $name, 45, $values, '') .
-                list_writable_backends($name) .
-                html_tag( 'tr',
-                    html_tag( 'td',
-                        addSubmit($submittext, $name.'[SUBMIT]'),
-                        'center', $color[4], 'colspan="2"')
-                    )
-                , 'center', '', 'border="0" cellpadding="1" width="90%"') ."\n";
-    } else {
-        echo html_tag( 'table',
-                addressbook_inp_field(_("Nickname"),     'nickname', $name, 15, $values,
-                    ' <small>' . _("Must be unique") . '</small>') .
-                addressbook_inp_field(_("E-mail address"),  'email', $name, 45, $values, '') .
-                addressbook_inp_field(_("First name"),  'firstname', $name, 45, $values, '') .
-                addressbook_inp_field(_("Last name"),    'lastname', $name, 45, $values, '') .
-                addressbook_inp_field(_("Additional info"), 'label', $name, 45, $values, '') .
-                list_writable_backends($name) .
-                html_tag( 'tr',
-                    html_tag( 'td',
-                        addSubmit($submittext, $name.'[SUBMIT]') ,
-                        'center', $color[4], 'colspan="2"')
-                    )
-                , 'center', '', 'border="0" cellpadding="1" width="90%"') ."\n";
-    }
-}
-
-function list_writable_backends($name) {
-    global $color, $abook;
-    if ( $name != 'addaddr' ) { return; }
-    if ( $abook->numbackends > 1 ) {
-        $ret = '<select name="backend">';
-        $backends = $abook->get_backend_list();
-        while (list($undef,$v) = each($backends)) {
-            if ($v->writeable) {
-                $ret .= '<option value="' . $v->bnum;
-                $ret .= '">' . $v->sname . "</option>\n";
-            }
-        }
-        $ret .= "</select>";
-        return html_tag( 'tr',
-                html_tag( 'td', _("Add to:"),'right', $color[4] ) .
-                html_tag( 'td', $ret, 'left', $color[4] )) . "\n";
-    } else {
-        return html_tag( 'tr',
-                html_tag( 'td',
-                    addHidden('backend', '1'),
-                    'center', $color[4], 'colspan="2"')) . "\n";
-    }
-}
+/* Create page header before addressbook_init in order to  display error messages correctly. */
+displayPageHeader($color, 'None');
 
-/* Open addressbook, with error messages on but without LDAP (the *
- * second "true"). Don't need LDAP here anyway                    */
-$abook = addressbook_init(true, true);
+/* Open addressbook with error messages on.
+ remote backends (LDAP) are enabled because they can be used. (list_addr function)
+*/
+$abook = addressbook_init(true, false);
 if($abook->localbackend == 0) {
     plain_error_message(
             _("No personal address book is defined. Contact administrator."),
@@ -143,7 +59,6 @@ if($abook->localbackend == 0) {
     exit();
 }
 
-displayPageHeader($color, 'None');
 
 $defdata   = array();
 $formerror = '';
@@ -152,7 +67,6 @@ $showaddrlist = true;
 $defselected  = array();
 $form_url = 'addressbook.php';
 
-
 /* Handle user's actions */
 if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') {
 
@@ -245,15 +159,7 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                         $olddata = $abook->lookup($enick, $ebackend);
 
                         /* Display the "new address" form */
-                        echo addForm($form_url, 'post').
-                            html_tag( 'table',
-                                    html_tag( 'tr',
-                                        html_tag( 'td',
-                                            "\n". '<strong>' . _("Update address") . '</strong>' ."\n",
-                                            'center', $color[0] )
-                                        ),
-                                    'center', '', 'width="100%" ' );
-                        address_form("editaddr", _("Update address"), $olddata);
+                        abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$olddata);
                         echo addHidden('oldnick', $olddata['nickname']).
                             addHidden('backend', $olddata['backend']).
                             addHidden('doedit', '1').
@@ -279,17 +185,8 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                                     'center', '', 'width="100%"' );
 
                             /* Display the "new address" form again */
-                            echo addForm($form_url, 'post').
-                                html_tag( 'table',
-                                        html_tag( 'tr',
-                                            html_tag( 'td',
-                                                "\n". '<strong>' . _("Update address") . '</strong>' ."\n",
-                                                'center', $color[0] )
-                                            ),
-                                        'center', '', 'width="100%"' );
-                            address_form("editaddr", _("Update address"), $newdata);
-                            echo 
-                                addHidden('oldnick', $oldnick).
+                            abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$newdata);
+                            echo addHidden('oldnick', $oldnick).
                                 addHidden('backend', $backend).
                                 addHidden('doedit',  '1').
                                 "\n" . '</form>';
@@ -373,10 +270,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") .
@@ -425,9 +322,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) {
@@ -441,9 +338,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),
@@ -473,19 +370,13 @@ if ($showaddrlist) {
 
 
 /* Display the "new address" form */
-echo '<a name="AddAddress"></a>' . "\n" .
-    addForm($form_url, 'post', 'f_add').
-    html_tag( 'table',  
-        html_tag( 'tr',
-            html_tag( 'td', "\n". '<strong>' . _("Add to address book") . '</strong>' . "\n",
-                'center', $color[0]
-                )
-            )
-        , 'center', '', 'width="100%"' ) ."\n";
-address_form('addaddr', _("Add address"), $defdata);
+echo '<a name="AddAddress"></a>' . "\n";
+abook_create_form($form_url,'addaddr',_("Add to address book"),_("Add address"),$defdata);
 echo "</form>\n";
 
 /* Add hook for anything that wants on the bottom */
+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