comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:8019b357cc03
1 <?
2 $mode = stGetRequestItem("mode", "start");
3
4 $botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456";
5 $botCheckOPs = "bit";
6 $botCheckROPs = "+-*";
7
8
9 function stPrintFormData($button, $mode = "start")
10 {
11 echo
12 "<form name=\"register\" action=\"register\" method=\"post\">\n".
13 " <input type=\"submit\" value=\"".chentities($button)."\" />\n";
14
15 stPrintFormHiddenInput("mode", $mode);
16
17 foreach (array("name", "groups", "email", "oneliner", "hash", "botcheck") as $name)
18 stPrintFormHiddenInput($name, stGetRequestItem($name));
19
20 echo "</form>\n";
21 }
22
23
24 function intValueToHash($val)
25 {
26 global $botCheckIDs;
27 $str = "";
28 do
29 {
30 $str = $botCheckIDs[$val & 31].$str;
31 $val >>= 5;
32 }
33 while ($val > 0);
34 return $str;
35 }
36
37
38 function intHashToValue($hash)
39 {
40 global $botCheckIDs;
41 for ($val = 0, $i = 0; $i < strlen($hash); $i++)
42 {
43 $val *= 32;
44 $n = strpos($botCheckIDs, $hash[$i]);
45 if ($n !== FALSE)
46 $val += $n;
47 else
48 return -2;
49 }
50 return $val;
51 }
52
53
54 function splitHash($hash)
55 {
56 global $botCheckOPs;
57 return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE);
58 }
59
60
61 function hashToCheckStr($hash)
62 {
63 global $botCheckOPs, $botCheckROPs;
64 $out = "";
65
66 foreach (splitHash($hash) as $val)
67 {
68 $i = strpos($botCheckOPs, $val);
69 if ($i !== FALSE)
70 $out .= " ".$botCheckROPs[$i]." ";
71 else
72 $out .= intHashToValue($val);
73 }
74 return $out;
75 }
76
77
78 function hashToAnswer($hash)
79 {
80 eval("\$res = ".hashToCheckStr($hash).";");
81 return $res;
82 }
83
84 // Check if registration is enabled
85 if (!stChkSetting("allowRegister"))
86 {
87 ?>
88 <h1>Sorry, registration disabled!</h1>
89 <p>
90 Registration to the event is not available at this time.
91 </p>
92 <?
93 }
94 else
95 if ($mode == "start")
96 {
97 $botCheckHash =
98 intValueToHash(rand(1,5)).
99 $botCheckOPs[rand(0,2)].
100 intValueToHash(rand(1,5)).
101 $botCheckOPs[rand(0,2)].
102 intValueToHash(5 * rand(1,5));
103
104 ?>
105 <h1>Registration</h1>
106
107 <form name="register" action="register" method="post">
108 <input type="hidden" name="mode" value="check">
109 <input type="hidden" name="hash" value="<? echo $botCheckHash ?>">
110 <table>
111 <?
112 stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name");
113 stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups");
114 stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email");
115 stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner");
116 stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check".
117 //" [".hashToAnswer($botCheckHash)."]".
118 ")", 20, 20, "botcheck");
119 ?>
120 <tr><td colspan="2"></td><td><input type="submit" value="Register" /></td></tr>
121 </table>
122 </form>
123 <p>
124 Only your <b>handle</b> and the answer to the botcheck are strictly required. If you plan on joining the IRC channel
125 (<? stPrintSpecURL("irc") ?>) or staying up to date by other means,
126 <b>e-mail</b> is not required either.
127 </p>
128
129 <?
130 }
131 else
132 if ($mode == "check")
133 {
134 if (stChkDataItem("name") || strlen(stGetRequestItem("name")) < 3)
135 stError("Handle / name not given, or too short.");
136
137 if (stChkDataItem("hash"))
138 stError("Invalid data.");
139
140 $hash = stGetRequestItem("hash");
141 $answer = stGetRequestItem("botcheck");
142 if (hashToAnswer($hash) != intval($answer))
143 stError("Incorrect answer to I.Q. / bot check.");
144
145 if ($errorSet)
146 {
147 echo "<p>Following errors occured:</p>\n".
148 "<ul>\n".$errorMsg."</ul>\n";
149 stPrintFormData("Go back");
150 }
151 else
152 {
153 $sql = stPrepareSQL(
154 "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)",
155 time(), "name", "groups", "oneliner", "email");
156
157 if (stExecSQL($sql) !== FALSE)
158 {
159 echo "<h1>Registration successful</h1>\n";
160 echo "<p>Now go make a demo about it!</p>\n";
161 if (stChkDataItem("email"))
162 {
163 echo "<h2>By the way ...</h2>".
164 "<p>As you did not specify an e-mail contact address, you'll have to get updates ".
165 "and information about the location (if you don't already know it) by ".
166 "some other means (<b>".stSpecURL("irc").", for example.</b>)</p>";
167 }
168 }
169 else
170 {
171 echo "<h1>An error occured.</h1>\n";
172 echo "<p>Oh noes! SQL error happenstance!</p>";
173 }
174 }
175 }
176 ?>