X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Faddressbook.php;h=08246cd6cf9446d62b145f1872b2cc2f15690d19;hb=d622d38af6c2101b24c27851caf30866070c90c1;hp=26b6aed3a8c71a1f0f17db38c4ace99f4eb5959a;hpb=f435778e5dabea883d6394d5ab43ae72d51dfd50;p=squirrelmail.git diff --git a/functions/addressbook.php b/functions/addressbook.php index 26b6aed3..08246cd6 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -1,58 +1,89 @@ in main directory) + // + // If you don't want a global site-wide addressbook, comment these + // two lines out. (They are disabled by default.) + // + // The global addressbook is unmodifiable by anyone. You must actually + // use a shell script or whatnot to modify the contents. + // + //global $data_dir; + //$address_book_global_filename = "$data_dir/global.abook"; + + // Include backends here. - include('../functions/abook_local_file.php'); - include('../functions/abook_ldap_server.php'); + require_once('../functions/abook_local_file.php'); + require_once('../functions/abook_ldap_server.php'); - // Un-comment if you're using database backend - // include('../functions/abook_database.php'); + // Use this if you wanna have a global address book + if (isset($address_book_global_filename)) + include_once('../functions/abook_global_file.php'); + + // Only load database backend if database is configured + global $addrbook_dsn; + if(isset($addrbook_dsn)) + include_once('../functions/abook_database.php'); // Create and initialize an addressbook object. // Returns the created object function addressbook_init($showerr = true, $onlylocal = false) { - global $data_dir, $username, $ldap_server; + global $data_dir, $username, $ldap_server, $address_book_global_filename; + global $addrbook_dsn; // Create a new addressbook 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)); + // Always add a local backend. We use *either* file-based *or* a + // database addressbook. If $addrbook_dsn is set, the database + // backend is used. If not, addressbooks are stores in files. + if(isset($addrbook_dsn) && !empty($addrbook_dsn)) { + // Database + $r = $abook->add_backend('database', Array('dsn' => $addrbook_dsn, + 'owner' => $username, + 'table' => 'address')); + if(!$r && $showerr) { + printf(_("Error initializing addressbook database.")); + exit; + } + } else { + // File + $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; + } + + } - if(!$r && $showerr) { - printf(_("Error opening file %s"), $filename); - exit; + // This would be for the global addressbook + if (isset($address_book_global_filename)) { + $r = $abook->add_backend('global_file'); + if (!$r && $showerr) { + printf(_("Error initializing global addressbook.")); + 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; @@ -284,7 +315,7 @@ } if(eregi('[ \\:\\|\\#\\"\\!]', $userdata['nickname'])) { - $this->error = _("Nickname contain illegal characters"); + $this->error = _("Nickname contains illegal characters"); return false; } @@ -362,7 +393,7 @@ } if(eregi('[\\: \\|\\#"\\!]', $userdata['nickname'])) { - $this->error = _("Nickname contain illegal characters"); + $this->error = _("Nickname contains illegal characters"); return false; }