Improved error handling.
authorpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 30 Mar 2000 20:01:15 +0000 (20:01 +0000)
committerpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 30 Mar 2000 20:01:15 +0000 (20:01 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@360 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/addressbook.php

index 5ba87caa90514c8bb1d5ca1af9e13c0ab07f7a09..738be3ffa7d0d11ecd209a5fd39d65569fc7c9e7 100644 (file)
@@ -15,7 +15,7 @@
 
    // Create and initialize an addressbook object. 
    // Returns the created object
-   function addressbook_init() {
+   function addressbook_init($showerr = true, $onlylocal = false) {
       global $data_dir, $username, $ldap_server;
       
       // Create a new addressbook object
       $filename = sprintf("%s%s.abook", $data_dir, $username);
       $r = $abook->add_backend("local_file", Array("filename" => $filename,
                                                   "create"   => true));
-      if(!$r) {
+      if(!$r && $showerr) {
         printf(_("Error opening file %s"), $filename);
         exit;
       }
-     
+
+      if($onlylocal)
+       return $abook;
 
       // Load configured LDAP servers
       reset($ldap_server);
       while(list($key,$param) = each($ldap_server)) {
         if(is_array($param)) {
            $r = $abook->add_backend("ldap_server", $param);
-            if(!$r) {
+            if(!$r && $showerr) {
               printf("&nbsp;"._("Error initializing LDAP server %s:")."<BR>\n",
                      $param["host"]);
               printf("&nbsp;".$abook->error);
       // all backends of a given type.
       function search($expression, $btype = "") {
         $ret = array();
+        $this->error = "";
 
         $sel = $this->get_backend_list($btype);
+        $failed = 0;
         for($i = 0 ; $i < sizeof($sel) ; $i++) {
            $backend = &$sel[$i];
            $backend->error = "";
            if(is_array($res)) {
               $ret = array_merge($ret, $res);
            } else {
-              $this->error = $backend->error;
-              return false;
+              $this->error = $this->error . "<br>\n". $backend->error;
+              $failed++;
            }
         }
 
+        // Only fail if all backends failed
+        if($failed >= sizeof($sel))
+           return false;
+
         return $ret;
       }
 
 
       // Return a sorted search
       function s_search($expression, $btype = "") {
+
         $ret = $this->search($expression, $btype);
+        if(!is_array($ret))
+           return $ret;
 
         // Inline function - Not nice, but still.. 
         function cmp($a,$b) {