From ba8231dc09d8aa603235092cb61941444bbe4632 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 23 Sep 2006 11:19:36 +0000 Subject: [PATCH] fixed list filtering --- lam/lib/lists.inc | 96 ++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 27a629a8..a34b5101 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -42,46 +42,46 @@ include_once("pdf.inc"); * * @package lists * @author Roland Gruber - * + * */ class lamList { - + /** Account type */ var $type; - + /** current page number */ var $page = 1; - + /** list of LDAP attributes */ var $attrArray = array(); - + /** list of attribute descriptions */ var $descArray = array(); - + /** maximum count of entries per page */ var $maxPageEntries = 10; - + /** sort column name */ var $sortColumn; - + /** LDAP suffix */ var $suffix; - + /** refresh page switch */ var $refresh = true; - + /** LDAP entries */ var $entries; - + /** filter string to include in URL */ var $filterText; - + /** list of possible LDAP suffixes(organizational units) */ var $possibleSuffixes; - + /** list of account specific labels */ var $labels; - + /** * Constructor * @@ -98,7 +98,7 @@ class lamList { 'createPDF' => _("Create PDF for selected object(s)"), 'createPDFAll' => _("Create PDF for all objects")); } - + /** * Prints the HTML code to display the list view. */ @@ -159,9 +159,16 @@ class lamList { $filter = array(); // build filter array for ($i = 0; $i < sizeof($this->attrArray); $i++) { - if (isset($_POST["filter" . strtolower($this->attrArray[$i])]) && eregi('^([0-9a-z _\\*\\$-])+$', $_POST["filter" . strtolower($this->attrArray[$i])])) { - $filter[$this->attrArray[$i]]['original'] = $_POST["filter" . strtolower($this->attrArray[$i])]; - $filter[$this->attrArray[$i]]['regex'] = $_POST["filter" . strtolower($this->attrArray[$i])]; + $foundFilter = null; + if (isset($_GET["filter" . strtolower($this->attrArray[$i])])) { + $foundFilter = $_GET["filter" . strtolower($this->attrArray[$i])]; + } + if (isset($_POST["filter" . strtolower($this->attrArray[$i])])) { + $foundFilter = $_POST["filter" . strtolower($this->attrArray[$i])]; + } + if (isset($foundFilter) && eregi('^([0-9a-z _\\*\\$-])+$', $foundFilter)) { + $filter[$this->attrArray[$i]]['original'] = $foundFilter; + $filter[$this->attrArray[$i]]['regex'] = $foundFilter; // replace special characters $filter[$this->attrArray[$i]]['regex'] = str_replace("*", "(.)*", $filter[$this->attrArray[$i]]['regex']); $filter[$this->attrArray[$i]]['regex'] = str_replace('$', '[$]', $filter[$this->attrArray[$i]]['regex']); @@ -184,8 +191,8 @@ class lamList { $this->filterText = $searchFilter; return $filter; } - - + + /** * Removes all entries which do not fit to the filter. * @@ -217,8 +224,8 @@ class lamList { if (sizeof($entries) == 0) StatusMessage("WARN", $this->labels['error_noneFound']); return $entries; } - - + + /** * Sorts an account list by a given attribute * @@ -232,8 +239,8 @@ class lamList { usort($info, array($this, "cmp_array")); return $info; } - - + + /** * Compare function used for usort-method * @@ -265,7 +272,7 @@ class lamList { * @param integer $count number of account entries */ function listDrawNavigationBar($count) { - + echo("type . "nav\" width=\"100%\" border=\"0\">\n"); echo("\n"); echo(""); } - + echo(""); - + echo("
  "); @@ -276,19 +283,19 @@ class lamList { echo("<="); } echo(" "); - + if ($this->page < ($count / $this->maxPageEntries)) { echo("type . "&norefresh=true&page=" . ($this->page + 1) . "&sort=" . $this->sortColumn . $this->filterText . "\">=>\n"); } else { echo("=>type . "nav-text\">"); echo" "; printf($this->labels['nav'], $count); echo("type . "nav-activepage\" align=\"right\">"); for ($i = 0; $i < ($count / $this->maxPageEntries); $i++) { if ($i == $this->page - 1) { @@ -300,7 +307,7 @@ class lamList { } echo("
\n"); } - + /** * Prints the attribute and filter row at the account table head */ @@ -318,7 +325,7 @@ class lamList { "sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] . "\n"; } echo "\n"; - + // print filter row echo "type . "list\">\n"; echo ""; @@ -333,6 +340,9 @@ class lamList { // print input boxes for filters for ($k = 0; $k < sizeof ($this->descArray); $k++) { $value = ""; + if (isset($_GET["filter" . strtolower($this->attrArray[$k])])) { + $value = " value=\"" . $_GET["filter" . strtolower($this->attrArray[$k])] . "\""; + } if (isset($_POST["filter" . strtolower($this->attrArray[$k])])) { $value = " value=\"" . $_POST["filter" . strtolower($this->attrArray[$k])] . "\""; } @@ -345,7 +355,7 @@ class lamList { /** * Prints the entry list - * + * * @param array $info entries */ function listPrintTableBody($info) { @@ -390,15 +400,15 @@ class lamList { $colspan = sizeof($this->attrArray) + 1; echo "type . "list\">\n"; echo "\"select\n"; - echo " type . "&norefresh=y&page=" . $this->page . + echo " type . "&norefresh=y&page=" . $this->page . "&sort=" . $this->sortColumn . $this->filterText . "&selectall=yes\">" . "" . _("Select all") . "\n"; echo "\n"; echo (""); - + echo ("
"); } - + /** * Manages all POST actions (e.g. button pressed) for the account lists. */ @@ -465,7 +475,7 @@ class lamList { } } } - + /** * Prints a combobox with possible sub-DNs. */ @@ -485,7 +495,7 @@ class lamList { echo ("

\n"); } } - + /** * Prints the create, delete and PDF buttons. * @@ -510,7 +520,7 @@ class lamList { echo ""; } } - + /** * Prints the HTML head. */ @@ -522,7 +532,7 @@ class lamList { echo "\n"; $this->listPrintJavaScript(); } - + /** * Prints JavaScript code needed for mouse-over effects. */ @@ -534,13 +544,13 @@ class lamList { echo "cbox = document.getElementsByName(box)[0];\n"; echo "if (cbox.checked == false) list.setAttribute('class', scope + 'list-over', 0);\n"; echo "}"; - + // mouseOut function echo "function list_out(list, box, scope) {\n"; echo "cbox = document.getElementsByName(box)[0];\n"; echo "if (cbox.checked == false) list.setAttribute('class', scope + 'list', 0);\n"; echo "}\n"; - + // onClick function echo "function list_click(list, box, scope) {\n"; echo "cbox = document.getElementsByName(box)[0];\n"; @@ -556,7 +566,7 @@ class lamList { echo "//-->\n"; echo "\n"; } - + /** * Returns an hash array containing with all attributes to be shown and their descriptions. * Format: array(attribute => description) @@ -593,7 +603,7 @@ class lamList { } return $ret; } - + /** * Sets some internal parameters. */ @@ -621,7 +631,7 @@ class lamList { if (isset($_GET['norefresh'])) $this->refresh = false; if (isset($_POST['refresh'])) $this->refresh = true; } - + /** * Rereads the entries from LDAP. */