X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Faddressbook.php;h=ef757cf6e78fe39d8cd097701165c221f9b19fd8;hb=8d863f644ed0060232193a928e7786ac9bdb17c9;hp=b31a71f82b28106a67c4c2ac97a6525b7c5836a5;hpb=76911253eb850bacde3d86c8cb7b4af072e67ebe;p=squirrelmail.git diff --git a/functions/addressbook.php b/functions/addressbook.php index b31a71f8..ef757cf6 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -3,15 +3,16 @@ /** * addressbook.php * - * Copyright (c) 1999-2003 The SquirrelMail Project Team + * Copyright (c) 1999-2004 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * Functions and classes for the addressbook system. * * $Id$ + * @package squirrelmail */ -/* +/** This is the path to the global site-wide addressbook. It looks and feels just like a user's .abook file If this is in the data directory, use "$data_dir/global.abook" @@ -24,34 +25,21 @@ The global addressbook is unmodifiable by anyone. You must actually use a shell script or whatnot to modify the contents. - global $data_dir; + global $data_dir, $address_book_global_filename; $address_book_global_filename = "$data_dir/global.abook"; - Include backends here. */ -require_once(SM_PATH . 'functions/abook_local_file.php'); -require_once(SM_PATH . 'functions/abook_ldap_server.php'); - -global $addrbook_dsn; - -/* Use this if you wanna have a global address book */ -if (isset($address_book_global_filename)) { - include_once(SM_PATH . 'functions/abook_global_file.php'); -} - -/* Only load database backend if database is configured */ -if(isset($addrbook_dsn) && !empty($addrbook_dsn)) { - include_once(SM_PATH . 'functions/abook_database.php'); -} +global $addrbook_dsn, $addrbook_global_dsn; -/* +/** Create and initialize an addressbook object. Returns the created object */ function addressbook_init($showerr = true, $onlylocal = false) { global $data_dir, $username, $ldap_server, $address_book_global_filename; global $addrbook_dsn, $addrbook_table; + global $addrbook_global_dsn, $addrbook_global_table, $addrbook_global_writeable, $addrbook_global_listing; /* Create a new addressbook object */ $abook = new AddressBook; @@ -94,6 +82,21 @@ function addressbook_init($showerr = true, $onlylocal = false) { } } + /* Load global addressbook from SQL if configured */ + if (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) { + /* Database configured */ + if (!isset($addrbook_global_table) || empty($addrbook_global_table)) { + $addrbook_global_table = 'global_abook'; + } + $r = $abook->add_backend('database', + Array('dsn' => $addrbook_global_dsn, + 'owner' => 'global', + 'name' => _("Global address book"), + 'writeable' => $addrbook_global_writeable, + 'listing' => $addrbook_global_listing, + 'table' => $addrbook_global_table)); + } + if ($onlylocal) { return $abook; } @@ -122,6 +125,7 @@ function addressbook_init($showerr = true, $onlylocal = false) { /* * Had to move this function outside of the Addressbook Class * PHP 4.0.4 Seemed to be having problems with inline functions. + * Note: this can return now since we don't support 4.0.4 anymore. */ function addressbook_cmp($a,$b) { @@ -136,10 +140,10 @@ function addressbook_cmp($a,$b) { } -/* +/** * This is the main address book class that connect all the * backends and provide services to the functions above. - * + * @package squirrelmail */ class AddressBook { @@ -401,7 +405,7 @@ class AddressBook { $alias = array(0 => $alias); } - /* Check that specified backend is writable */ + /* Check that specified backend is writeable */ if (!$this->backends[$bnum]->writeable) { $this->error = _("Addressbook is read-only"); return false; @@ -454,7 +458,7 @@ class AddressBook { $userdata['nickname'] = $userdata['email']; } - /* Check that specified backend is writable */ + /* Check that specified backend is writeable */ if (!$this->backends[$bnum]->writeable) { $this->error = _("Addressbook is read-only");; return false; @@ -475,8 +479,9 @@ class AddressBook { } /* End of class Addressbook */ -/* +/** * Generic backend that all other backends extend + * @package squirrelmail */ class addressbook_backend { @@ -545,4 +550,25 @@ function alistcmp($a,$b) { return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1; } + +/* + PHP 5 requires that the class be made first, which seems rather + logical, and should have been the way it was generated the first time. +*/ + +require_once(SM_PATH . 'functions/abook_local_file.php'); +require_once(SM_PATH . 'functions/abook_ldap_server.php'); + +/* Use this if you wanna have a global address book */ +if (isset($address_book_global_filename)) { + include_once(SM_PATH . 'functions/abook_global_file.php'); +} + +/* Only load database backend if database is configured */ +if((isset($addrbook_dsn) && !empty($addrbook_dsn)) || + (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) ) { + include_once(SM_PATH . 'functions/abook_database.php'); +} + + ?>