From 16d28bd336f577213b3f6b825a1f01edda11cdf1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 23 Jan 2005 18:41:35 +0000 Subject: [PATCH] replaced LDAP filtering by local search; renamed some variables --- lam/templates/lists/listdomains.php | 61 +++++++------ lam/templates/lists/listgroups.php | 121 +++++++++++++------------- lam/templates/lists/listhosts.php | 113 +++++++++++++------------ lam/templates/lists/listusers.php | 127 +++++++++++++++------------- 4 files changed, 217 insertions(+), 205 deletions(-) diff --git a/lam/templates/lists/listdomains.php b/lam/templates/lists/listdomains.php index 38328937..392dfac3 100644 --- a/lam/templates/lists/listdomains.php +++ b/lam/templates/lists/listdomains.php @@ -45,13 +45,15 @@ session_save_path("../../sess"); setlanguage(); +$scope = 'domain'; + // get sorting column when register_globals is off $sort = $_GET['sort']; // copy HTTP-GET variables to HTTP-POST $_POST = $_POST + $_GET; -$dom_info = $_SESSION['dom_info']; +$info = $_SESSION[$scope . 'info']; $dom_units = $_SESSION['dom_units']; // check if button was pressed and if we have to add/delete a domain @@ -104,8 +106,11 @@ if ($_POST['dom_suffix']) $dom_suffix = $_POST['dom_suffix']; // new suffix sel elseif ($_SESSION['dom_suffix']) $dom_suffix = $_SESSION['dom_suffix']; // old suffix from session else $dom_suffix = $_SESSION["config"]->get_DomainSuffix(); // default suffix -// first time page is shown -if (! $_GET['norefresh']) { +$refresh = true; +if ($_GET['norefresh']) $refresh = false; +if ($_POST['refresh']) $refresh = true; + +if ($refresh) { // configure search filter $filter = "(objectClass=sambaDomain)"; $attrs = $attr_array; @@ -114,28 +119,28 @@ if (! $_GET['norefresh']) { StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem.")); } if ($sr) { - $dom_info = ldap_get_entries($_SESSION["ldap"]->server, $sr); + $info = ldap_get_entries($_SESSION["ldap"]->server, $sr); ldap_free_result($sr); - if ($dom_info["count"] == 0) StatusMessage("WARN", "", _("No Samba Domains found!")); + if ($info["count"] == 0) StatusMessage("WARN", "", _("No Samba domains found!")); // delete first array entry which is "count" - unset($dom_info['count']); + unset($info['count']); // sort rows by sort column ($sort) - $dom_info = listSort($sort, $attr_array, $dom_info); + $info = listSort($sort, $attr_array, $info); } - else StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No Samba Domains found!")); + else StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No Samba domains found!")); } // use search result from session else { - if (sizeof($dom_info) == 0) StatusMessage("WARN", "", _("No Samba Domains found!")); + if (sizeof($info) == 0) StatusMessage("WARN", "", _("No Samba domains found!")); // sort rows by sort column ($sort) - if ($dom_info) $dom_info = listSort($sort, $attr_array, $dom_info); + if ($info) $info = listSort($sort, $attr_array, $info); } -echo ("
\n"); +echo ("\n"); // draw navigation bar if domain accounts were found -if (sizeof($dom_info) > 0) { -listDrawNavigationBar(sizeof($dom_info), $max_page_entries, $page, $sort, '', "domain", _("%s Samba domain(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, '', "domain", _("%s Samba domain(s) found")); echo ("
\n"); } @@ -155,25 +160,25 @@ echo "\n"; // calculate which rows to show $table_begin = ($page - 1) * $max_page_entries; -if (($page * $max_page_entries) > sizeof($dom_info)) $table_end = sizeof($dom_info); +if (($page * $max_page_entries) > sizeof($info)) $table_end = sizeof($info); else $table_end = ($page * $max_page_entries); // print domain list for ($i = $table_begin; $i < $table_end; $i++) { - echo("" . - " " . - " " . _("Edit") . ""); + echo("" . + " " . + " " . _("Edit") . ""); for ($k = 0; $k < sizeof($attr_array); $k++) { echo (""); // print all attribute entries seperated by "; " - if (sizeof($dom_info[$i][strtolower($attr_array[$k])]) > 0) { + if (sizeof($info[$i][strtolower($attr_array[$k])]) > 0) { // delete first array entry which is "count" - if (is_array($dom_info[$i][strtolower($attr_array[$k])])) unset($dom_info[$i][strtolower($attr_array[$k])]['count']); - if (is_array($dom_info[$i][strtolower($attr_array[$k])])) echo implode("; ", $dom_info[$i][strtolower($attr_array[$k])]); - else echo $dom_info[$i][strtolower($attr_array[$k])]; + if (is_array($info[$i][strtolower($attr_array[$k])])) unset($info[$i][strtolower($attr_array[$k])]['count']); + if (is_array($info[$i][strtolower($attr_array[$k])])) echo implode("; ", $info[$i][strtolower($attr_array[$k])]); + else echo $info[$i][strtolower($attr_array[$k])]; } echo (""); } @@ -184,8 +189,8 @@ echo (""); echo ("
"); // draw navigation bar if domain accounts were found -if (sizeof($dom_info) > 0) { -listDrawNavigationBar(sizeof($dom_info), $max_page_entries, $page, $sort, '', "domain", _("%s Samba domain(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, '', "domain", _("%s Samba domain(s) found")); echo ("
\n"); } @@ -211,7 +216,7 @@ if (sizeof($dom_units) > 1) { echo ("

\n"); echo ("\n"); -if (sizeof($dom_info) > 0) echo ("\n"); +if (sizeof($info) > 0) echo ("\n"); echo ("

\n"); echo ("
\n"); @@ -220,7 +225,7 @@ echo "\n"; // save variables to session -$_SESSION['dom_info'] = $dom_info; +$_SESSION[$scope . 'info'] = $info; $_SESSION['dom_units'] = $dom_units; $_SESSION['dom_suffix'] = $dom_suffix; diff --git a/lam/templates/lists/listgroups.php b/lam/templates/lists/listgroups.php index 27f750ca..182efa5e 100644 --- a/lam/templates/lists/listgroups.php +++ b/lam/templates/lists/listgroups.php @@ -49,13 +49,15 @@ session_save_path("../../sess"); setlanguage(); +$scope = 'group'; + // get sorting column when register_globals is off $sort = $_GET['sort']; // copy HTTP-GET variables to HTTP-POST $_POST = $_POST + $_GET; -$grp_info = $_SESSION['grp_info']; +$info = $_SESSION[$scope . 'info']; $grp_units = $_SESSION['grp_units']; // check if button was pressed and if we have to add/delete a group @@ -95,9 +97,9 @@ if ($_POST['new_group'] || $_POST['del_group'] || $_POST['pdf_group'] || $_POST[ // PDF for all groups elseif ($_POST['pdf_all']){ $list = array(); - for ($i = 0; $i < sizeof($_SESSION['grp_info']); $i++) { + for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) { $_SESSION["accountPDF-$i"] = new accountContainer("group", "accountPDF-$i"); - $_SESSION["accountPDF-$i"]->load_account($_SESSION['grp_info'][$i]['dn']); + $_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']); $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { @@ -152,58 +154,58 @@ if ($_POST['grp_suffix']) $grp_suffix = $_POST['grp_suffix']; // new suffix sel elseif ($_SESSION['grp_suffix']) $grp_suffix = $_SESSION['grp_suffix']; // old suffix from session else $grp_suffix = $_SESSION["config"]->get_GroupSuffix(); // default suffix -// generate search filter for sort links -$searchFilter = ""; -for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) { - $searchFilter = $searchFilter . "&filter" . strtolower($attr_array[$k]) . "=". - $_POST["filter" . strtolower($attr_array[$k])]; - } -} +$refresh = true; +if ($_GET['norefresh']) $refresh = false; +if ($_POST['refresh']) $refresh = true; -if (! $_GET['norefresh']) { +if ($refresh) { // configure search filter $module_filter = get_ldap_filter("group"); // basic filter is provided by modules - $filter = "(&" . $module_filter; - for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) - $filter = $filter . "(" . strtolower($attr_array[$k]) . "=" . - $_POST["filter" . strtolower($attr_array[$k])] . ")"; - else - $_POST["filter" . strtolower($attr_array[$k])] = ""; - } - $filter = $filter . ")"; + $filter = "(&" . $module_filter . ")"; $attrs = $attr_array; $sr = @ldap_search($_SESSION["ldap"]->server(), $grp_suffix, $filter, $attrs); if (ldap_errno($_SESSION["ldap"]->server()) == 4) { StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem.")); } if ($sr) { - $grp_info = ldap_get_entries($_SESSION["ldap"]->server, $sr); + $info = ldap_get_entries($_SESSION["ldap"]->server, $sr); ldap_free_result($sr); - if ($grp_info["count"] == 0) StatusMessage("WARN", "", _("No Groups found!")); // delete first array entry which is "count" - unset($grp_info['count']); - // sort rows by sort column ($sort) - $grp_info = listSort($sort, $attr_array, $grp_info); + unset($info['count']); + // save results + $_SESSION[$scope . 'info'] = $info; } else { - $grp_info = array(); - $_SESSION['grp_info'] = array(); - StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No Groups found!")); + $info = array(); + $_SESSION[$scope . 'info'] = array(); + StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No groups found!")); } } + +$filter = listBuildFilter($_POST, $attr_array); +$info = listFilterAccounts($info, $filter); +if (sizeof($info) == 0) StatusMessage("WARN", "", _("No groups found!")); +// sort rows by sort column ($sort) +if ($info) $info = listSort($sort, $attr_array, $info); + +// build filter URL +$searchFilter = array(); +$filterAttributes = array_keys($filter); +for ($i = 0; $i < sizeof($filterAttributes); $i++) { + $searchFilter[] = "filter" . $filterAttributes[$i] . "=" . $filter[$filterAttributes[$i]]['original']; +} +if (sizeof($searchFilter) > 0) { + $searchFilter = "&" . implode("&", $searchFilter); +} else { - if (sizeof($grp_info) == 0) StatusMessage("WARN", "", _("No Groups found!")); - // sort rows by sort column ($sort) - if ($grp_info) $grp_info =listSort($sort, $attr_array, $grp_info); + $searchFilter = ""; } -echo ("
\n"); +echo ("\n"); // draw navigation bar if group accounts were found -if (sizeof($grp_info) > 0) { -listDrawNavigationBar(sizeof($grp_info), $max_page_entries, $page, $sort, $searchFilter, "group", _("%s group(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, $searchFilter, "group", _("%s group(s) found")); echo ("
"); } @@ -212,53 +214,53 @@ listPrintTableHeader("group", $searchFilter, $desc_array, $attr_array, $_POST, $ // calculate which rows to show $table_begin = ($page - 1) * $max_page_entries; -if (($page * $max_page_entries) > sizeof($grp_info)) $table_end = sizeof($grp_info); +if (($page * $max_page_entries) > sizeof($info)) $table_end = sizeof($info); else $table_end = ($page * $max_page_entries); -if (sizeof($grp_info) > 0) { +if (sizeof($info) > 0) { // print group list for ($i = $table_begin; $i < $table_end; $i++) { - echo(""); + echo(""); if ($_GET['selectall'] == "yes") { - echo " "; + echo " "; } else { - echo " "; + echo " "; } - echo (" " . _("Edit") . ""); + echo (" " . _("Edit") . ""); for ($k = 0; $k < sizeof($attr_array); $k++) { echo (""); // print all attribute entries seperated by "; " - if (sizeof($grp_info[$i][strtolower($attr_array[$k])]) > 0) { + if (sizeof($info[$i][strtolower($attr_array[$k])]) > 0) { // delete first array entry which is "count" - if (is_array($grp_info[$i][strtolower($attr_array[$k])])) unset($grp_info[$i][strtolower($attr_array[$k])]['count']); + if (is_array($info[$i][strtolower($attr_array[$k])])) unset($info[$i][strtolower($attr_array[$k])]['count']); // generate links for group members if (strtolower($attr_array[$k]) == "memberuid") { // sort array - sort($grp_info[$i][strtolower($attr_array[$k])]); + sort($info[$i][strtolower($attr_array[$k])]); // make a link for each member of the group $linklist = array(); - for ($d = 0; $d < sizeof($grp_info[$i][strtolower($attr_array[$k])]); $d++) { - $user = $grp_info[$i][strtolower($attr_array[$k])][$d]; // user name + for ($d = 0; $d < sizeof($info[$i][strtolower($attr_array[$k])]); $d++) { + $user = $info[$i][strtolower($attr_array[$k])][$d]; // user name $linklist[$d] = "" . $user . ""; } echo implode("; ", $linklist); } // print all other attributes else { - if (is_array($grp_info[$i][strtolower($attr_array[$k])])) { + if (is_array($info[$i][strtolower($attr_array[$k])])) { // delete "count" entry - unset($grp_info[$i][strtolower($attr_array[$k])]['count']); + unset($info[$i][strtolower($attr_array[$k])]['count']); // sort array - sort($grp_info[$i][strtolower($attr_array[$k])]); - echo implode("; ", $grp_info[$i][strtolower($attr_array[$k])]); + sort($info[$i][strtolower($attr_array[$k])]); + echo implode("; ", $info[$i][strtolower($attr_array[$k])]); } - else echo $grp_info[$i][strtolower($attr_array[$k])]; + else echo $info[$i][strtolower($attr_array[$k])]; } } echo (""); @@ -278,8 +280,8 @@ echo (""); echo ("
"); // draw navigation bar if group accounts were found -if (sizeof($grp_info) > 0) { -listDrawNavigationBar(sizeof($grp_info), $max_page_entries, $page, $sort, $searchFilter, "group", _("%s group(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, $searchFilter, "group", _("%s group(s) found")); echo ("
\n"); } @@ -304,7 +306,7 @@ if (sizeof($grp_units) > 1) { } echo ("\n"); -if (sizeof($grp_info) > 0) { +if (sizeof($info) > 0) { echo ("\n"); echo ("


\n"); echo "
PDF\n"; @@ -324,7 +326,6 @@ echo ("\n"); echo "\n"; // save variables to session -$_SESSION['grp_info'] = $grp_info; $_SESSION['grp_units'] = $grp_units; $_SESSION['grp_suffix'] = $grp_suffix; diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index e6f7c3fd..e121599b 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -49,13 +49,15 @@ session_save_path("../../sess"); setlanguage(); +$scope = 'host'; + // get sorting column when register_globals is off $sort = $_GET['sort']; // copy HTTP-GET variables to HTTP-POST $_POST = $_POST + $_GET; -$hst_info = $_SESSION['hst_info']; +$info = $_SESSION[$scope . 'info']; $hst_units = $_SESSION['hst_units']; // check if button was pressed and if we have to add/delete a host @@ -95,9 +97,9 @@ if ($_POST['new_host'] || $_POST['del_host'] || $_POST['pdf_host'] || $_POST['pd // PDF for all hosts elseif ($_POST['pdf_all']){ $list = array(); - for ($i = 0; $i < sizeof($_SESSION['hst_info']); $i++) { + for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) { $_SESSION["accountPDF-$i"] = new accountContainer("host", "accountPDF-$i"); - $_SESSION["accountPDF-$i"]->load_account($_SESSION['hst_info'][$i]['dn']); + $_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']); $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { @@ -152,58 +154,58 @@ if ($_POST['hst_suffix']) $hst_suffix = $_POST['hst_suffix']; // new suffix sel elseif ($_SESSION['hst_suffix']) $hst_suffix = $_SESSION['hst_suffix']; // old suffix from session else $hst_suffix = $_SESSION["config"]->get_HostSuffix(); // default suffix -// generate search filter for sort links -$searchFilter = ""; -for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) { - $searchFilter = $searchFilter . "&filter" . strtolower($attr_array[$k]) . "=". - $_POST["filter" . strtolower($attr_array[$k])]; - } -} +$refresh = true; +if ($_GET['norefresh']) $refresh = false; +if ($_POST['refresh']) $refresh = true; -if (! $_GET['norefresh']) { +if ($refresh) { // configure search filter $module_filter = get_ldap_filter("host"); // basic filter is provided by modules - $filter = "(&" . $module_filter; - for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) - $filter = $filter . "(" . strtolower($attr_array[$k]) . "=" . - $_POST["filter" . strtolower($attr_array[$k])] . ")"; - else - $_POST["filter" . strtolower($attr_array[$k])] = ""; - } - $filter = $filter . ")"; + $filter = "(&" . $module_filter . ")"; $attrs = $attr_array; $sr = @ldap_search($_SESSION["ldap"]->server(), $hst_suffix, $filter, $attrs); if (ldap_errno($_SESSION["ldap"]->server()) == 4) { StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem.")); } if ($sr) { - $hst_info = ldap_get_entries($_SESSION["ldap"]->server, $sr); + $info = ldap_get_entries($_SESSION["ldap"]->server, $sr); ldap_free_result($sr); - if ($hst_info["count"] == 0) StatusMessage("WARN", "", _("No Samba Hosts found!")); // delete first array entry which is "count" - unset($hst_info['count']); - // sort rows by sort column ($sort) - $hst_info = listSort($sort, $attr_array, $hst_info); + unset($info['count']); + // save results + $_SESSION[$scope . 'info'] = $info; } else { - $hst_info = array(); - $_SESSION['hst_info'] = array(); - StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No Samba Hosts found!")); + $info = array(); + $_SESSION[$scope . 'info'] = array(); + StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), _("No hosts found!")); } } + +$filter = listBuildFilter($_POST, $attr_array); +$info = listFilterAccounts($info, $filter); +if (sizeof($info) == 0) StatusMessage("WARN", "", _("No hosts found!")); +// sort rows by sort column ($sort) +if ($info) $info = listSort($sort, $attr_array, $info); + +// build filter URL +$searchFilter = array(); +$filterAttributes = array_keys($filter); +for ($i = 0; $i < sizeof($filterAttributes); $i++) { + $searchFilter[] = "filter" . $filterAttributes[$i] . "=" . $filter[$filterAttributes[$i]]['original']; +} +if (sizeof($searchFilter) > 0) { + $searchFilter = "&" . implode("&", $searchFilter); +} else { - if (sizeof($hst_info) == 0) StatusMessage("WARN", "", _("No Samba Hosts found!")); - // sort rows by sort column ($sort) - if ($hst_info) $hst_info = listSort($sort, $attr_array, $hst_info); + $searchFilter = ""; } -echo ("
\n"); +echo ("\n"); // draw navigation bar if host accounts were found -if (sizeof($hst_info) > 0) { -listDrawNavigationBar(sizeof($hst_info), $max_page_entries, $page, $sort, $searchFilter, "host", _("%s host(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, $searchFilter, "host", _("%s host(s) found")); echo ("
\n"); } @@ -212,37 +214,37 @@ listPrintTableHeader("host", $searchFilter, $desc_array, $attr_array, $_POST, $s // calculate which rows to show $table_begin = ($page - 1) * $max_page_entries; -if (($page * $max_page_entries) > sizeof($hst_info)) $table_end = sizeof($hst_info); +if (($page * $max_page_entries) > sizeof($info)) $table_end = sizeof($info); else $table_end = ($page * $max_page_entries); -if (sizeof($hst_info) > 0) { +if (sizeof($info) > 0) { // print host list for ($i = $table_begin; $i < $table_end; $i++) { - echo(""); + echo(""); if ($_GET['selectall'] == "yes") { - echo " "; + echo " "; } else { - echo " "; + echo " "; } - echo (" " . _("Edit") . ""); + echo (" " . _("Edit") . ""); for ($k = 0; $k < sizeof($attr_array); $k++) { echo (""); // print all attribute entries seperated by "; " - if (sizeof($hst_info[$i][strtolower($attr_array[$k])]) > 0) { + if (sizeof($info[$i][strtolower($attr_array[$k])]) > 0) { // delete "count" entry - unset($hst_info[$i][strtolower($attr_array[$k])]['count']); - if (is_array($hst_info[$i][strtolower($attr_array[$k])])) { + unset($info[$i][strtolower($attr_array[$k])]['count']); + if (is_array($info[$i][strtolower($attr_array[$k])])) { // sort array - sort($hst_info[$i][strtolower($attr_array[$k])]); - echo implode("; ", $hst_info[$i][strtolower($attr_array[$k])]); + sort($info[$i][strtolower($attr_array[$k])]); + echo implode("; ", $info[$i][strtolower($attr_array[$k])]); } - else echo $hst_info[$i][strtolower($attr_array[$k])]; + else echo $info[$i][strtolower($attr_array[$k])]; } echo (""); } @@ -262,8 +264,8 @@ echo (""); echo ("
"); // draw navigation bar if host accounts were found -if (sizeof($hst_info) > 0) { -listDrawNavigationBar(sizeof($hst_info), $max_page_entries, $page, $sort, $searchFilter, "host", _("%s host(s) found")); +if (sizeof($info) > 0) { +listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort, $searchFilter, "host", _("%s host(s) found")); echo ("
\n"); } @@ -289,7 +291,7 @@ echo ("

 

\n"); // add/delete/PDF buttons echo ("\n"); -if (sizeof($hst_info) > 0) { +if (sizeof($info) > 0) { echo ("\n"); echo ("


\n"); echo "
PDF\n"; @@ -309,7 +311,6 @@ echo ("\n"); echo "\n"; // save variables to session -$_SESSION['hst_info'] = $hst_info; $_SESSION['hst_units'] = $hst_units; $_SESSION['hst_suffix'] = $hst_suffix; diff --git a/lam/templates/lists/listusers.php b/lam/templates/lists/listusers.php index 4a86f6f0..6571ab21 100644 --- a/lam/templates/lists/listusers.php +++ b/lam/templates/lists/listusers.php @@ -51,6 +51,8 @@ session_save_path("../../sess"); setlanguage(); +$scope = 'user'; + // copy HTTP-GET variables to HTTP-POST $_POST = $_POST + $_GET; @@ -76,6 +78,7 @@ if ($trans_primary == "on" && !$_GET["norefresh"]) { } +$info = $_SESSION[$scope . 'info']; $usr_units = $_SESSION['usr_units']; // check if button was pressed and if we have to add/delete a user or create a PDF @@ -119,9 +122,9 @@ if ($_POST['new_user'] || $_POST['del_user'] || $_POST['pdf_user'] || $_POST['pd // PDF for all users elseif ($_POST['pdf_all']){ $list = array(); - for ($i = 0; $i < sizeof($_SESSION['userlist']); $i++) { + for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) { $_SESSION["accountPDF-$i"] = new accountContainer("user", "accountPDF-$i"); - $_SESSION["accountPDF-$i"]->load_account($_SESSION['usr_info'][$i]['dn']); + $_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']); $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { @@ -182,61 +185,59 @@ elseif ($_SESSION['usr_suffix']) $usr_suffix = $_SESSION['usr_suffix']; // old else $usr_suffix = $_SESSION["config"]->get_UserSuffix(); // default suffix -// generate search filter for sort links -$searchFilter = ""; -for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) { - $searchFilter = $searchFilter . "&filter" . - strtolower($attr_array[$k]) . "=". - $_POST["filter" . strtolower($attr_array[$k])]; - } -} - // configure search filter for LDAP $module_filter = get_ldap_filter("user"); // basic filter is provided by modules -$filter = "(&" . $module_filter; // users do not end with "$" -for ($k = 0; $k < sizeof($desc_array); $k++) { - if (eregi("^([0-9a-z_\\*\\+\\-])+$", $_POST["filter" . strtolower($attr_array[$k])])) - $filter = $filter . "(" . strtolower($attr_array[$k]) . "=" . - $_POST["filter" . strtolower($attr_array[$k])] . ")"; - else - $_POST["filter" . strtolower($attr_array[$k])] = ""; -} -$filter = $filter . ")"; +$filter = "(&" . $module_filter . ")"; -// read entries only from ldap server if not yet stored in session or if refresh -// button is pressed or if filter is applied -if ($_SESSION["userlist"] && $_GET["norefresh"]) { - $_SESSION["userlist"] = listSort($sort, $attr_array, $_SESSION["userlist"]); - $userinfo = $_SESSION["userlist"]; -} -else { +$refresh = true; +if ($_GET['norefresh']) $refresh = false; +if ($_POST['refresh']) $refresh = true; + +if ($refresh) { $attrs = $attr_array; $sr = @ldap_search($_SESSION["ldap"]->server(), $usr_suffix, $filter, $attrs); if (ldap_errno($_SESSION["ldap"]->server()) == 4) { StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem.")); } if ($sr) { - $userinfo = ldap_get_entries ($_SESSION["ldap"]->server, $sr); + $info = ldap_get_entries ($_SESSION["ldap"]->server, $sr); ldap_free_result ($sr); - if ($userinfo["count"] == 0) StatusMessage("WARN", "", _("No Users found!")); - // delete first array entry which is "count" - unset($userinfo['count']); - $userinfo = listSort($sort, $attr_array, $userinfo); - $_SESSION["userlist"] = $userinfo; - } + // delete first array entry which is "count" + unset($info['count']); + // save results + $_SESSION[$scope . 'info'] = $info; + } else { - $_SESSION['userlist'] = array(); - $userinfo = array(); + $_SESSION[$scope . 'info'] = array(); + $info = array(); StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), - _("No Users found!")); + _("No users found!")); } } -$user_count = sizeof ($_SESSION["userlist"]); +$filter = listBuildFilter($_POST, $attr_array); +$info = listFilterAccounts($info, $filter); +if (sizeof($info) == 0) StatusMessage("WARN", "", _("No users found!")); +// sort rows by sort column ($sort) +if ($info) $info = listSort($sort, $attr_array, $info); -echo ("
\n"); +// build filter URL +$searchFilter = array(); +$filterAttributes = array_keys($filter); +for ($i = 0; $i < sizeof($filterAttributes); $i++) { + $searchFilter[] = "filter" . $filterAttributes[$i] . "=" . $filter[$filterAttributes[$i]]['original']; +} +if (sizeof($searchFilter) > 0) { + $searchFilter = "&" . implode("&", $searchFilter); +} +else { + $searchFilter = ""; +} + +$user_count = sizeof($info); + +echo ("\n"); // display table only if users exist in LDAP if ($user_count != 0) { @@ -249,51 +250,55 @@ if ($user_count != 0) { // account table head listPrintTableHeader("user", $searchFilter . "&trans_primary=" . $trans_primary, $desc_array, $attr_array, $_POST, $sort); +// calculate which rows to show +$table_begin = ($page - 1) * $max_page_entries; +if (($page * $max_page_entries) > sizeof($info)) $table_end = sizeof($info); +else $table_end = ($page * $max_page_entries); + if ($user_count != 0) { // translate GIDs and resort array if selected if ($trans_primary == "on") { // translate GIDs - for ($i = 0; $i < sizeof($userinfo); $i++) { - if ($trans_primary_hash[$userinfo[$i]['gidnumber'][0]]) { - $userinfo[$i]['gidnumber'][0] = $trans_primary_hash[$userinfo[$i]['gidnumber'][0]]; + for ($i = 0; $i < sizeof($info); $i++) { + if ($trans_primary_hash[$info[$i]['gidnumber'][0]]) { + $info[$i]['gidnumber'][0] = $trans_primary_hash[$info[$i]['gidnumber'][0]]; } } // resort if needed if ($sort == "gidnumber") { - $userinfo = listSort($sort, $attr_array, $userinfo); + $info = listSort($sort, $attr_array, $info); } } // print user list - $userinfo = array_slice ($userinfo, ($page - 1) * $max_page_entries, $max_page_entries); - for ($i = 0; $i < sizeof ($userinfo); $i++) { // ignore last entry in array which is "count" - echo("\n"); + for ($i = $table_begin; $i < $table_end; $i++) { // ignore last entry in array which is "count" + echo("\n"); // checkboxes if selectall = "yes" if ($_GET['selectall'] == "yes") { - echo "\n\n\n"; + echo "\n\n\n"; } else { - echo "\n\n\n"; + echo "\n\n\n"; } - echo ("\n" . + echo ("\n" . _("Edit") . "\n\n"); for ($k = 0; $k < sizeof($attr_array); $k++) { echo ("\n"); // print attribute values - if (sizeof($userinfo[$i][strtolower($attr_array[$k])]) > 0) { - if (is_array($userinfo[$i][strtolower($attr_array[$k])])) { + if (sizeof($info[$i][strtolower($attr_array[$k])]) > 0) { + if (is_array($info[$i][strtolower($attr_array[$k])])) { // delete first array entry which is "count" - unset($userinfo[$i][strtolower($attr_array[$k])]['count']); + unset($info[$i][strtolower($attr_array[$k])]['count']); // sort array - sort($userinfo[$i][strtolower($attr_array[$k])]); + sort($info[$i][strtolower($attr_array[$k])]); // print all attribute entries seperated by "; " - echo implode("; ", $userinfo[$i][strtolower($attr_array[$k])]) . "\n"; + echo implode("; ", $info[$i][strtolower($attr_array[$k])]) . "\n"; } - else echo $userinfo[$i][strtolower($attr_array[$k])] . "\n"; + else echo $info[$i][strtolower($attr_array[$k])] . "\n"; } echo ("\n"); }