X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Faddressbook.php;h=705742df6bbd111ec26dab27f38b44f31b360f6e;hb=92948f86768dd49bf544b9f09cd134a07a9cf1eb;hp=dcafc36a68231d9a7020703676b4dfca498ef8f4;hpb=d6c32258c05219670ab3b4ae2d460d844ea9a247;p=squirrelmail.git diff --git a/functions/addressbook.php b/functions/addressbook.php index dcafc36a..705742df 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -3,13 +3,14 @@ /** * 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$ + * @version $Id$ * @package squirrelmail + * @subpackage addressbook */ /** @@ -30,7 +31,7 @@ */ -global $addrbook_dsn; +global $addrbook_dsn, $addrbook_global_dsn; /** Create and initialize an addressbook object. @@ -39,6 +40,7 @@ global $addrbook_dsn; 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; @@ -81,6 +83,30 @@ 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)); + } + + /* + * hook allows to include different address book backends. + * plugins should extract $abook and $r from arguments + * and use same add_backend commands as above functions. + */ + $hookReturn = do_hook('abook_init', $abook, $r); + $abook = $hookReturn[1]; + $r = $hookReturn[2]; + if ($onlylocal) { return $abook; } @@ -109,6 +135,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) { @@ -123,10 +150,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 { @@ -196,12 +223,10 @@ class AddressBook { function full_address($row) { global $addrsrch_fullname, $data_dir, $username; - - if (($prefix = getPref($data_dir, $username, 'addrsrch_fullname') or - isset($addrsrch_fullname) and $prefix = $addrsrch_fullname) - and $prefix !== 'noprefix') { - $name = ($prefix === 'nickname') ? $row['nickname'] - : $row['name']; + $prefix = getPref($data_dir, $username, 'addrsrch_fullname'); + if (($prefix != "" || (isset($addrsrch_fullname) && + $prefix == $addrsrch_fullname)) && $prefix != 'noprefix') { + $name = ($prefix == 'nickname' ? $row['nickname'] : $row['name']); return $name . ' <' . trim($row['email']) . '>'; } else { return trim($row['email']); @@ -388,7 +413,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; @@ -441,7 +466,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; @@ -462,8 +487,9 @@ class AddressBook { } /* End of class Addressbook */ -/* +/** * Generic backend that all other backends extend + * @package squirrelmail */ class addressbook_backend { @@ -520,8 +546,12 @@ class addressbook_backend { } -/* Sort array by the key "name" */ +/** + * Sort array by the key "name" + */ function alistcmp($a,$b) { + $abook_sort=get_abook_sort(); + if ($a['backend'] > $b['backend']) { return 1; } else { @@ -529,9 +559,31 @@ function alistcmp($a,$b) { return -1; } } - return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1; + return (strtolower($a[$abook_sort]) > strtolower($b[$abook_sort])) ? 1 : -1; } +/** + * Address book sorting order + * + * returns name of field that should be used for sorting. + * @return string name of address book field + */ +function get_abook_sort() { + global $data_dir, $username; + + /* get sorting order */ + if(sqgetGlobalVar('abook_sort', $abook_sort,SQ_GET)) { + sqgetGlobalVar('abook_sort', $abook_sort,SQ_GET); + setPref($data_dir, $username, 'abook_sort', $abook_sort); + } else { + $abook_sort = getPref($data_dir, $username, 'abook_sort', 'name'); + } + + if ($abook_sort != "nickname" && $abook_sort != "email" && $abook_sort != "label") + $abook_sort = "name"; + + return $abook_sort; +} /* PHP 5 requires that the class be made first, which seems rather @@ -547,9 +599,17 @@ if (isset($address_book_global_filename)) { } /* Only load database backend if database is configured */ -if(isset($addrbook_dsn) && !empty($addrbook_dsn)) { +if((isset($addrbook_dsn) && !empty($addrbook_dsn)) || + (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn)) ) { include_once(SM_PATH . 'functions/abook_database.php'); } +/* + * hook allows adding different address book classes. + * class must follow address book class coding standards. + * + * see addressbook_backend class and functions/abook_*.php files. + */ +do_hook('abook_add_class'); ?>