Mercurial > hg > batmud > misc
changeset 207:ccfd98ff8be2 misc
Sync changes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Apr 2011 09:41:38 +0300 |
parents | 13bbc57c2afe |
children | 6bee11440024 |
files | materials/alloy.php materials/index.php |
diffstat | 2 files changed, 60 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/alloy.php Tue Apr 19 14:46:27 2011 +0300 +++ b/materials/alloy.php Fri Apr 22 09:41:38 2011 +0300 @@ -43,6 +43,7 @@ printPageHeader($pageTitle, " + <meta name=\"robots\" content=\"nofollow\" /> <style type=\"text/css\"> .hits20 a { color: black; } .hits20 { background: #0c0; color: black; }
--- a/materials/index.php Tue Apr 19 14:46:27 2011 +0300 +++ b/materials/index.php Fri Apr 22 09:41:38 2011 +0300 @@ -3,15 +3,16 @@ $pageIndex = "index.php"; require "mcommon.inc.php"; require "materials.inc.php"; - $sortDirs = array("asc", "desc"); +// Sorting column if (isset($_GET["s"])) { $sortColumn = intval($_GET["s"]); } else $sortColumn = 0; +// Sorting direction if (isset($_GET["d"])) { $s = substr(strtolower($_GET["d"]), 0, 1); $sortDirection = ($s == "d") ? 1 : 0; @@ -19,16 +20,44 @@ $sortDirection = 0; +// Material column hiding if (isset($_GET["h"]) && is_array($_GET["h"])) - $filterTable = array_flip($_GET["h"]); + $hideColumns = array_flip($_GET["h"]); else - $filterTable = array(); + $hideColumns = array(); + + +// Column filters +if (isset($_GET["f"]) && is_array($_GET["f"])) + $attrFilters = $_GET["f"]; +else + $attrFilters = array(); -if (isset($_GET["f"]) && is_array($_GET["f"])) - $colFilters = $_GET["f"]; -else - $colFilters = array(); +function printTC($a, $column) +{ + global $sortColumn; + echo "<".$a; + if ($column == $sortColumn) + echo " class=\"hilite\""; + echo ">"; +} + + +function getURLStr($cfilters, $col, $dir) +{ + global $sortDirs, $hideColumns; + + $str = "s=".$col."&d=".$sortDirs[$dir]; + + foreach ($cfilters as $fkey => $fval) + $str .= "&f%5B".$fkey."%5D=".$fval; + + foreach ($hideColumns as $fkey => $fvalue) + $str .= "&h%5B%5D=".$fkey; + + return $str; +} function sortMatFunc($a, $b) @@ -42,9 +71,9 @@ $res = $a[$index] < $b[$index]; if ($sortDirection) - return ($res ? 1 : -1); + return $res ? 1 : -1; else - return ($res ? -1 : 1); + return $res ? -1 : 1; } @@ -58,16 +87,8 @@ uasort($matTable, "sortMatFunc"); -function printTC($a, $column) -{ - global $sortColumn; - echo "<".$a; - if ($column == $sortColumn) - echo " class=\"hilite\""; - echo ">"; -} - -printPageHeader($pageTitle); +printPageHeader($pageTitle, + "<meta name=\"robots\" content=\"nofollow\" />\n"); ?> <h1><? echo $pageTitle; ?></h1> <form action="<? echo $pageIndex; ?>" method="get"> @@ -79,7 +100,7 @@ [<a href="<? echo $pageIndex; ?>">Reset/Clear</a>] [<a href="alloy.php">Alloy browser</a>] - <b>CHANGE COLOURS/STYLE: <? for ($i = 1; $i <= 3; $i++) - echo "<a href=\"?css=$i\">($i)</a> " + echo "<a href=\"?css=".$i."\">(".$i.")</a> " ?></b> <br /> <ul> @@ -90,7 +111,7 @@ <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 or materials with certain feature(s) is possible, - for example <a href="index.php?s=0&d=asc&f[1]=5&f[2]=3">show only 'incr. sturdy' + for example <a href="index.php?s=0&d=asc&f[1]=5&f[2]=6">show only 'incr. sturdy' AND 'highly magical'</a> materials. Click on desired feature (table cell) to add a filter.</li> <li>Columns can be disabled from the filtering list (shift or ctrl with mouse click to select several)</li> </ul> @@ -104,7 +125,7 @@ next($transNameTable); while (list($key, $value) = each($transNameTable)) { echo " <option". - (isset($filterTable[$key]) ? " selected=\"selected\"" : ""). + (isset($hideColumns[$key]) ? " selected=\"selected\"" : ""). " value=\"$key\">".htmlentities($value)."</option>\n"; } ?> @@ -113,8 +134,8 @@ <td> <select name="f[14]"> <? -$typeFilter = isset($colFilters[14]) ? $colFilters[14] : -1; -if ($typeFilter == -1) unset($colFilters[14]); +$typeFilter = isset($attrFilters[14]) ? $attrFilters[14] : -1; +if ($typeFilter == -1) unset($attrFilters[14]); $typeTable = $transTable[14]; $typeTable[-1] = "EVERYTHING"; ksort($typeTable); @@ -123,7 +144,6 @@ ($typeFilter == $key ? " selected=\"selected\"" : ""). ">".htmlentities($value)."</option>\n"; } - ?> </select> </td> @@ -134,9 +154,9 @@ </table> </form> <? -if (count($colFilters) > 0) { +if (count($attrFilters) > 0) { $str = ""; - foreach ($colFilters as $fkey => $fval) { + foreach ($attrFilters as $fkey => $fval) { if ($str != "") $str .= ", "; $str .= "<b>".strtolower($transNameTable[$fkey + 1])."</b>=".strtolower($transTable[$fkey][$fval]); } @@ -146,27 +166,12 @@ <table class="matTable"> <tr> <? -function getFilterStr($filters) -{ - global $filterTable; - - $str = ""; - foreach ($filters as $fkey => $fval) - $str .= "&f%5B".$fkey."%5D=".$fval; - - foreach ($filterTable as $fkey => $fvalue) - $str .= "&h%5B%5D=".$fkey; - - return $str; -} - foreach ($transNameTable as $key => $value) { - if (!isset($filterTable[$key])) { + if (!isset($hideColumns[$key])) { echo " "; printTC("th", $key); - echo "<a href=\"?s=".$key."&d=". - $sortDirs[($key == $sortColumn) ? !$sortDirection : $sortDirection]. - getFilterStr($colFilters). + echo "<a href=\"?". + getURLStr($attrFilters, $key, ($key == $sortColumn) ? !$sortDirection : $sortDirection). "\">".htmlentities($value)."</a></th>\n"; } } @@ -175,7 +180,7 @@ foreach ($matTable as $key => $value) { $doShow = TRUE; - foreach ($colFilters as $fkey => $fval) { + foreach ($attrFilters as $fkey => $fval) { if ($fval >= 0 && $value[$fkey] != $fval) { $doShow = FALSE; break; @@ -186,10 +191,13 @@ $col = 0; echo " <tr>"; printTC("td", $col++); - echo "<a href=\"alloy.php?m=".urlencode($key)."\">".htmlentities($key)."</a></td>"; + + echo "<a href=\"alloy.php?m=".urlencode($key)."\">".htmlentities($key)."</a>". +// " <a href=\"?".getURLStr($attrFilters, $sortColumn, $sortDirection)."\">•</a>". + "</td>"; foreach ($value as $kkey => $kvalue) { - if (!isset($filterTable[$kkey + 1])) { + if (!isset($hideColumns[$kkey + 1])) { printTC("td", $col); if (is_array($kvalue)) { // Arrays need special handling, and is bit messy @@ -202,15 +210,14 @@ echo ", ".htmlentities($transTable[$kkey][$lode]); } else { // A simple entry, just print it out - $tmpFilters = $colFilters; + $tmpFilters = $attrFilters; if (isset($tmpFilters[$kkey])) unset($tmpFilters[$kkey]); else $tmpFilters[$kkey] = $kvalue; - echo "<a href=\"?s=".$sortColumn."&d=". - $sortDirs[$sortDirection]. - getFilterStr($tmpFilters). + echo "<a href=\"?". + getURLStr($tmpFilters, $sortColumn, $sortDirection). "\">".htmlentities($transTable[$kkey][$kvalue])."</a>"; } echo "</td>";