From e4b5049df903a2faf9877732a4286cf6dc8b6706 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 14 Jun 2003 12:16:59 +0000 Subject: [PATCH] moved suffix search to ldap.inc removed unneeded echo in profilecreate.php --- lam/lib/ldap.inc | 17 +++++++++++++++++ lam/templates/lists/listgroups.php | 15 +-------------- lam/templates/lists/listhosts.php | 15 +-------------- lam/templates/profedit/profilecreate.php | 2 +- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc index daa2bade..2326647b 100644 --- a/lam/lib/ldap.inc +++ b/lam/lib/ldap.inc @@ -132,6 +132,23 @@ class Ldap{ } } + // returns an array with all organizational units under the given suffix + function search_units($suffix) { + $sr = @ldap_search($_SESSION["ldap"]->server(), $suffix, "objectClass=organizationalunit", array("DN")); + if ($sr) { + $units = ldap_get_entries($_SESSION["ldap"]->server, $sr); + // delete first array entry which is "count" + array_shift($units); + // remove sub arrays + for ($i = 0; $i < sizeof($units); $i++) $units[$i] = $units[$i]['dn']; + // add root suffix if needed + if (!in_array($suffix, $units)) { + array_push($units, $suffix); + } + } + return $units; + } + // returns the LDAP connection handle function server() { return $this->server; diff --git a/lam/templates/lists/listgroups.php b/lam/templates/lists/listgroups.php index 0a588d1c..9373f5bb 100644 --- a/lam/templates/lists/listgroups.php +++ b/lam/templates/lists/listgroups.php @@ -231,20 +231,7 @@ echo ("
\n"); if (! $_GET['norefresh']) { // generate list of possible suffixes - $sr = @ldap_search($_SESSION["ldap"]->server(), - $_SESSION["config"]->get_GroupSuffix(), - "objectClass=organizationalunit", array("DN")); - if ($sr) { - $grp_units = ldap_get_entries($_SESSION["ldap"]->server, $sr); - // delete first array entry which is "count" - array_shift($grp_units); - // remove sub arrays - for ($i = 0; $i < sizeof($grp_units); $i++) $grp_units[$i] = $grp_units[$i]['dn']; - // add root suffix from config - if (!in_array($_SESSION["config"]->get_GroupSuffix(), $grp_units)) { - array_push($grp_units, $_SESSION["config"]->get_GroupSuffix()); - } - } + $grp_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_GroupSuffix()); } echo ("

\n"); diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index 9db7e426..295986ad 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -225,20 +225,7 @@ echo ("
\n"); if (! $_GET['norefresh']) { // generate list of possible suffixes - $sr = @ldap_search($_SESSION["ldap"]->server(), - $_SESSION["config"]->get_HostSuffix(), - "objectClass=organizationalunit", array("DN")); - if ($sr) { - $hst_units = ldap_get_entries($_SESSION["ldap"]->server, $sr); - // delete first array entry which is "count" - array_shift($hst_units); - // remove sub arrays - for ($i = 0; $i < sizeof($hst_units); $i++) $hst_units[$i] = $hst_units[$i]['dn']; - // add root suffix from config - if (!in_array($_SESSION["config"]->get_HostSuffix(), $hst_units)) { - array_push($hst_units, $_SESSION["config"]->get_HostSuffix()); - } - } +$hst_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_HostSuffix()); } echo ("

\n"); diff --git a/lam/templates/profedit/profilecreate.php b/lam/templates/profedit/profilecreate.php index e3690d32..22aa563d 100644 --- a/lam/templates/profedit/profilecreate.php +++ b/lam/templates/profedit/profilecreate.php @@ -274,7 +274,7 @@ elseif ($_GET['type'] == "host") { } // error: no or wrong type -else echo (StatusMessage("ERROR", "", _("No type specified!"))); +else StatusMessage("ERROR", "", _("No type specified!")); echo ("\n");