Converted all files in functions/ to use SM_PATH. This will break all
[squirrelmail.git] / functions / addressbook.php
index 61b9e7beefd811cc2a246c4cf53731f81d02631d..f62ccde50fdc0f752c2968d05edf02a7d4864ea2 100644 (file)
@@ -30,8 +30,8 @@
   Include backends here.
 */
 
-require_once('../functions/abook_local_file.php');
-require_once('../functions/abook_ldap_server.php');
+require_once(SM_PATH . 'functions/abook_local_file.php');
+require_once(SM_PATH . 'functions/abook_ldap_server.php');
 
 global $addrbook_dsn;
 
@@ -51,7 +51,7 @@ if(isset($addrbook_dsn) && !empty($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.