Mercurial > hg > batmud > misc
changeset 262:d26cf08d9bf0 misc
Remove dead files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Mar 2015 06:04:45 +0200 |
parents | 57ded86f87b7 |
children | a3270c80e3c0 |
files | materials/stats.php materials/submit.php |
diffstat | 2 files changed, 0 insertions(+), 383 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/stats.php Sun Mar 08 05:35:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -<? -$pageTitle = "Alloy combination submitter statistics (BETA)"; - -require "mcommon.inc.php"; -require "guids.inc.php"; - -$users = array(); -$total = 0; - -foreach ($submitPasswords as $password => $user) { - $g = strtolower($password); - $filename = "data-".strtolower($user).".log"; - $file = @fopen($filename, "r"); - - if ($file !== FALSE) { - while (($line = fgets($file, 1024)) !== false) { - if (preg_match("/^(.*?)#(.*?)=(.*)$/", strtolower($line), $m)) { - if ($m[1] == $g) { - $total++; - $com = explode("+", $m[2]); - $users[$user]["tries"]++; - - if (!isset($users[$user]["combo"][$com[0]][$com[1]]) && !isset($users[$user]["combo"][$com[1]][$com[0]])) { - $users[$user]["combo"][$com[0]][$com[1]] = $m[3]; - } - } - } - } - fclose($file); - } -} - -function cmp($a, $b) -{ - return $b["tries"] - $a["tries"]; -} - -uasort($users, "cmp"); - -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> - <th>Submitted tries</th> - <th>Different combos</th> - </tr> -<? - -$combos = 0; -foreach ($users as $user => $data) { - echo " <tr><td>".$user."</td><td>".$data["tries"]."</td><td>".count($data["combo"])."</td></tr>\n"; - $combos += count($data["combo"]); -} -?> -</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 Sun Mar 08 05:35:08 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,314 +0,0 @@ -<? -$pageTitle = "Alloy combination submitter"; -$pageIndex = "submit.php"; - -require "mcommon.inc.php"; -require "materials.inc.php"; -require "alloys.inc.php"; -require "guids.inc.php"; - -$formMode = -1; -$hasPassword = FALSE; -$hasData = FALSE; - -// Get form arguments, if they are set -if (isset($_GET["guid"])) { - $formPassword = $_GET["guid"]; - $hasPassword = TRUE; -} elseif (isset($_POST["guid"])) { - $formPassword = stripslashes($_POST["guid"]); - $hasPassword = TRUE; -} - -if (isset($_POST["data"])) { - $formData = stripslashes($_POST["data"]); - $hasData = TRUE; -} - - -// Check submitter password -if ($hasPassword) { - if (strlen($formPassword) < 6 || strlen($formPassword) > 20) { - $formMode = -1; - $errorMsg = "Submitter password <b>'".htmlentities(substr($formPassword, 0, 20))."...'</b> is invalid."; - } else - if (!isset($submitPasswords[$formPassword])) { - $formMode = -1; - $errorMsg = "Submitter password <b>'".htmlentities($formPassword)."'</b> is not known. ". - "Please check that you have entered your password code correctly (it is case-sensitive!)<br /><br />". - "Also, if you received your Password recently (during last 10 minutes or so), it might not have ". - "yet been added to the system. Wait for a bit and try again."; - } else { - // Password is ok - if ($hasData) { - // Got some data, go and check it for sanity - $formMode = 2; - } else { - // No data. Proceed to submission, except if below code triggers... - $formMode = 1; - - // This is a bit of a hack ... - $mat1Set = isset($_GET["mat1"]); $mat1 = $_GET["mat1"]; - $mat2Set = isset($_GET["mat2"]); $mat2 = $_GET["mat2"]; - $resSet = isset($_GET["res"]); $res = $_GET["res"]; - if ($mat1Set || $mat2Set || $resSet) { - if ($mat1Set && $mat2Set && $resSet) { - // Data set, process it. - $formMode = 2; - } else { - // Some data set, but not all. - $formMode = -1; - $errorMsg = "All required parameters not set. You need to send <b>mat1, mat2 and res</b>."; - } - } - } - } -} else { - // By default, assume we are in Password setup mode - $formMode = 0; -} - -function getMaterial($name) -{ - global $matTable; - if (isset($matTable[$name])) - return $matTable[$name]; - else - return FALSE; -} - -function getMatClass($mat) { - $matClass = array( - 0 => 0, - 1 => 0, - - 2 => 1, - - 3 => 2, - 5 => 2, - - 4 => 3, - 7 => 3, - - 6 => 4, - 8 => 5, - 9 => 6, - 10 => 7, - ); - return isset($matClass[$mat]) ? $matClass[$mat] : -1; -} - -function pageHead() -{ - global $pageTitle; - printPageHeader($pageTitle); - echo "<h1>".$pageTitle."</h1>\n"; -} - -function pageEnd() -{ - printPageFooter(); -} - -function plainText($str) -{ - return strip_tags(preg_replace(array("/<p>/","/<\/p>/", "/<br *\/?>/"), array(" ", " ", " "), $str)); -} - -function addAlloy(&$alloys, $names) -{ - global $errorStr, $errorSet; - $allKnown = TRUE; - $allSame = TRUE; - $matClass = -1; - $last = count($names) - 1; - - for ($i = 1; $i < count($names); $i++) { - $tmp = getMaterial($names[$i]); - if ($tmp === FALSE) - $allKnown = FALSE; - else { - if ($matClass != -1 && getMatClass($tmp[14]) != $matClass) - $allSame = FALSE; - $matClass = getMatClass($tmp[14]); - } - } - - if (!$allKnown) { - $errorStr .= "<li>One or more of following materials were unknown: "; - for ($i = 1; $i < $last; $i++) - $errorStr .= "'".$names[$i]."', "; - $errorStr .= " or '".$names[$last]."'.</li>"; - $errorSet = TRUE; - return FALSE; - } elseif (!$allSame) { - $errorStr .= "<li>Material types of "; - for ($i = 1; $i < $last; $i++) - $errorStr .= "'".$names[$i]."', "; - $errorStr .= " and '".$names[$last]."' do not match. Invalid submission.</li>"; - $errorSet = TRUE; - return FALSE; - } else { - // FIXME! - $tmp = array(); - for ($i = 1; $i < count($names); $i++) - $tmp[] = $names[$i]; - $alloys[] = $tmp; - return TRUE; - } -} - -// Page code begins here -if ($formMode == -1) { - 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(); -?> -<p> -Welcome to the Pupunen alloy database submit form. Before you can proceed to submit -your combinations, you will need to enter your personal submitter Password in the -form below. To get your own Password code, ask for one via tell from <b>Ggr</b> @ BatMUD. -This identification system is in place to lessen the possibility of fake submissions. -</p> -<form action="<? echo $pageIndex; ?>" method="get"> -<b>Submitter Password code:</b> <input type="text" name="guid" size="30" class="itext" -<? if ($hasPassword) echo "value=\"".$formPassword."\""; ?> /> -<input type="submit" value=" Continue " class="isubmit" /> -</form> -<h2>NOTICE!</h2> -<p> -Please only submit combinations that you have tested yourself RECENTLY (e.g. during 2009 or so). -Submitting data from old logs is counterproductive, because this project's intention -is to update the alloy data matrixes. -</p> -<br /> -<div class="infobox"> -<b>Alternatively</b>, if you wish to use triggers or some other similar system -to submit data, this form offers a simple submission "API". You can use an URL -in following format to submit data automatically: -<pre> -http://tnsp.org/mat/submit.php?guid=<b>your_guid</b>&mat1=<b>material1</b>&mat2=<b>material2</b>&res=<b>result</b> -</pre> -The parameters should be self-explanatory. The URL and arguments need to be properly encoded, -of course (at least spaces replaced with "+", if nothing else). -</div> -<? -pageEnd(); -} elseif ($formMode == 1) { -pageHead(); -?> -<form action="<? echo $pageIndex; ?>" method="post"> -Submitter: <b><? echo htmlentities($submitPasswords[$formPassword]); ?></b><br /><br /> -<textarea name="data" cols="80" rows="10"></textarea><br /><br /> -<div class="icenter"> -<input type="hidden" value="<? echo htmlentities($formPassword); ?>" name="guid" /> -<input type="submit" value=" Submit " class="isubmit" /> -</div> -</form> -<p> -<b>Feel free to bookmark this page, to avoid entering the Password each time.</b> -</p> -<p> -With the above form, you can submit alloy combinations to be included in this -alloy database project. The format for submissions should be the line -<b>"You mix A and B and create a quantity of C"</b>. You can submit as many -such lines as you wish. <b>Empty lines, and unidentified lines are discarded, -validated data will be shown on next page!</b> -</p> -<p> -Please notice, that even though the submissions are automatically checked -for certain "sanity", they will not automatically go into the database, -but require my (Ggr) manual intervention and may take some time before -they are added. -</p> -<? -pageEnd(); -} elseif ($formMode == 2) { - // Process and check the data - $errorSet = FALSE; - $errorStr = ""; - $alloys = array(); - if ($hasData) { - $postData = explode("\n", $formData); - foreach ($postData as $line) - if (preg_match("/You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of ([a-z ]+)/", $line, $m)) { - addAlloy($alloys, $m); - } - } else { - addAlloy($alloys, array("match", $mat1, $mat2, $res)); - } - - if (count($alloys) > 0) { - // Open datafile and save accepted data - $filename = "data-".strtolower($submitPasswords[$formPassword]).".log"; - $outFile = @fopen($filename, "a"); - if ($outFile !== FALSE) { - @chmod($filename, 0600); - foreach ($alloys as $val) { - $s = $formPassword."#".$val[0]; - for ($i = 1; $i < count($val) - 1; $i++) - $s .= "+".$val[$i]; - $s .= "=".$val[count($val) - 1]."\n"; - if (fwrite($outFile, $s) === FALSE) { - $errorStr = "<li><b>FATAL ERROR! Error sending data to database server!</b> Data not daved!</li>"; - $errorSet = TRUE; - break; - } - } - fclose($outFile); - } else { - $errorStr .= "<li><b>FATAL ERROR! Could not open database connection!</b> Data not saved!</li>"; - $errroSet = TRUE; - } - } - - // Save the error messages, just in case - if ($errorSet) { - $filename = "error-".strtolower($submitPasswords[$formPassword]).".log"; - $outFile = @fopen($filename, "a"); - if ($outFile !== FALSE) { - @chmod($filename, 0600); - fwrite($outFile, $errorStr); - fclose($outFile); - } - } - - // Show output - if ($hasData) { - pageHead(); - if ($errorSet) { - echo "<h3>Errors found!</h3>\n<ul>".$errorStr."</ul>\n"; - } - - if (count($alloys) > 0) { - echo "<h3>Accepted alloys</h3>\n<ul>"; - foreach ($alloys as $val) { - echo "<li>".$val[0]; - for ($i = 1; $i < count($val) - 1; $i++) - echo " + ".$val[$i]; - echo " = <b>".$val[count($val) - 1]."</b></li>\n"; - } - echo "</ul>\n". - "<p><b>THANK YOU for your submission!</b></p>\n"; - } else { - echo "<p><b>No alloy combinations could be parsed from input.</b></p>\n"; - } - echo "<p>[ <a href=\"?guid=".urlencode($formPassword)."\">Click here to return to the submit page</a> ]</p>\n"; - pageEnd(); - } else { - if ($errorSet) - echo "ERROR! ".plainText($errorStr); - else - echo "OK"; - } - -} -?>