From b66fd35204f785743212e5565910c0da49a5b8d8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 25 Apr 2011 17:46:57 +0000 Subject: [PATCH] types specify suffix list --- lam/docs/devel/profile_editor.htm | 2 +- lam/lib/baseType.inc | 34 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lam/docs/devel/profile_editor.htm b/lam/docs/devel/profile_editor.htm index 19cc6038..04395f00 100644 --- a/lam/docs/devel/profile_editor.htm +++ b/lam/docs/devel/profile_editor.htm @@ -31,7 +31,7 @@ This script is used to display the account profile to the user.
The profile options include the LDAP OU suffix and options provided by the account modules.

-The values for the OU selection are read with search_units().
+The values for the OU selection are read with type->getSuffixList().

The account modules provide all other profile options. The profile editor displays a separate diff --git a/lam/lib/baseType.inc b/lam/lib/baseType.inc index e6ca6852..251c0356 100644 --- a/lam/lib/baseType.inc +++ b/lam/lib/baseType.inc @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2005 - 2010 Roland Gruber + Copyright (C) 2005 - 2011 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -129,6 +129,38 @@ class baseType { public function getTitleBarSubtitle($attributes) { return null; } + + /** + * Returns a list of LDAP suffixes for this type. + * + * @return array sorted list of possible suffixes for this type. + */ + public function getSuffixList() { + $suffix = $_SESSION["config"]->get_Suffix(get_class($this)); + $ret = array(); + $sr = @ldap_search($_SESSION["ldap"]->server(), escapeDN($suffix), "objectClass=organizationalunit", array("DN"), 0, 0, 0, LDAP_DEREF_NEVER); + if ($sr) { + $units = ldap_get_entries($_SESSION["ldap"]->server(), $sr); + $units = cleanLDAPResult($units); + // extract Dns + for ($i = 0; $i < sizeof($units); $i++) { + if ($units[$i]['dn']) $ret[] = $units[$i]['dn']; + } + } + // add root suffix if needed + $found = false; + for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive + if (strtolower($suffix) == strtolower($ret[$i])) { + $found = true; + break; + } + } + if (!$found) { + $ret[] = $suffix; + } + usort($ret, 'compareDN'); + return $ret; + } }