added functions to filter account lists
This commit is contained in:
parent
a48e6ec6e9
commit
f6d7db5f07
|
@ -29,6 +29,62 @@ $Id$
|
|||
* @author Roland Gruber
|
||||
*/
|
||||
|
||||
/**
|
||||
* Builds the regular expressions from the filter values.
|
||||
*
|
||||
* @param array $post HTTP Post values
|
||||
* @param array $attributes list of displayed attributes
|
||||
* @return array filter data array($attribute => array('regex' => $reg, 'original' => $orig))
|
||||
* $reg is the regular expression to use, $orig the user's unmodified input string
|
||||
*/
|
||||
function listBuildFilter($post, $attributes) {
|
||||
$filter = array();
|
||||
for ($i = 0; $i < sizeof($attributes); $i++) {
|
||||
if (eregi('^([0-9a-z_\\*\\$])+$', $_POST["filter" . strtolower($attributes[$i])])) {
|
||||
$filter[$attributes[$i]]['original'] = $_POST["filter" . strtolower($attributes[$i])];
|
||||
$filter[$attributes[$i]]['regex'] = $_POST["filter" . strtolower($attributes[$i])];
|
||||
// replace special characters
|
||||
$filter[$attributes[$i]]['regex'] = str_replace("*", "(.)*", $filter[$attributes[$i]]['regex']);
|
||||
$filter[$attributes[$i]]['regex'] = str_replace('$', '[$]', $filter[$attributes[$i]]['regex']);
|
||||
// add string begin and end
|
||||
$filter[$attributes[$i]]['regex'] = "^" . $filter[$attributes[$i]]['regex'] . "$";
|
||||
}
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all entries which do not fit to the filter.
|
||||
*
|
||||
* @param array $entries list of accounts
|
||||
* @param array $filter attribute filter
|
||||
* @return array filtered list of accounts
|
||||
*/
|
||||
function listFilterAccounts($entries, $filter) {
|
||||
$attributes = array_keys($filter);
|
||||
for ($r = 0; $r < sizeof($entries); $r++) {
|
||||
for ($a = 0; $a < sizeof($attributes); $a++) {
|
||||
// check if filter fits
|
||||
$found = false;
|
||||
for ($i = 0; $i < sizeof($entries[$r][$attributes[$a]]); $i++) {
|
||||
if (eregi($filter[$attributes[$a]]['regex'], $entries[$r][$attributes[$a]][$i])) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
// remove account and reindex array
|
||||
unset($entries[$r]);
|
||||
$entries = array_values($entries);
|
||||
$r--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sorts an account list by a given attribute
|
||||
|
@ -94,7 +150,7 @@ function listDrawNavigationBar($count, $max_page_entries, $page, $sort, $searchF
|
|||
echo("<tr>\n");
|
||||
echo("<td><input type=\"submit\" name=\"refresh\" value=\"" . _("Refresh") . "\"> ");
|
||||
if ($page != 1) {
|
||||
echo("<a href=\"list" . $scope . "s.php?page=" . ($page - 1) . "&sort=" . $sort . $searchFilter . "\"><=</a>\n");
|
||||
echo("<a href=\"list" . $scope . "s.php?norefresh=true&page=" . ($page - 1) . "&sort=" . $sort . $searchFilter . "\"><=</a>\n");
|
||||
}
|
||||
else {
|
||||
echo("<=");
|
||||
|
@ -102,7 +158,7 @@ function listDrawNavigationBar($count, $max_page_entries, $page, $sort, $searchF
|
|||
echo(" ");
|
||||
|
||||
if ($page < ($count / $max_page_entries)) {
|
||||
echo("<a href=\"list" . $scope . "s.php?page=" . ($page + 1) . "&sort=" . $sort . $searchFilter . "\">=></a>\n");
|
||||
echo("<a href=\"list" . $scope . "s.php?norefresh=true&page=" . ($page + 1) . "&sort=" . $sort . $searchFilter . "\">=></a>\n");
|
||||
}
|
||||
else {
|
||||
echo("=></td>");
|
||||
|
@ -119,7 +175,7 @@ function listDrawNavigationBar($count, $max_page_entries, $page, $sort, $searchF
|
|||
echo(" " . ($i + 1));
|
||||
}
|
||||
else {
|
||||
echo(" <a href=\"list" . $scope . "s.php?page=" . ($i + 1) . "&sort=" . $sort . "\">" . ($i + 1) . "</a>\n");
|
||||
echo(" <a href=\"list" . $scope . "s.php?norefresh=true&page=" . ($i + 1) . "&sort=" . $sort . "\">" . ($i + 1) . "</a>\n");
|
||||
}
|
||||
}
|
||||
echo("</td></tr></table>\n");
|
||||
|
|
Loading…
Reference in New Issue