Mercurial > hg > fapweb
view pages/register.inc.php @ 1010:b3f579c33b08
Cosmetics, comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Nov 2015 16:43:42 +0200 |
parents | ffacd904fd1f |
children | b7916209da83 |
line wrap: on
line source
<? // // FAPWeb - Simple Web-based Demoparty Management System // Attendee registration page // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) // $mode = stGetRequestItem("mode", "start"); // Settings for robot check hash generator $botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456"; $botCheckOPs = "bit"; $botCheckROPs = "+-*"; $formFields = array( "name" => "Name", "groups" => "Group(s)", "email" => "E-mail", "oneliner" => "Oneliner", "hash" => FALSE, "botcheck" => FALSE, ); function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") { echo " <tr><th>".chentities($text1)."</th><td>". stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). "</td><td>".chentities($text2)."</td></tr>\n"; } function stPrintFormHiddenInput($name, $value) { echo " ".stGetFormHiddenInput($name, $value)."\n"; } function stPrintFormData($button, $mode = "start", $exclude = array()) { global $formFields; echo stGetFormStart("register", "register"). " ".stGetFormSubmitInput("continue", $button)."\n"; stPrintFormHiddenInput("mode", $mode); foreach ($formFields as $name => $title) { if (!in_array($name, $exclude)) stPrintFormHiddenInput($name, stGetRequestItem($name)); } echo "</form>\n"; } // Convert integer value to hash code function intValueToHash($val) { global $botCheckIDs; $str = ""; do { $str = $botCheckIDs[$val & 31].$str; $val >>= 5; } while ($val > 0); return $str; } // Convert integer hash to integer value function intHashToValue($hash) { global $botCheckIDs; for ($val = 0, $i = 0; $i < strlen($hash); $i++) { $val *= 32; $n = strpos($botCheckIDs, $hash[$i]); if ($n !== FALSE) $val += $n; else return -2; } return $val; } // Split hash into parts function splitHash($hash) { global $botCheckOPs; return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE); } function hashToCheckStr($hash) { global $botCheckOPs, $botCheckROPs; $out = ""; foreach (splitHash($hash) as $val) { $i = strpos($botCheckOPs, $val); if ($i !== FALSE) $out .= " ".$botCheckROPs[$i]." "; else $out .= intHashToValue($val); } return $out; } function hashToAnswer($hash) { eval("\$res = ".hashToCheckStr($hash).";"); return $res; } // Check if user registration is available stCheckRegistrationAvailable(); // Check if registration is enabled if (!stChkSetting("allowRegister")) { echo stGetSetting("registerNotEnabled"); } else if ($maxAttendeesHard > 0 && $numAttendees >= $maxAttendeesHard) { echo stGetSetting("registerLimitExceeded"); } else if ($mode == "start") { // // Show registration form // // Generate bot-check $botCheckHash = intValueToHash(rand(1,5)). $botCheckOPs[rand(0,2)]. intValueToHash(rand(1,5)). $botCheckOPs[rand(0,2)]. intValueToHash(5 * rand(1,5)); echo stGetSetting("registerPageBlurb"). stGetFormStart("register", "register"). " ".stGetFormHiddenInput("mode", "check")."\n". " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". " <table class=\"register\">\n"; stPrintFormTextInput("Handle:", "(elite)", 20, SET_LEN_USERNAME, "name"); stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 30, SET_LEN_GROUPS, "groups"); stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 30, SET_LEN_EMAIL, "email"); stPrintFormTextInput("Oneliner:", "(whatever)", 30, SET_LEN_ONELINER, "oneliner"); stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check". //" [".hashToAnswer($botCheckHash)."]". ")", 20, 20, "botcheck", "autocomplete=\"off\""); echo " <tr><td colspan=\"2\"></td><td>".stGetFormSubmitInput("register", "Continue")."</td></tr>\n". " </table>\n". "</form>\n"; echo stGetSetting("registerInfoText"); } else if ($mode == "check" || $mode == "register") { // // Check the registrant's details // stChkRequestItem("hash", $hash, array(CHK_GTEQ, VT_STR, 0, "Invalid data.")); stValidateRequestUserData(FALSE, FALSE); $answer = stGetRequestItem("botcheck"); if (hashToAnswer($hash) != intval($answer)) stError("Incorrect answer to I.Q. / bot check."); if ($errorSet) { // There were errors or missing data echo "<h1>Following errors occured:</h1>\n". "<ul>\n"; foreach ($errorMsgs as $msg) echo " <li>".$msg."</li>\n"; echo "</ul>\n"; stPrintFormData("Go back", "start", array("botcheck")); } else if ($mode == "register") { // Data ok, registration mode $sql = stGetAttendeeRegistrationSQL(); if (stExecSQL($sql) !== FALSE) { echo stGetSetting("registerPostText"); if (strlen(stGetRequestItem("email")) < 4) echo stGetSetting("registerPostNoEmail"); } else { echo "<h1>An error occured.</h1>\n". "<p>Oh noes! SQL error happenstance!</p>"; } } else { // Data ok, verify echo "<h1>Verify your information</h1>\n". "<p>Is the following information correct?</p>\n". "<table class=\"register\">\n"; foreach ($formFields as $name => $title) { if ($title !== FALSE) { echo " <tr><th class=\"".$name."\">".chentities($title).":</th>". "<td>".chentities(stGetRequestItem($name))."</td></tr>\n"; } } echo "</table>\n"; stPrintFormData("Go back", "start", array("botcheck")); stPrintFormData("Register", "register"); } } ?>