Mercurial > hg > batmud > misc
changeset 151:4c0b50a5e7b5 misc
Updated.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2010 22:41:33 +0000 |
parents | 35c93e4727ea |
children | 330ec9a42ae0 |
files | materials/alloy.php materials/stats.php materials/submit.php |
diffstat | 3 files changed, 67 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/alloy.php Tue Dec 21 17:04:09 2010 +0000 +++ b/materials/alloy.php Tue Dec 21 22:41:33 2010 +0000 @@ -7,16 +7,19 @@ require "alloys.inc.php"; -if (isset($_GET["o"])) - $showOnly = intval($_GET["o"]); -else - $showOnly = 0; +$showOnly = isset($_GET["o"]) ? intval($_GET["o"]) : 0; if (isset($_GET["m"])) { $showMat = strtolower($_GET["m"]); $showMatName = strtoupper(substr($showMat,0,1)).substr($showMat, 1); } +if (isset($_GET["swap"])) + $swapRows = $_GET["swap"]; +else + $swapRows = array(); + + printPageHeader($pageTitle, " <style type=\"text/css\"> td.hits20 { background: #0c0; color: black; } @@ -40,7 +43,7 @@ <li><b>Also available in <a href="alloys.txt">ASCII plaintext format</a>.</b></li> <li>Only 2-material alloys are supported by this browser.</li> <li>There may be bugs and lots of combinations are not researched yet.</li> - <li><b>You can now help! We have a <a href="submit.php">submission form</a>!</b></li> + <li><b>You can now help! We have a <a href="submit.php">submission form</a>!</b> We also have <a href="stats.php">submitter statistics</a>.</li> </ul> </td> </tr> @@ -189,25 +192,49 @@ echo "<p>No mixtable entries.</p>\n"; } } -} else { +} +else +{ + /* + * Print alloy table for given material type + */ + // Filter table from maintable matching desired material type(s) $currTable = array(); foreach ($matTable as $name => $data) { if ($data[14] == $typeTable[$showOnly][1] || $data[14] == $typeTable[$showOnly][2]) - $currTable[$name] = $data; + $currTable[] = $name; + } + + // Swap desired rows + if (count($swapRows) > 0) { + $str = ""; + $nkeys = count($currTable); + foreach ($swapRows as $from => $to) + if ($from >= 0 && $from < $nkeys && $to >= 0 && $to < $nkeys && $to != $from) { + if ($str != "") $str .= ", "; + $str .= "$from <=> $to"; + $tmp = $currTable[$from]; + $currTable[$from] = $currTable[$to]; + $currTable[$to] = $tmp; + } + if ($str != "") + echo "<p>Swapped rows: ".$str."</p>\n"; } + + // Print out the table echo "<table class=\"alloyTable\">". " <tr>\n". " <th>-</th>\n"; - foreach ($currTable as $name => $data) { + foreach ($currTable as $name) { echo " <th>".matLink($name)."</th>\n"; } echo " </tr>\n"; - foreach ($currTable as $mat1 => $value) { + foreach ($currTable as $mat1) { echo " <tr><th>".matLink($mat1)."</th>"; - foreach ($currTable as $mat2 => $v) { + foreach ($currTable as $mat2) { if (isset($alloyTable[$mat1][$mat2])) $tmp = $alloyTable[$mat1][$mat2]; @@ -219,7 +246,7 @@ $tag = ($mat1 == $mat2) ? "th" : "td"; if (isset($tmp) && list($a, $b) = each($tmp)) { - echo "<".$tag.addValueStyle($b)." title=\"".$b." succesful alloys (".$mat1." + ".$mat2." = ".$a.")\">".matLink($a)."</".$tag.">"; + echo "<".$tag.addValueStyle($b)." title=\"".$b." successful alloys (".$mat1." + ".$mat2." = ".$a.")\">".matLink($a)."</".$tag.">"; } else echo "<".$tag." class=\"nohits\">-</".$tag.">"; }
--- a/materials/stats.php Tue Dec 21 17:04:09 2010 +0000 +++ b/materials/stats.php Tue Dec 21 22:41:33 2010 +0000 @@ -1,5 +1,5 @@ <? -$pageTitle = "Alloy combination submitter statistics"; +$pageTitle = "Alloy combination submitter statistics (BETA)"; require "mcommon.inc.php"; require "guids.inc.php"; @@ -40,6 +40,9 @@ printPageHeader($pageTitle); ?> <h1><? echo $pageTitle ?></h1> +<p> +"Submitted tries" means number of successful alloying attempts submitted by user, "different combos" is number of submissions with different components. +</p> <table> <tr> <th>User</th> @@ -57,5 +60,10 @@ </table> <? echo "<p><b>$total</b> user-submitted tries, <b>".$combos."</b> total user-submitted combos.</p>\n"; +?> +<p> +[<a href="alloy.php">Back to Alloy browser</a>] +</p> +<? printPageFooter(); ?>
--- a/materials/submit.php Tue Dec 21 17:04:09 2010 +0000 +++ b/materials/submit.php Tue Dec 21 22:41:33 2010 +0000 @@ -110,6 +110,11 @@ printPageFooter(); } +function plainText($str) +{ + return strip_tags(preg_replace(array("/<p>/","/<\/p>/", "/<br *\/?>/"), array(" ", " ", " "), $str)); +} + function addAlloy(&$alloys, $names) { global $errorStr, $errorSet; @@ -155,10 +160,14 @@ // Page code begins here if ($formMode == -1) { - pageHead(); - echo "<h2>An error occured</h2>\n<div>".$errorMsg."<br /></div>\n"; - echo "<p>[ <a href=\"submit.php\">Try again</a> ]</p>\n"; - pageEnd(); + if ($hasData) { + pageHead(); + echo "<h2>An error occured</h2>\n<div>".$errorMsg."<br /></div>\n"; + echo "<p>[ <a href=\"submit.php\">Try again</a> ]</p>\n"; + pageEnd(); + } else { + echo "ERROR! ".plainText($errorMsg); + } } elseif ($formMode == 0) { pageHead(); @@ -240,9 +249,9 @@ if (count($alloys) > 0) { // Open datafile and save accepted data $filename = "data-".strtolower($submitGUIDS[$formGUID]).".log"; - $outFile = fopen($filename, "a"); + $outFile = @fopen($filename, "a"); if ($outFile !== FALSE) { - chmod($filename, 0600); + @chmod($filename, 0600); foreach ($alloys as $val) { $s = $formGUID."#".$val[0]; for ($i = 1; $i < count($val) - 1; $i++) @@ -264,9 +273,9 @@ // Save the error messages, just in case if ($errorSet) { $filename = "error-".strtolower($submitGUIDS[$formGUID]).".log"; - $outFile = fopen($filename, "a"); + $outFile = @fopen($filename, "a"); if ($outFile !== FALSE) { - chmod($filename, 0600); + @chmod($filename, 0600); fwrite($outFile, $errorStr); fclose($outFile); } @@ -295,11 +304,9 @@ echo "<p>[ <a href=\"?guid=".urlencode($formGUID)."\">Click here to return to the submit page</a> ]</p>\n"; pageEnd(); } else { - if ($errorSet) { - pageHead(); - echo "<ol>".$errorStr."</ol>\n"; - pageEnd(); - } else + if ($errorSet) + echo "ERROR! ".plainText($errorStr); + else echo "OK"; }