- added more hooks
[squirrelmail.git] / functions / addressbook.php
index bafa53be7a4e8aeb18e96195a2afe4c1bdb34a56..45f586b38b7e0d9da0a5709349c1e5feebe8b429 100644 (file)
 
       // Return a list of addresses matching expression in
       // all backends of a given type.
-      function search($expression, $btype = "") {
+      function search($expression, $bnum = -1) {
         $ret = array();
         $this->error = "";
 
-        $sel = $this->get_backend_list($btype);
-        $failed = 0;
-        for($i = 0 ; $i < sizeof($sel) ; $i++) {
-           $backend = &$sel[$i];
-           $backend->error = "";
-           $res = $backend->search($expression);
-           if(is_array($res)) {
-              $ret = array_merge($ret, $res);
-           } else {
-              $this->error = $this->error . "<br>\n". $backend->error;
-              $failed++;
+        // Search all backends
+        if($bnum == -1) {
+           $sel = $this->get_backend_list("");
+           $failed = 0;
+           for($i = 0 ; $i < sizeof($sel) ; $i++) {
+              $backend = &$sel[$i];
+              $backend->error = "";
+              $res = $backend->search($expression);
+              if(is_array($res)) {
+                 $ret = array_merge($ret, $res);
+              } else {
+                 $this->error = $this->error . "<br>\n". $backend->error;
+                 $failed++;
+              }
            }
+
+           // Only fail if all backends failed
+           if($failed >= sizeof($sel))
+              return false;
+
         }
 
-        // Only fail if all backends failed
-        if($failed >= sizeof($sel))
-           return false;
+        // Search only one backend
+        else {
+           $ret = $this->backends[$bnum]->search($expression);
+           if(!is_array($ret)) {
+              $this->error = $this->error . "<br>\n". $this->backends[$bnum]->error;
+              return false;
+           }
+        }
 
         return $ret;
       }
 
 
       // Return a sorted search
-      function s_search($expression, $btype = "") {
+      function s_search($expression, $bnum = -1) {
 
-        $ret = $this->search($expression, $btype);
+        $ret = $this->search($expression, $bnum);
         if(!is_array($ret))
            return $ret;
 
 
 
       // Return all addresses
-      function list_addr() {
+      function list_addr($bnum = -1) {
         $ret = array();
 
-        $sel = $this->get_backend_list("local");
+        if($bnum == -1) 
+           $sel = $this->get_backend_list("local");
+        else
+           $sel = array(0 => &$this->backends[$bnum]);
+
         for($i = 0 ; $i < sizeof($sel) ; $i++) {
            $backend = &$sel[$i];
            $backend->error = "";