diff register.inc.php @ 0:8019b357cc03

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Dec 2012 19:07:18 +0200
parents
children 6da681d1f62a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/register.inc.php	Tue Dec 04 19:07:18 2012 +0200
@@ -0,0 +1,176 @@
+<?
+$mode = stGetRequestItem("mode", "start");
+
+$botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456";
+$botCheckOPs = "bit";
+$botCheckROPs = "+-*";
+
+
+function stPrintFormData($button, $mode = "start")
+{
+  echo
+  "<form name=\"register\" action=\"register\" method=\"post\">\n".
+  " <input type=\"submit\" value=\"".chentities($button)."\" />\n";
+
+  stPrintFormHiddenInput("mode", $mode);
+  
+  foreach (array("name", "groups", "email", "oneliner", "hash", "botcheck") as $name)
+    stPrintFormHiddenInput($name, stGetRequestItem($name));
+
+  echo "</form>\n";
+}
+
+
+function intValueToHash($val)
+{
+  global $botCheckIDs;
+  $str = "";
+  do
+  {
+    $str = $botCheckIDs[$val & 31].$str;
+    $val >>= 5;
+  }
+  while ($val > 0);
+  return $str;
+}
+
+
+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;
+}
+
+
+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 registration is enabled
+if (!stChkSetting("allowRegister"))
+{
+?>
+<h1>Sorry, registration disabled!</h1>
+<p>
+Registration to the event is not available at this time.
+</p>
+<?
+}
+else
+if ($mode == "start")
+{
+  $botCheckHash =
+    intValueToHash(rand(1,5)).
+    $botCheckOPs[rand(0,2)].
+    intValueToHash(rand(1,5)).
+    $botCheckOPs[rand(0,2)].
+    intValueToHash(5 * rand(1,5));
+
+?>
+<h1>Registration</h1>
+
+<form name="register" action="register" method="post">
+ <input type="hidden" name="mode" value="check">
+ <input type="hidden" name="hash" value="<? echo $botCheckHash ?>">
+ <table>
+<?
+stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name");
+stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups");
+stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email");
+stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner");
+stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check".
+//" [".hashToAnswer($botCheckHash)."]".
+")", 20, 20, "botcheck");
+?>
+  <tr><td colspan="2"></td><td><input type="submit" value="Register" /></td></tr>
+ </table>
+</form>
+<p>
+Only your <b>handle</b> and the answer to the botcheck are strictly required. If you plan on joining the IRC channel
+(<? stPrintSpecURL("irc") ?>) or staying up to date by other means,
+<b>e-mail</b> is not required either.
+</p>
+
+<?
+}
+else
+if ($mode == "check")
+{
+  if (stChkDataItem("name") || strlen(stGetRequestItem("name")) < 3)
+    stError("Handle / name not given, or too short.");
+
+  if (stChkDataItem("hash"))
+    stError("Invalid data.");
+
+  $hash = stGetRequestItem("hash");
+  $answer = stGetRequestItem("botcheck");
+  if (hashToAnswer($hash) != intval($answer))
+    stError("Incorrect answer to I.Q. / bot check.");
+
+  if ($errorSet)
+  {
+    echo "<p>Following errors occured:</p>\n".
+    "<ul>\n".$errorMsg."</ul>\n";
+    stPrintFormData("Go back");
+  }
+  else
+  {
+    $sql = stPrepareSQL(
+      "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)",
+      time(), "name", "groups", "oneliner", "email");
+
+    if (stExecSQL($sql) !== FALSE)
+    {
+      echo "<h1>Registration successful</h1>\n";
+      echo "<p>Now go make a demo about it!</p>\n";
+      if (stChkDataItem("email"))
+      {
+        echo "<h2>By the way ...</h2>".
+        "<p>As you did not specify an e-mail contact address, you'll have to get updates ".
+        "and information about the location (if you don't already know it) by ".
+        "some other means (<b>".stSpecURL("irc").", for example.</b>)</p>";
+      }
+    }
+    else
+    {
+      echo "<h1>An error occured.</h1>\n";
+      echo "<p>Oh noes! SQL error happenstance!</p>";
+    }
+  }
+}
+?>
\ No newline at end of file