restore filter when coming back from user edit

This commit is contained in:
Roland Gruber 2013-02-19 17:36:46 +00:00
parent ec40c54cb9
commit edeac37af3
3 changed files with 54 additions and 29 deletions

View File

@ -76,11 +76,8 @@ class lamList {
/** LDAP entries */ /** LDAP entries */
protected $entries; protected $entries;
/** filter string to include in URL */ /** list of filters (attribute name => filter input) */
protected $filterText; protected $filters = array();
/** LDAP filter part which was entered by user via filter boxes */
protected $filterPart = '';
/** list of possible LDAP suffixes(organizational units) */ /** list of possible LDAP suffixes(organizational units) */
protected $possibleSuffixes; protected $possibleSuffixes;
@ -206,9 +203,11 @@ class lamList {
* Builds the regular expressions from the filter values. * Builds the regular expressions from the filter values.
*/ */
protected function listBuildFilter() { protected function listBuildFilter() {
if (isset($_GET['accountEditBack'])) {
return;
}
$filter = array(); $filter = array();
$filterParam = ""; $this->filters = array();
$LDAPFilterPart = "";
if (!isset($_POST['clear_filter'])) { if (!isset($_POST['clear_filter'])) {
// build filter array // build filter array
for ($i = 0; $i < sizeof($this->attrArray); $i++) { for ($i = 0; $i < sizeof($this->attrArray); $i++) {
@ -221,8 +220,7 @@ class lamList {
} }
if (isset($foundFilter) && ($foundFilter != '')) { if (isset($foundFilter) && ($foundFilter != '')) {
if (preg_match('/^([\p{L}\p{N} _\\*\\$\\.@-])+$/iu', $foundFilter)) { // \p{L} matches any Unicode letter if (preg_match('/^([\p{L}\p{N} _\\*\\$\\.@-])+$/iu', $foundFilter)) { // \p{L} matches any Unicode letter
$filterParam .= "&amp;filter" . $this->attrArray[$i] . '=' . $foundFilter; $this->filters[strtolower($this->attrArray[$i])] = $foundFilter;
$LDAPFilterPart .= '(' . $this->attrArray[$i] . '=' . $foundFilter . ')';
} }
else { else {
StatusMessage('ERROR', _('Please enter a valid filter. Only letters, numbers and " _*$.@-" are allowed.'), htmlspecialchars($foundFilter)); StatusMessage('ERROR', _('Please enter a valid filter. Only letters, numbers and " _*$.@-" are allowed.'), htmlspecialchars($foundFilter));
@ -230,8 +228,6 @@ class lamList {
} }
} }
} }
$this->filterText = $filterParam;
$this->filterPart = $LDAPFilterPart;
} }
/** /**
@ -273,6 +269,7 @@ class lamList {
* @param integer $count number of account entries * @param integer $count number of account entries
*/ */
protected function listDrawNavigationBar($count) { protected function listDrawNavigationBar($count) {
$filter = $this->getFilterAsTextForURL();
echo("<table width=\"100%\" border=\"0\">\n"); echo("<table width=\"100%\" border=\"0\">\n");
echo("<tr>\n"); echo("<tr>\n");
echo("<td align=\"left\">"); echo("<td align=\"left\">");
@ -283,12 +280,12 @@ class lamList {
echo("<td class=\"activepage\" align=\"right\">"); echo("<td class=\"activepage\" align=\"right\">");
if ($this->page != 1) { if ($this->page != 1) {
echo("<a title=\"" . _('Jump to first page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=1" . echo("<a title=\"" . _('Jump to first page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=1" .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $this->filterText . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-first.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-first.png\"></a>\n");
} }
if ($this->page > 10) { if ($this->page > 10) {
echo("<a title=\"" . _('Jump 10 pages backward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page - 10) . echo("<a title=\"" . _('Jump 10 pages backward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page - 10) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $this->filterText . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-previous.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-previous.png\"></a>\n");
} }
for ($i = $this->page - 6; $i < ($this->page + 5); $i++) { for ($i = $this->page - 6; $i < ($this->page + 5); $i++) {
@ -303,28 +300,42 @@ class lamList {
} }
else { else {
echo "&nbsp;<a href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($i + 1) . echo "&nbsp;<a href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($i + 1) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $this->filterText . "\">" . ($i + 1) . "</a>\n"; "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . ($i + 1) . "</a>\n";
} }
} }
if ($this->page < (($count / $this->maxPageEntries) - 10)) { if ($this->page < (($count / $this->maxPageEntries) - 10)) {
echo("<a title=\"" . _('Jump 10 pages forward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page + 10) . echo("<a title=\"" . _('Jump 10 pages forward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page + 10) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $this->filterText . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-next.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-next.png\"></a>\n");
} }
if ($this->page < ($count / $this->maxPageEntries)) { if ($this->page < ($count / $this->maxPageEntries)) {
echo("<a title=\"" . _('Jump to last page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ceil(($count / $this->maxPageEntries)) . echo("<a title=\"" . _('Jump to last page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ceil(($count / $this->maxPageEntries)) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $this->filterText . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-last.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-last.png\"></a>\n");
} }
echo "</td>"; echo "</td>";
} }
echo "</tr></table>\n"; echo "</tr></table>\n";
} }
/**
* Returns the filter as text to be used as URL parameter.
*
* @return String filter text
*/
protected function getFilterAsTextForURL() {
$text = '';
foreach ($this->filters as $attr => $filter) {
$text .= "&amp;filter" . strtolower($attr) . '=' . $filter;
}
return $text;
}
/** /**
* Prints the attribute and filter row at the account table head * Prints the attribute and filter row at the account table head
*/ */
protected function listPrintTableHeader() { protected function listPrintTableHeader() {
$filter = $this->getFilterAsTextForURL();
// print table header // print table header
echo "<table id=\"accountTable\" frame=\"box\" rules=\"none\" class=\"" . $this->type . "-border collapse accountlist ui-corner-all\" width=\"100%\"><thead>\n"; echo "<table id=\"accountTable\" frame=\"box\" rules=\"none\" class=\"" . $this->type . "-border collapse accountlist ui-corner-all\" width=\"100%\"><thead>\n";
echo "<tr class=\"" . $this->type . "-dark\">\n<th width=22 height=34></th>\n<th></th>\n"; echo "<tr class=\"" . $this->type . "-dark\">\n<th width=22 height=34></th>\n<th></th>\n";
@ -336,11 +347,11 @@ class lamList {
$sortImage = "sort_desc.png"; $sortImage = "sort_desc.png";
} }
echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;". echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;".
"sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] .
"&nbsp;<img height=16 width=16 style=\"vertical-align: middle;\" src=\"../../graphics/$sortImage\" alt=\"sort direction\"></a></th>\n"; "&nbsp;<img height=16 width=16 style=\"vertical-align: middle;\" src=\"../../graphics/$sortImage\" alt=\"sort direction\"></a></th>\n";
} }
else echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;". else echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;".
"sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "</a></th>\n"; "sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "</a></th>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
@ -354,7 +365,7 @@ class lamList {
$filterButton = new htmlButton('apply_filter', 'filter.png', true); $filterButton = new htmlButton('apply_filter', 'filter.png', true);
$filterButton->setTitle(_("Filter")); $filterButton->setTitle(_("Filter"));
$filterGroup->addElement($filterButton); $filterGroup->addElement($filterButton);
if (isset($this->filterPart) && ($this->filterPart != '')) { if (sizeof($this->filters) > 0) {
$filterGroup->addElement(new htmlSpacer('1px', null)); $filterGroup->addElement(new htmlSpacer('1px', null));
$clearFilterButton = new htmlButton('clear_filter', 'clearFilter.png', true); $clearFilterButton = new htmlButton('clear_filter', 'clearFilter.png', true);
$clearFilterButton->setTitle(_('Clear filter')); $clearFilterButton->setTitle(_('Clear filter'));
@ -368,11 +379,8 @@ class lamList {
if ($this->canBeFiltered($this->attrArray[$k])) { if ($this->canBeFiltered($this->attrArray[$k])) {
$value = ""; $value = "";
if (!isset($_POST['clear_filter'])) { if (!isset($_POST['clear_filter'])) {
if (isset($_GET["filter" . strtolower($this->attrArray[$k])])) { if (isset($this->filters[strtolower($this->attrArray[$k])])) {
$value = $_GET["filter" . strtolower($this->attrArray[$k])]; $value = $this->filters[strtolower($this->attrArray[$k])];
}
if (isset($_POST["filter" . strtolower($this->attrArray[$k])])) {
$value = $_POST["filter" . strtolower($this->attrArray[$k])];
} }
} }
$filterInput = new htmlInputField('filter' . strtolower($this->attrArray[$k]), $value); $filterInput = new htmlInputField('filter' . strtolower($this->attrArray[$k]), $value);
@ -836,6 +844,10 @@ class lamList {
* Sets some internal parameters. * Sets some internal parameters.
*/ */
protected function listGetParams() { protected function listGetParams() {
if (isset($_GET['accountEditBack'])) {
$this->refresh = true;
return;
}
// check if only PDF should be shown // check if only PDF should be shown
if (isset($_GET['printPDF'])) { if (isset($_GET['printPDF'])) {
$this->showPDFPage(null); $this->showPDFPage(null);
@ -888,7 +900,7 @@ class lamList {
} }
// configure search filter // configure search filter
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules $module_filter = get_ldap_filter($this->type); // basic filter is provided by modules
$filter = "(&" . $module_filter . $this->filterPart . ")"; $filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
$attrs = $this->attrArray; $attrs = $this->attrArray;
// remove virtual attributes from list // remove virtual attributes from list
for ($i = 0; $i < sizeof($attrs); $i++) { for ($i = 0; $i < sizeof($attrs); $i++) {
@ -914,6 +926,19 @@ class lamList {
$this->possibleSuffixes = $typeObj->getSuffixList(); $this->possibleSuffixes = $typeObj->getSuffixList();
} }
/**
* Builds the LDAP filter based on the filter entries in the GUI.
*
* @return String LDAP filter
*/
protected function buildLDAPAttributeFilter() {
$text = '';
foreach ($this->filters as $attr => $filter) {
$text .= '(' . $attr . '=' . $filter . ')';
}
return $text;
}
/** /**
* Forces a refresh of the LDAP data. * Forces a refresh of the LDAP data.
* Function must be called before $this->refresh option is checked to load new LDAP data (e.g. in listGetParams). * Function must be called before $this->refresh option is checked to load new LDAP data (e.g. in listGetParams).

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2012 Roland Gruber Copyright (C) 2003 - 2013 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -826,7 +826,7 @@ class accountContainer {
if (isset($_POST['accountContainerBackToList'])) { if (isset($_POST['accountContainerBackToList'])) {
// Return to account list // Return to account list
unset($_SESSION[$this->base]); unset($_SESSION[$this->base]);
metaRefresh("../lists/list.php?type=" . $this->type); metaRefresh("../lists/list.php?type=" . $this->type . '&amp;accountEditBack=true');
exit; exit;
} }
// create PDF file // create PDF file

View File

@ -5,7 +5,7 @@
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2009 - 2012 Pozdnyak Pavel Copyright (C) 2009 - 2012 Pozdnyak Pavel
2010 - 2012 Roland Gruber 2010 - 2013 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -168,7 +168,7 @@ class lamAsteriskExtList extends lamList {
parent::listRefreshData(); parent::listRefreshData();
// configure search filter // configure search filter
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules $module_filter = get_ldap_filter($this->type); // basic filter is provided by modules
$filter = "(&" . $module_filter . $this->filterPart . ")"; $filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
$attrs = $this->attrArray; $attrs = $this->attrArray;
$attrs[] = "astpriority"; $attrs[] = "astpriority";
$entries = searchLDAP($this->suffix, $filter, $attrs); $entries = searchLDAP($this->suffix, $filter, $attrs);