view materials/index.php @ 0:81f1abadda3e misc

Renamed.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 17 Jul 2008 12:04:43 +0000
parents
children 652a6864d3ce
line wrap: on
line source

<?
require "config.inc.php";
require "material.inc.php";

$sortDirs = array("asc", "desc");


if (isset($_GET["s"])) {
  $sortColumn = intval($_GET["s"]);
} else
  $sortColumn = 0;


if (isset($_GET["d"])) {
  $s = substr(strtolower($_GET["d"]), 0, 1);
  if ($s == "d")
    $sortDirection = 1;
  else
    $sortDirection = 0;
} else
  $sortDirection = 0;


if (isset($_GET["h"]) && is_array($_GET["h"]))
  $filterTable = array_flip($_GET["h"]);
else
  $filterTable = array();


if (isset($_GET["o"])) {
  $showOnly = intval($_GET["o"]);
} else
  $showOnly = -1;


function sortMatFunc($a, $b)
{
  global $sortDirection, $sortColumn;
  $index = $sortColumn - 1;

  if ($a[$index] == $b[$index])
    return 0;
  
  $res = $a[$index] < $b[$index];
  
  if ($sortDirection)
    return ($res ? 1 : -1);
  else
    return ($res ? -1 : 1);
}

if ($sortColumn <= 0 || $sortColumn >= 18) {
  $sortColumn = 0;
  if ($sortDirection)
    krsort($matTable, SORT_STRING);
  else
    ksort($matTable, SORT_STRING);
} else
  uasort($matTable, "sortMatFunc");


function printTC($a, $column)
{
  global $sortColumn;
  echo "<".$a;
  if ($column == $sortColumn)
    echo " class=\"hilite\"";
  echo ">";
}


require "../header.inc.php";
?>
<h1><? echo $pageTitle; ?></h1>
<form action="index.php" method="get">
<table class="optionsTable">
 <tr>
  <th>Hide columns</th>
  <th>Show only type</th>
  <td rowspan="3" style="background: black; border: 1px solid white; color: red;">
   Please note, that this is BETA version. There may be bugs.
   If you notice any persistent bugs, contact <b>Ggr</b>.
   <ul>
    <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>Columns can be disabled from the filtering list (shift or ctrl with mouse click to select several)</li>
   </ul>
  </td>
 </tr>
 <tr>
  <td>
   <select multiple="multiple" size="5" name="h[]">
<?
reset($transNameTable);
next($transNameTable);
while (list($key, $value) = each($transNameTable)) {
  echo "<option";
  if (isset($filterTable[$key]))
    echo " selected=\"selected\"";
  echo " value=\"$key\">".htmlentities($value)."</option>\n";
}
?>
   </select>
  </td>
  <td>
   <select name="o">
<?
$typeTable = $transTable[14];
$typeTable[-1] = "EVERYTHING";
ksort($typeTable);
reset($typeTable);
$showOnlySet = FALSE;
while (list($key, $value) = each($typeTable)) {
  echo "    <option value=\"$key\"";
  if ($showOnly == $key) {
    echo " selected=\"selected\"";
    $showOnlySet = TRUE;
  }
  echo ">".htmlentities($value)."</option>\n";
}
if ($showOnly < 0)
  $showOnlySet = FALSE;

?>
   </select>
  </td>
 </tr>
 <tr>
  <td colspan="2" class="icenter"><input type="submit" value=" Filter " class="isubmit" /></td>
  <td></td>
 </tr>
</table>
<?
/*
if ($sortColumn >= 0) {
  echo "<input type=\"hidden\" name=\"s\" value=\"".$sortColumn."\" />\n";
  echo "<input type=\"hidden\" name=\"d\" value=\"".$sortDirs[$sortDirection]."\" />\n";
}
*/
?>
</form>

<table class="matTable">
 <tr>
<?
reset($transNameTable);
while (list($key, $value) = each($transNameTable)) {
  if (!isset($filterTable[$key])) {
  echo "  ";
  printTC("th", $key);
  echo "<a href=\"?s=".$key."&amp;d=";
  if ($key == $sortColumn)
    echo $sortDirs[!$sortDirection];
  else
    echo $sortDirs[$sortDirection];
  if ($showOnlySet)
    echo "&amp;o=".$showOnly;
  
  reset($filterTable);
  while (list($fkey, $fvalue) = each($filterTable)) {
    echo "&amp;h%5B%5D=".$fkey;
  }
  echo "\">".htmlentities($value)."</a></th>\n";
  }
}
echo " </tr>\n";

reset($matTable);
while (list($key, $value) = each($matTable)) {
  if ($showOnlySet)
    $doShow = ($value[14] == $showOnly);
  else
    $doShow = TRUE;
  
  if ($doShow) {
    $col = 0;
    echo " <tr>";
    printTC("td", $col++);
    echo htmlentities($key)."</td>";
    
    while (list($kkey, $kvalue) = each($value)) {
      if (!isset($filterTable[$kkey+1])) {
        printTC("td", $col);
        if (isset($transTable[$kkey][$kvalue])) {
          echo htmlentities($transTable[$kkey][$kvalue]);
        } else {
          echo $kvalue;
        }
        echo "</td>";
      }
      $col++;
    }
    echo "</tr>\n";
  }
}
echo "</table>\n";

require "../footer.inc.php";
?>