From 479f893f6ddef6a102b8f4ff3f68fc0b64838710 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 15 Aug 2013 15:55:06 +0200 Subject: [PATCH] LDAP: Show Host name in configuration drop down --- apps/user_ldap/lib/helper.php | 28 +++++++++++++++++++++++++++ apps/user_ldap/settings.php | 2 ++ apps/user_ldap/templates/settings.php | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php index f65f466789..4c9dd07a12 100644 --- a/apps/user_ldap/lib/helper.php +++ b/apps/user_ldap/lib/helper.php @@ -70,6 +70,34 @@ class Helper { return $prefixes; } + /** + * + * @brief determines the host for every configured connection + * @return an array with configprefix as keys + * + */ + static public function getServerConfigurationHosts() { + $referenceConfigkey = 'ldap_host'; + + $query = ' + SELECT DISTINCT `configkey`, `configvalue` + FROM `*PREFIX*appconfig` + WHERE `appid` = \'user_ldap\' + AND `configkey` LIKE ? + '; + $query = \OCP\DB::prepare($query); + $configHosts = $query->execute(array('%'.$referenceConfigkey))->fetchAll(); + $result = array(); + + foreach($configHosts as $configHost) { + $len = strlen($configHost['configkey']) - strlen($referenceConfigkey); + $prefix = substr($configHost['configkey'], 0, $len); + $result[$prefix] = $configHost['configvalue']; + } + + return $result; + } + /** * @brief deletes a given saved LDAP/AD server configuration. * @param string the configuration prefix of the config to delete diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 22e2dac6d2..7169192a18 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -44,7 +44,9 @@ OCP\Util::addstyle('user_ldap', 'settings'); $tmpl = new OCP\Template('user_ldap', 'settings'); $prefixes = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes(); +$hosts = \OCA\user_ldap\lib\Helper::getServerConfigurationHosts(); $tmpl->assign('serverConfigurationPrefixes', $prefixes); +$tmpl->assign('serverConfigurationHosts', $hosts); // assign default values if(!isset($ldap)) { diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index c051ea5cfe..e214d57fb1 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -24,7 +24,7 @@ $sel = ' selected'; foreach($_['serverConfigurationPrefixes'] as $prefix) { ?> - +