From 2d3e2bc56108fc014edfaa154237b551daea4cc0 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 21 Sep 2011 07:17:46 -0400
Subject: [PATCH] Add option 'searchonly' for address books; currently used by LDAP directories

---
 program/localization/de_DE/messages.inc |    1 +
 program/steps/addressbook/list.inc      |    3 +++
 CHANGELOG                               |    1 +
 program/include/rcube_addressbook.php   |    1 +
 program/include/rcube_ldap.php          |    9 +++++++++
 program/include/rcube_result_set.php    |    3 ++-
 program/localization/de_CH/messages.inc |    1 +
 program/localization/en_US/messages.inc |    1 +
 config/main.inc.php.dist                |    4 +++-
 9 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 2b2cfbe..f4100da 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Add option 'searchonly' for LDAP address books
 - Add Priority filter to the messages list
 - Cache synchronization using QRESYNC/CONDSTORE
 - Fix locked folder rename option on servers supporting RFC2086 only (#1488089)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 941795f..466c2bd 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -540,9 +540,11 @@
   'auth_cid'       => '',
   // SASL authentication method (for proxy auth), e.g. DIGEST-MD5
   'auth_method'    => '',
-  // Indicates if the addressbook shall be displayed on the list.
+  // Indicates if the addressbook shall be hidden from the list.
   // With this option enabled you can still search/view contacts.
   'hidden'        => false,
+  // Indicates if the addressbook shall not list contacts but only allows searching.
+  'searchonly'    => false,
   // Indicates if we can write to the LDAP directory or not.
   // If writable is true then these fields need to be populated:
   // LDAP_Object_Classes, required_fields, LDAP_rdn
diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php
index 6d126e9..94a715b 100644
--- a/program/include/rcube_addressbook.php
+++ b/program/include/rcube_addressbook.php
@@ -38,6 +38,7 @@
     public $primary_key;
     public $groups = false;
     public $readonly = true;
+    public $searchonly = false;
     public $undelete = false;
     public $ready = false;
     public $group_id = null;
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index c6ca88e..13e7b54 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -71,6 +71,9 @@
     function __construct($p, $debug=false, $mail_domain=NULL)
     {
         $this->prop = $p;
+        
+        if (isset($p['searchonly']))
+            $this->searchonly = $p['searchonly'];
 
         // check if groups are configured
         if (is_array($p['groups']) && count($p['groups'])) {
@@ -429,6 +432,12 @@
      */
     function list_records($cols=null, $subset=0)
     {
+        if ($this->prop['searchonly'] && empty($this->filter) && !$this->group_id) {
+            $this->result = new rcube_result_set(0);
+            $this->result->searchonly = true;
+            return $this->result;
+        }
+        
         // add general filter to query
         if (!empty($this->prop['filter']) && empty($this->filter))
         {
diff --git a/program/include/rcube_result_set.php b/program/include/rcube_result_set.php
index 1036160..db52fc5 100644
--- a/program/include/rcube_result_set.php
+++ b/program/include/rcube_result_set.php
@@ -5,7 +5,7 @@
  | program/include/rcube_result_set.php                                  |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2006-2010, The Roundcube Dev Team                       |
+ | Copyright (C) 2006-2011, The Roundcube Dev Team                       |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -31,6 +31,7 @@
     var $count = 0;
     var $first = 0;
     var $current = 0;
+    var $searchonly = false;
     var $records = array();
 
 
diff --git a/program/localization/de_CH/messages.inc b/program/localization/de_CH/messages.inc
index e7277e3..151fe25 100644
--- a/program/localization/de_CH/messages.inc
+++ b/program/localization/de_CH/messages.inc
@@ -48,6 +48,7 @@
 $messages['encryptedmessage'] = 'Dies ist eine verschlüsselte Nachricht und kann leider nicht angezeigt werden.';
 $messages['nocontactsfound'] = 'Keine Kontakte gefunden';
 $messages['contactnotfound'] = 'Die gewählte Adresse wurde nicht gefunden';
+$messages['contactsearchonly'] = 'Geben Sie einen Suchbegriff ein, um Kontakte zu finden';
 $messages['sendingfailed'] = 'Versand der Nachricht fehlgeschlagen';
 $messages['senttooquickly'] = 'Bitte warten Sie $sec Sekunde(n) vor dem Senden dieser Nachricht';
 $messages['errorsavingsent'] = 'Ein Fehler ist beim Speichern der gesendeten Nachricht aufgetreten';
diff --git a/program/localization/de_DE/messages.inc b/program/localization/de_DE/messages.inc
index 59bf360..e88ea90 100644
--- a/program/localization/de_DE/messages.inc
+++ b/program/localization/de_DE/messages.inc
@@ -49,6 +49,7 @@
 $messages['encryptedmessage'] = 'Dies ist eine verschlüsselte Nachricht und kann leider nicht angezeigt werden.';
 $messages['nocontactsfound'] = 'Keine Kontakte gefunden';
 $messages['contactnotfound'] = 'Der angeforderte Kontakt wurde nicht gefunden';
+$messages['contactsearchonly'] = 'Geben Sie einen Suchbegriff ein, um Kontakte zu finden';
 $messages['sendingfailed'] = 'Versenden der Nachricht fehlgeschlagen';
 $messages['senttooquickly'] = 'Bitte warten Sie $sec Sekunde(n) vor dem Senden dieser Nachricht';
 $messages['errorsavingsent'] = 'Ein Fehler ist beim Speichern der gesendeten Nachricht aufgetreten';
diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc
index 65bc9ca..8ca06a6 100644
--- a/program/localization/en_US/messages.inc
+++ b/program/localization/en_US/messages.inc
@@ -48,6 +48,7 @@
 $messages['encryptedmessage'] = 'This is an encrypted message and can not be displayed. Sorry!';
 $messages['nocontactsfound'] = 'No contacts found.';
 $messages['contactnotfound'] = 'The requested contact was not found.';
+$messages['contactsearchonly'] = 'Enter some search terms to find contacts';
 $messages['sendingfailed'] = 'Failed to send message.';
 $messages['senttooquickly'] = 'Please wait $sec sec(s). before sending this message.';
 $messages['errorsavingsent'] = 'An error occured while saving sent message.';
diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc
index dbc86e2..313b52e 100644
--- a/program/steps/addressbook/list.inc
+++ b/program/steps/addressbook/list.inc
@@ -73,6 +73,9 @@
 
     // get contacts for this user
     $result = $CONTACTS->list_records(array('name'));
+    
+    if (!$result->count && $result->searchonly)
+        $OUTPUT->show_message('contactsearchonly', 'notice');
 }
 
 // update message count display

--
Gitblit v1.9.1