From 8d9321225140a3db0b72796d4d0236d6cacfeb8a Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Sat, 17 Sep 2011 19:36:41 +0200 Subject: Started working on a study program. --- lib/functions.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'lib/functions.php') diff --git a/lib/functions.php b/lib/functions.php index 549ed3b..6190818 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -50,3 +50,64 @@ function assert_error($a, $e, $t = "") { die(); } } + + +// **** DISPLAY FILTERS ******* + +function get_filter($name) { + global $filters, $fdefaults; + if (!isset($filters[$name])) return ""; + $v = (isset($_GET[$name]) ? $_GET[$name] : ""); + if (!isset($filters[$name][$v])) return $fdefaults[$name]; + return $v; +} + +function filter_html_entry($name, $entry) { + global $filters, $filters_defaults, $url; + if (!isset($filters[$name])) return ""; + if (!isset($filters[$name][$entry])) return ""; + $rurl = array("p=".$url, $name . "=" . $entry); + foreach ($filters as $filter => $n) { + if ($filter != $name) { + $rurl[] = ($filter . "=" . get_filter($filter)); + } + } + return '' . $filters[$name][$entry] . ''; +} + +function filter_html($name) { + global $filters, $filters_defaults; + if (!isset($filters[$name])) return ""; + $r = array(); + foreach ($filters[$name] as $v => $t) { + if (get_filter($name) == $v) { + $r[] = "" . $t . ""; + } else { + $r[] = filter_html_entry($name, $v); + } + } + return implode(", ", $r); +} + +function filters_html() { + global $filters; + $r = array(); + foreach ($filters as $k => $filter) { + $r[$k] = filter_html($k); + } + return $r; +} + +function filters_html_full() { + global $filters_names; + $r = array(); + foreach (filters_html() as $f => $h) { + $r[] = $f . " (" . $h . ")"; + } + return implode(", ", $r); +} + +$ord_ways = array ( + "ASC" => "ascending", + "DESC" => "descending" +); -- cgit v1.2.3