Mercurial > hg > batmud > misc
changeset 276:2e2ea2bfd843 misc
Many improvements to the material browser.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Mar 2015 10:28:50 +0200 |
parents | 6c9bcf5ffc72 |
children | 40cfb180d576 |
files | materials/index.php |
diffstat | 1 files changed, 61 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/index.php Sun Mar 08 09:08:23 2015 +0200 +++ b/materials/index.php Sun Mar 08 10:28:50 2015 +0200 @@ -18,11 +18,12 @@ $sortDirection = substr(strtolower(stGetRequestItem("d", "", TRUE)), 0, 1) == "d"; // Material column hiding +$hideColumns = array(); if (isset($_GET["h"]) && is_array($_GET["h"])) - $hideColumns = array_flip($_GET["h"]); -else - $hideColumns = array(); - +{ + foreach ($_GET["h"] as $vval) + $hideColumns[$vval] = 1; +} // Column filters if (isset($_GET["f"]) && is_array($_GET["f"])) @@ -30,6 +31,14 @@ else $attrFilters = array(); +// Material filters +if (isset($_GET["m"]) && is_array($_GET["m"])) + $matFilters = $_GET["m"]; +else + $matFilters = array(); + +$doMatFilter = intval(stGetRequestItem("mf", 0, TRUE)); + function stGetTC($a, $column) { @@ -38,7 +47,7 @@ } -function stGetURLStr($cfilters, $col, $dir) +function stGetURLStr($cfilters, $col, $dir, $mfilters) { global $sortDirs, $hideColumns; @@ -47,9 +56,12 @@ foreach ($cfilters as $fkey => $fval) $str .= "&f%5B".$fkey."%5D=".$fval; - foreach ($hideColumns as $fkey => $fvalue) + foreach ($hideColumns as $fkey => $fval) $str .= "&h%5B%5D=".$fkey; + foreach ($mfilters as $fkey => $fval) + $str .= "&m%5B".$fkey."%5D=".$fval; + return $str; } @@ -78,7 +90,8 @@ krsort($matTable, SORT_STRING); else ksort($matTable, SORT_STRING); -} else +} +else uasort($matTable, "stSortMatFunc"); @@ -87,6 +100,18 @@ ?> <h1><? echo $pageTitle; ?></h1> <form action="<? echo $pageIndex; ?>" method="get"> +<? +echo + stGetFormHiddenInput("s", $sortColumn)."\n". + stGetFormHiddenInput("d", $sortDirs[$sortDirection]). + stGetFormHiddenInput("mf", $doMatFilter)."\n"; + +foreach ($attrFilters as $fkey => $fval) + echo stGetFormHiddenInput("f[".$fkey."]", $fval)."\n"; + +foreach ($matFilters as $fkey => $fval) + echo stGetFormHiddenInput("m[".$fkey."]", $fval)."\n"; +?> <table class="optionsTable"> <tr> <th>Hide columns</th> @@ -155,11 +180,19 @@ { $filters = array(); foreach ($attrFilters as $fkey => $fval) - { + if ($fkey >= 0) $filters[] = "<b>".strtolower($transNameTable[$fkey + 1])."</b>=".strtolower($transTable[$fkey][$fval]); - } + echo "<p>Filtering: ".implode(", ", $filters)."</p>\n"; } + +if (count($matFilters) > 0) +{ + echo + "<p>Material filter: ".implode(", ", array_keys($matFilters))." ". + "<a href=\"?".stGetURLStr($attrFilters, $sortColumn, $sortDirection, $matFilters). + "&mf=".($doMatFilter ? "0" : "1")."\">[".($doMatFilter ? "Deactivate" : "Activate")."]</a></p>\n"; +} ?> <div class="matTable"> <table class="matTable"> @@ -167,12 +200,14 @@ <? foreach ($transNameTable as $key => $value) { - if (!isset($hideColumns[$key])) + if ($key == 0 || !isset($hideColumns[$key])) { echo " ".stGetTC("th", $key). "<a href=\"?". - stGetURLStr($attrFilters, $key, ($key == $sortColumn) ? !$sortDirection : $sortDirection). + stGetURLStr($attrFilters, $key, + ($key == $sortColumn) ? !$sortDirection : $sortDirection, + $matFilters). "\">".chentities($value)."</a></th>\n"; } } @@ -187,14 +222,25 @@ $doShow = FALSE; break; } - + + if ($doMatFilter && !isset($matFilters[$key])) + $doShow = FALSE; + if ($doShow) { $col = 0; + + // Material filter + $tmpFilters = $matFilters; + if (isset($tmpFilters[$key])) + unset($tmpFilters[$key]); + else + $tmpFilters[$key] = 1; + echo " <tr>".stGetTC("td", $col++). - "<a href=\"/mat/".urlencode($key)."\">".chentities($key)."</a>". -// " <a href=\"?".stGetURLStr($attrFilters, $sortColumn, $sortDirection)."\">•</a>". + "<a href=\"/mat/".urlencode($key)."\">".chentities($key)."</a> ". + "<a href=\"?".stGetURLStr($attrFilters, $sortColumn, $sortDirection, $tmpFilters)."\">•</a>". "</td>"; foreach ($value as $kkey => $kvalue) @@ -223,7 +269,7 @@ $tmpFilters[$kkey] = $kvalue; echo "<a href=\"?". - stGetURLStr($tmpFilters, $sortColumn, $sortDirection). + stGetURLStr($tmpFilters, $sortColumn, $sortDirection, $matFilters). "\">".chentities($transTable[$kkey][$kvalue])."</a>"; } echo "</td>";