From baecd8becccd7786632c1cda895123293ceb1408 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Thu, 26 Jul 2012 11:18:38 -0400
Subject: [PATCH] Move the hard-coded list of fields used to list contacts to a central location

---
 program/steps/addressbook/list.inc   |    6 ++++--
 program/include/rcube_ldap.php       |    4 +++-
 program/steps/mail/autocomplete.inc  |    4 ++--
 program/steps/addressbook/delete.inc |    3 ++-
 program/steps/mail/list_contacts.inc |    3 ++-
 program/include/rcube_config.php     |    5 +++++
 program/steps/addressbook/search.inc |    3 ++-
 7 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index 1b621e0..9db746f 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -49,6 +49,11 @@
     public function __construct()
     {
         $this->load();
+
+        // Defaults, that we do not require you to configure,
+        // but contain information that is used in various
+        // locations in the code:
+        $this->set('contactlist_fields', array('name', 'firstname', 'surname', 'email'));
     }
 
 
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 6a32a23..3a7fc18 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -767,7 +767,9 @@
         }
 
         // use VLV pseudo-search for autocompletion
-        if ($this->prop['vlv_search'] && $this->conn && join(',', (array)$fields) == 'name,firstname,surname,email')
+        $rcmail = rcmail::get_instance();
+
+        if ($this->prop['vlv_search'] && $this->conn && join(',', (array)$fields) == join(',', $rcmail->config->get('contactlist_fields')))
         {
             // add general filter to query
             if (!empty($this->prop['filter']) && empty($this->filter))
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index a2f1249..81b8a09 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -70,6 +70,7 @@
 // update saved search after data changed
 if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) {
     $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
+    $afields = $RCMAIL->config->get('contactlist_fields');
     $search  = (array)$_SESSION['search'][$search_request];
     $records = array();
 
@@ -83,7 +84,7 @@
         $source->set_search_set($set);
 
         // get records
-        $result = $source->list_records(array('name', 'firstname', 'surname', 'email'));
+        $result = $source->list_records($afields);
 
         if (!$result->count) {
             unset($search[$s]);
diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc
index a24fb95..06a1e10 100644
--- a/program/steps/addressbook/list.inc
+++ b/program/steps/addressbook/list.inc
@@ -19,6 +19,8 @@
  +-----------------------------------------------------------------------+
 */
 
+$afields = $RCMAIL->config->get('contactlist_fields');
+
 // Use search result
 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
 {
@@ -43,7 +45,7 @@
         $source->set_search_set($set);
 
         // get records
-        $result = $source->list_records(array('name', 'firstname', 'surname', 'email'));
+        $result = $source->list_records($afields);
 
         while ($row = $result->next()) {
             $row['sourceid'] = $s;
@@ -73,7 +75,7 @@
     $CONTACTS = rcmail_contact_source(null, true);
 
     // get contacts for this user
-    $result = $CONTACTS->list_records(array('name', 'firstname', 'surname', 'email'));
+    $result = $CONTACTS->list_records($afields);
 
     if (!$result->count && $result->searchonly) {
         $OUTPUT->show_message('contactsearchonly', 'notice');
diff --git a/program/steps/addressbook/search.inc b/program/steps/addressbook/search.inc
index f83eb9f..d31e54b 100644
--- a/program/steps/addressbook/search.inc
+++ b/program/steps/addressbook/search.inc
@@ -145,6 +145,7 @@
     $search_set = array();
     $records    = array();
     $sort_col   = $RCMAIL->config->get('addressbook_sort_col', 'name');
+    $afields = $RCMAIL->config->get('contactlist_fields');
 
     foreach ($sources as $s) {
         $source = $RCMAIL->get_address_book($s['id']);
@@ -179,7 +180,7 @@
         }
 
         // get records
-        $result = $source->list_records(array('name', 'firstname', 'surname', 'email'));
+        $result = $source->list_records($afields);
 
         while ($row = $result->next()) {
             $row['sourceid'] = $s['id'];
diff --git a/program/steps/mail/autocomplete.inc b/program/steps/mail/autocomplete.inc
index ba34fa5..5557981 100644
--- a/program/steps/mail/autocomplete.inc
+++ b/program/steps/mail/autocomplete.inc
@@ -26,7 +26,7 @@
     $members = array();
     $abook->set_group($gid);
     $abook->set_pagesize(1000);  // TODO: limit number of group members by config
-    $result = $abook->list_records(array('name', 'firstname', 'surname', 'email'));
+    $result = $abook->list_records($RCMAIL->config->get('contactlist_fields'));
     while ($result && ($sql_arr = $result->iterate())) {
       foreach ((array)$sql_arr['email'] as $email) {
         $members[] = format_email_recipient($email, rcube_addressbook::compose_list_name($sql_arr));
@@ -64,7 +64,7 @@
     $abook = $RCMAIL->get_address_book($id);
     $abook->set_pagesize($MAXNUM);
 
-    if ($result = $abook->search(array('name', 'firstname', 'surname', 'email'), $search, $mode, true, true, 'email')) {
+    if ($result = $abook->search($RCMAIL->config->get('contactlist_fields'), $search, $mode, true, true, 'email')) {
       while ($sql_arr = $result->iterate()) {
         // Contact can have more than one e-mail address
         $email_arr = (array)$abook->get_col_values('email', $sql_arr, true);
diff --git a/program/steps/mail/list_contacts.inc b/program/steps/mail/list_contacts.inc
index 1a64803..7c99a13 100644
--- a/program/steps/mail/list_contacts.inc
+++ b/program/steps/mail/list_contacts.inc
@@ -57,7 +57,8 @@
 
     // get contacts for this user
     $CONTACTS->set_group(0);
-    $result = $CONTACTS->list_records(array('name', 'firstname', 'surname', 'email'));
+    $afields = $RCMAIL->config->get('contactlist_fields');
+    $result = $CONTACTS->list_records($afields);
 
     if (!$result->count && $result->searchonly) {
         $OUTPUT->show_message('contactsearchonly', 'notice');

--
Gitblit v1.9.1