From 1a6d8448ec92a6ef6e4eb642eba48695cfe07f1c Mon Sep 17 00:00:00 2001 From: alec Date: Wed, 20 Jul 2011 12:52:59 +0000 Subject: - Add user identifier autocomplete feature (LDAP only) git-svn-id: https://svn.roundcube.net/trunk@4943 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/acl/acl.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'plugins/acl/acl.php') diff --git a/plugins/acl/acl.php b/plugins/acl/acl.php index 552b5032b..24dcc95d4 100644 --- a/plugins/acl/acl.php +++ b/plugins/acl/acl.php @@ -3,7 +3,7 @@ /** * Folders Access Control Lists Management (RFC4314, RFC2086) * - * @version 0.3 + * @version 0.4 * @author Aleksander Machniak * * @@ -30,6 +30,7 @@ class acl extends rcube_plugin private $rc; private $supported = null; private $mbox; + private $ldap; private $specials = array('anyone', 'anonymous'); /** @@ -45,6 +46,7 @@ class acl extends rcube_plugin $this->add_hook('addressbook_form', array($this, 'folder_form')); // Plugin actions $this->register_action('plugin.acl', array($this, 'acl_actions')); + $this->register_action('plugin.acl-autocomplete', array($this, 'acl_autocomplete')); } /** @@ -76,6 +78,45 @@ class acl extends rcube_plugin $this->rc->output->send(); } + /** + * Handler for user login autocomplete request + */ + function acl_autocomplete() + { + $this->load_config(); + + $search = get_input_value('_search', RCUBE_INPUT_GPC, true); + $uid_field = $this->rc->config->get('acl_users_uid_field', 'uid'); + $users = array(); + + if ($this->init_ldap()) { + $this->ldap->set_pagesize(15); + $result = $this->ldap->search('*', $search); + + foreach ($result->records as $record) { + $user = $record[$uid_field]; + + if (is_array($user)) { + $user = array_filter($user); + $user = $user[0]; + } + + if ($user) { + + if ($record['name']) + $user = $record['name'] . ' (' . $user . ')'; + + $users[] = $user; + } + } + } + + sort($users, SORT_LOCALE_STRING); + + $this->rc->output->command('ksearch_query_results', $users, $search); + $this->rc->output->send(); + } + /** * Handler for 'folder_form' hook * @@ -138,6 +179,7 @@ class acl extends rcube_plugin // The 'Sharing' tab $this->mbox = $mbox_imap; + $this->rc->output->set_env('acl_users_source', (bool) $this->rc->config->get('acl_users_source')); $this->rc->output->set_env('mailbox', $mbox_imap); $this->rc->output->add_handlers(array( 'acltable' => array($this, 'templ_table'), @@ -573,4 +615,44 @@ class acl extends rcube_plugin return $_SESSION['acl_username_realm'] = $domain; } + + /** + * Initializes autocomplete LDAP backend + */ + private function init_ldap() + { + if ($this->ldap) + return $this->ldap->ready; + + $ldap_config = (array) $this->rc->config->get('ldap_public'); + $addressbook = $this->rc->config->get('acl_users_source'); + $uid_field = $this->rc->config->get('acl_users_uid_field', 'uid'); + + if (empty($addressbook) || empty($uid_field) || empty($ldap_config[$addressbook])) { + return false; + } + + // search also in UID field + $ldap_config[$addressbook]['search_fields'] = array_unique( + array_merge((array)$uid_field, (array)$ldap_config[$addressbook]['search_fields'])); + + // add UID field to fieldmap, so it will be returned in a record + if (isset($ldap_config[$addressbook]['fieldmap'])) { + if (empty($ldap_config[$addressbook]['fieldmap']['uid'])) { + $ldap_config[$addressbook]['fieldmap']['uid'] = $uid_field; + } + } + // ... no fieldmap, use the old method + else if (empty($ldap_config[$addressbook]['uid_field'])) { + $ldap_config[$addressbook]['uid_field'] = $uid_field; + } + + // Initialize LDAP connection + $this->ldap = new rcube_ldap( + $ldap_config[$addressbook], + $this->rc->config->get('ldap_debug'), + $this->rc->config->mail_domain($_SESSION['imap_host'])); + + return $this->ldap->ready; + } } -- cgit v1.2.3