X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Faddressbook.php;h=0e2a44aa421c83bed06383cc2c56cbaab2d19cca;hb=a9e67ec391e80d1df7fe52c21d7f106ddc3c5583;hp=271155daeb72a850c621b83781c08126639533e1;hpb=4935919f85eaa48efcfec39107bb7c2c1583cd56;p=squirrelmail.git diff --git a/functions/addressbook.php b/functions/addressbook.php index 271155da..0e2a44aa 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -3,7 +3,7 @@ /** * addressbook.php * - * Copyright (c) 1999-2001 The Squirrelmail Development Team + * Copyright (c) 1999-2002 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * Functions and classes for the addressbook system. @@ -41,7 +41,7 @@ if (isset($address_book_global_filename)) { } /* Only load database backend if database is configured */ -if(isset($addrbook_dsn)) { +if(isset($addrbook_dsn) && !empty($addrbook_dsn)) { include_once('../functions/abook_database.php'); } @@ -51,7 +51,7 @@ if(isset($addrbook_dsn)) { */ function addressbook_init($showerr = true, $onlylocal = false) { global $data_dir, $username, $ldap_server, $address_book_global_filename; - global $addrbook_dsn; + global $addrbook_dsn, $addrbook_table; /* Create a new addressbook object */ $abook = new AddressBook; @@ -63,9 +63,12 @@ function addressbook_init($showerr = true, $onlylocal = false) { */ if (isset($addrbook_dsn) && !empty($addrbook_dsn)) { /* Database */ + if (!isset($addrbook_table) || empty($addrbook_table)) { + $addrbook_table = 'address'; + } $r = $abook->add_backend('database', Array('dsn' => $addrbook_dsn, 'owner' => $username, - 'table' => 'address')); + 'table' => $addrbook_table)); if (!$r && $showerr) { echo _("Error initializing addressbook database."); exit; @@ -198,6 +201,26 @@ class AddressBook { } + /* + * This function takes a $row array as returned by the addressbook + * search and returns an e-mail address with the full name or + * nickname optionally prepended. + */ + + function full_address($row) { + global $addrsrch_fullname, $datadir, $user; + + if (($prefix = getPref($datadir, $user, 'addrsrch_fullname') or + isset($addrsrch_fullname) and $prefix = $addrsrch_fullname) + and $prefix !== 'noprefix') { + $name = ($prefix === 'nickname') ? $row['nickname'] + : $row['name']; + return $name . ' <' . trim($row['email']) . '>'; + } else { + return trim($row['email']); + } + } + /* Return a list of addresses matching expression in all backends of a given type. @@ -314,7 +337,6 @@ class AddressBook { return $ret; } - /* * Create a new address from $userdata, in backend $bnum. * Return the backend number that the/ address was added @@ -511,4 +533,16 @@ class addressbook_backend { } -?> \ No newline at end of file +/* Sort array by the key "name" */ +function alistcmp($a,$b) { + if ($a['backend'] > $b['backend']) { + return 1; + } else { + if ($a['backend'] < $b['backend']) { + return -1; + } + } + return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1; +} + +?>