changeset 147:9330b5ce7e1c misc

Various improvements.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2010 02:45:23 +0000
parents a3344e4babc8
children 6480620d2e4a
files materials/index.php
diffstat 1 files changed, 19 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/materials/index.php	Tue Dec 21 02:25:15 2010 +0000
+++ b/materials/index.php	Tue Dec 21 02:45:23 2010 +0000
@@ -31,12 +31,6 @@
   $colFilters = array();
 
 
-if (isset($_GET["o"]))
-  $showOnly = intval($_GET["o"]);
-else
-  $showOnly = -1;
-
-
 function sortMatFunc($a, $b)
 {
   global $sortDirection, $sortColumn;
@@ -90,7 +84,8 @@
     <li><b>Raw material data is also available in <a href="materials.csv">CSV format</a>, <a href="materials_short.txt">short tabular format</a> and <a href="materials_long.txt">long format</a></b>.</li>
     <li>You can sort by any column by clicking on the column name. Clicking again will change
     sorting direction (ascending/descending).</li>
-    <li>Filtering to show only certain type of materials is possible.</li>
+    <li>Filtering to show only certain type of materials or materials with certain feature(s) is possible,
+      for example <a href="index.php?s=0&amp;d=asc&amp;f[1]=5&amp;f[2]=3">show only 'incr. sturdy' AND 'highly magical'</a> materials.</li>
     <li>Columns can be disabled from the filtering list (shift or ctrl with mouse click to select several)</li>
    </ul>
   </td>
@@ -110,22 +105,19 @@
    </select>
   </td>
   <td>
-   <select name="o">
+   <select name="f[14]">
 <?
+$typeFilter = isset($colFilters[14]) ? $colFilters[14] : -1;
 $typeTable = $transTable[14];
 $typeTable[-1] = "EVERYTHING";
-$showOnlySet = FALSE;
 ksort($typeTable);
 foreach ($typeTable as $key => $value) {
   echo "    <option value=\"$key\"";
-  if ($showOnly == $key) {
+  if ($typeFilter == $key) {
     echo " selected=\"selected\"";
-    $showOnlySet = TRUE;
   }
   echo ">".htmlentities($value)."</option>\n";
 }
-if ($showOnly < 0)
-  $showOnlySet = FALSE;
 
 ?>
    </select>
@@ -143,9 +135,15 @@
 <?
 function getFilterStr($filters)
 {
+  global $filterTable;
+
   $str = "";
   foreach ($filters as $fkey => $fval)
     $str .= "&amp;f%5B".$fkey."%5D=".$fval;
+
+  foreach ($filterTable as $fkey => $fvalue)
+    $str .= "&amp;h%5B%5D=".$fkey;
+
   return $str;
 }
 
@@ -155,32 +153,21 @@
     printTC("th", $key);
     echo "<a href=\"?s=".$key."&amp;d=".
       $sortDirs[($key == $sortColumn) ? !$sortDirection : $sortDirection].
-      getFilterStr($colFilters);
-
-    if ($showOnlySet)
-      echo "&amp;o=".$showOnly;
-  
-    foreach ($filterTable as $filKey => $filValue)
-      echo "&amp;h%5B%5D=".$filKey;
-
-    echo "\">".htmlentities($value)."</a></th>\n";
+      getFilterStr($colFilters).
+      "\">".htmlentities($value)."</a></th>\n";
   }
 }
 echo " </tr>\n";
 
-
 foreach ($matTable as $key => $value) {
 
-  if (count($colFilters) > 0) {
-    $doShow = TRUE;
-    foreach ($colFilters as $fkey => $fval) {
-      if ($value[$fkey] != $fval) {
-        $doShow = FALSE;
-        break;
-      }
+  $doShow = TRUE;
+  foreach ($colFilters as $fkey => $fval) {
+    if ($fval >= 0 && $value[$fkey] != $fval) {
+      $doShow = FALSE;
+      break;
     }
-  } else
-    $doShow = $showOnlySet ? ($value[14] == $showOnly) : TRUE;
+  }
   
   if ($doShow) {
     $col = 0;