changeset 146:a3344e4babc8 misc

Add advanced filtering.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2010 02:25:15 +0000
parents 7c9b72f6319a
children 9330b5ce7e1c
files materials/index.php
diffstat 1 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/materials/index.php	Tue Dec 21 01:40:58 2010 +0000
+++ b/materials/index.php	Tue Dec 21 02:25:15 2010 +0000
@@ -14,10 +14,7 @@
 
 if (isset($_GET["d"])) {
   $s = substr(strtolower($_GET["d"]), 0, 1);
-  if ($s == "d")
-    $sortDirection = 1;
-  else
-    $sortDirection = 0;
+  $sortDirection = ($s == "d") ? 1 : 0;
 } else
   $sortDirection = 0;
 
@@ -28,6 +25,12 @@
   $filterTable = array();
 
 
+if (isset($_GET["f"]) && is_array($_GET["f"]))
+  $colFilters = $_GET["f"];
+else
+  $colFilters = array();
+
+
 if (isset($_GET["o"]))
   $showOnly = intval($_GET["o"]);
 else
@@ -138,12 +141,21 @@
 <table class="matTable">
  <tr>
 <?
+function getFilterStr($filters)
+{
+  $str = "";
+  foreach ($filters as $fkey => $fval)
+    $str .= "&amp;f%5B".$fkey."%5D=".$fval;
+  return $str;
+}
+
 foreach ($transNameTable as $key => $value) {
   if (!isset($filterTable[$key])) {
     echo "  ";
     printTC("th", $key);
     echo "<a href=\"?s=".$key."&amp;d=".
-      $sortDirs[($key == $sortColumn) ? !$sortDirection : $sortDirection];
+      $sortDirs[($key == $sortColumn) ? !$sortDirection : $sortDirection].
+      getFilterStr($colFilters);
 
     if ($showOnlySet)
       echo "&amp;o=".$showOnly;
@@ -156,9 +168,19 @@
 }
 echo " </tr>\n";
 
+
 foreach ($matTable as $key => $value) {
 
-  $doShow = $showOnlySet ? ($value[14] == $showOnly) : TRUE;
+  if (count($colFilters) > 0) {
+    $doShow = TRUE;
+    foreach ($colFilters as $fkey => $fval) {
+      if ($value[$fkey] != $fval) {
+        $doShow = FALSE;
+        break;
+      }
+    }
+  } else
+    $doShow = $showOnlySet ? ($value[14] == $showOnly) : TRUE;
   
   if ($doShow) {
     $col = 0;
@@ -180,7 +202,12 @@
             echo ", ".htmlentities($transTable[$kkey][$lode]);
         } else {
           // A simple entry, just print it out
-          echo htmlentities($transTable[$kkey][$kvalue]);
+          $tmpFilters = $colFilters;
+          $tmpFilters[$kkey] = $kvalue;
+          echo "<a href=\"?s=".$sortColumn."&amp;d=".
+            $sortDirs[$sortDirection].
+            getFilterStr($tmpFilters).
+            "\">".htmlentities($transTable[$kkey][$kvalue])."</a>";
         }
         echo "</td>";
       }