* Got bored and copied all the validate.php and define() stuff to 1.1
[squirrelmail.git] / functions / addressbook.php
index 2e2ccfda3192a5474199624d3da4d7ca9c510fa4..26b6aed3a8c71a1f0f17db38c4ace99f4eb5959a 100644 (file)
@@ -8,12 +8,17 @@
    **  $Id$
    **/
     
-   $addressbook_php = true;
+   if (defined ('addressbook_php'))
+      return; 
+   define ('addressbook_php', true); 
 
    // Include backends here.
    include('../functions/abook_local_file.php');
    include('../functions/abook_ldap_server.php');
 
+   // Un-comment if you're using database backend
+   // include('../functions/abook_database.php');
+
 
    // Create and initialize an addressbook object. 
    // Returns the created object
       $abook = new AddressBook;
       
       // Always add a local backend
+
+      // Use *either* file-based *or* database addressbook. Remove
+      // and insert comments to enable the one you want.
+
+      // ------ BEGIN Initialize file-based personal addressbook ------
       $filename = sprintf('%s%s.abook', $data_dir, $username);
       $r = $abook->add_backend('local_file', Array('filename' => $filename,
                                                   'create'   => true));
+
       if(!$r && $showerr) {
         printf(_("Error opening file %s"), $filename);
         exit;
       }
+      // ------ END Initialize file-based personal addressbook ------
+
+      // ------ BEGIN Initialize database-based personal addressbook ------
+      //      $r = $abook->add_backend('database', Array('dsn' => 'mysql://dbuser@host/dbname',
+      //                                                'owner' => $username,
+      //                                                'table' => 'address'));
+      //      if(!$r && $showerr) {
+      //        printf(_("Error initializing addressbook: %s"), $filename);
+      //        exit;
+      //      }
+      // ------ END Initialize database-based personal addressbook ------
 
       if($onlylocal)
        return $abook;
 
       // Load configured LDAP servers (if PHP has LDAP support)
-      if(is_array($ldap_server) && function_exists('ldap_connect')) {
+      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)) {
         $ret = array();
         for($i = 1 ; $i <= $this->numbackends ; $i++) {
            if(empty($type) || $type == $this->backends[$i]->btype) {
-              array_push($ret, &$this->backends[$i]);
+              $ret[] = &$this->backends[$i];
            }
         }
         return $ret;
            $userdata['nickname'] = $userdata['email'];
         }
 
-        if(eregi('[\\: \\|\\#\"\\!]', $userdata['nickname'])) {
+        if(eregi('[ \\:\\|\\#\\"\\!]', $userdata['nickname'])) {
            $this->error = _("Nickname contain illegal characters");
            return false;
         }