Bah, the constant switching between quote types is frustrating.
[squirrelmail.git] / functions / addressbook.php
index c33e224016fc5275f840d48f4a121109c8b0bab7..90de7dab7a625cfbec275b182a762747b89163c6 100644 (file)
@@ -26,13 +26,16 @@ include_once(SM_PATH . 'functions/display_messages.php');
 global $addrbook_dsn, $addrbook_global_dsn;
 
 /**
-   Create and initialize an addressbook object.
-   Returns the created object
-*/
+ * Create and initialize an addressbook object.
+ * @param boolean $showerr display any address book init errors. html page header 
+ * must be created before calling addressbook_init() with $showerr enabled.
+ * @param boolean $onlylocal enable only local address book backends
+ * @return object address book object.
+ */
 function addressbook_init($showerr = true, $onlylocal = false) {
     global $data_dir, $username, $color, $ldap_server, $address_book_global_filename;
     global $addrbook_dsn, $addrbook_table;
-    global $abook_global_file, $abook_global_file_writeable;
+    global $abook_global_file, $abook_global_file_writeable, $abook_global_file_listing;
     global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing;
 
     /* Create a new addressbook object */
@@ -55,8 +58,7 @@ function addressbook_init($showerr = true, $onlylocal = false) {
                             'owner' => $username,
                             'table' => $addrbook_table));
         if (!$r && $showerr) {
-            echo _("Error initializing addressbook database.");
-            exit;
+            $abook_init_error.=_("Error initializing addressbook database.") . "<br />\n" . $abook->error;
         }
     } else {
         /* File */
@@ -64,15 +66,18 @@ function addressbook_init($showerr = true, $onlylocal = false) {
         $r = $abook->add_backend('local_file', Array('filename' => $filename,
                               'create'   => true));
         if(!$r && $showerr) {
-            printf( _("Error opening file %s"), $filename );
-            exit;
+            // no need to use $abook->error, because message explains error.
+            $abook_init_error.=sprintf( _("Error opening file %s"), $filename );
         }
 
     }
 
-    /* This would be for the global addressbook */
-    if (isset($abook_global_file) && isset($abook_global_file_writeable)
-        && trim($abook_global_file)!=''){
+    /* Global file based addressbook */
+    if (isset($abook_global_file) && 
+        isset($abook_global_file_writeable) &&
+        isset($abook_global_file_listing) &&
+        trim($abook_global_file)!=''){
+
         // Detect place of address book
         if (! preg_match("/[\/\\\]/",$abook_global_file)) {
             /* no path chars, address book stored in data directory
@@ -88,14 +93,17 @@ function addressbook_init($showerr = true, $onlylocal = false) {
         } else {
             $abook_global_filename=SM_PATH . $abook_global_file;
         }
+
         $r = $abook->add_backend('local_file',array('filename'=>$abook_global_filename,
                                                     'name' => _("Global address book"),
                                                     'detect_writeable' => false,
-                                                    'writeable'=> $abook_global_file_writeable));
+                                                    'writeable'=> $abook_global_file_writeable,
+                                                    'listing' => $abook_global_file_listing));
 
         /* global abook init error is not fatal. add error message and continue */
         if (!$r && $showerr) {
-            $abook_init_error.=_("Error initializing global addressbook.") . "<br />" . $abook->error;
+            if ($abook_init_error!='') $abook_init_error.="<br />\n";
+            $abook_init_error.=_("Error initializing global addressbook.") . "<br />\n" . $abook->error;
         }
     }
 
@@ -112,6 +120,11 @@ function addressbook_init($showerr = true, $onlylocal = false) {
                                      'writeable' => $addrbook_global_writeable,
                                      'listing' => $addrbook_global_listing,
                                      'table' => $addrbook_global_table));
+      /* global abook init error is not fatal. add error message and continue */
+      if (!$r && $showerr) {
+          if ($abook_init_error!='') $abook_init_error.="<br />\n";
+          $abook_init_error.=_("Error initializing global addressbook.") . "<br />\n" . $abook->error;
+      }
     }
 
     /*
@@ -124,29 +137,23 @@ function addressbook_init($showerr = true, $onlylocal = false) {
     $abook = $hookReturn[1];
     $r = $hookReturn[2];
 
-    if ($onlylocal) {
-        /* display error message, if present */
-        if ($abook_init_error!='' && $showerr) {
-            error_box($abook_init_error,$color);
-        }
-        return $abook;
-    }
-
-    /* Load configured LDAP servers (if PHP has LDAP support) */
-    if (isset($ldap_server) && is_array($ldap_server) && function_exists('ldap_connect')) {
-        reset($ldap_server);
-        while (list($undef,$param) = each($ldap_server)) {
-            if (is_array($param)) {
-                $r = $abook->add_backend('ldap_server', $param);
-                if (!$r && $showerr) {
-                    printf( '&nbsp;' . _("Error initializing LDAP server %s:") .
-                            "<br />\n", $param['host']);
-                    echo '&nbsp;' . $abook->error;
-                    exit;
+    if (! $onlylocal) {
+        /* Load configured LDAP servers (if PHP has LDAP support) */
+        if (isset($ldap_server) && is_array($ldap_server)) {
+            reset($ldap_server);
+            while (list($undef,$param) = each($ldap_server)) {
+                if (is_array($param)) {
+                    $r = $abook->add_backend('ldap_server', $param);
+                    if (!$r && $showerr) {
+                        if ($abook_init_error!='') $abook_init_error.="<br />\n";
+                        $abook_init_error.=sprintf(_("Error initializing LDAP server %s:") .
+                                                   "<br />\n", $param['host']);
+                        $abook_init_error.= $abook->error;
+                    }
                 }
             }
-        }
-    }
+        } // end of ldap server init
+    } // end of remote abook backend init
 
     /**
      * display address book init errors.
@@ -178,7 +185,7 @@ function abook_create_form($form_url,$name,$title,$button,$defdata=array()) {
                                       'center', $color[0]
                                       )
                             )
-                  , 'center', '', 'width="100%"' ) ."\n";
+                  , 'center', '', 'width="90%"' ) ."\n";
     address_form($name, $button, $defdata);
 }