Mercurial > hg > fapweb
annotate register.inc.php @ 138:e04f6e3c04f7
Add some comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Oct 2013 22:05:00 +0300 |
parents | aeebfedb5709 |
children | e227e6a3d46b |
rev | line source |
---|---|
0 | 1 <? |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
2 // |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
3 // FAPWeb Simple Demoparty System |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
4 // Attendee registration page |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
6 // |
0 | 7 $mode = stGetRequestItem("mode", "start"); |
8 | |
138 | 9 // Settings for robot check hash generator |
0 | 10 $botCheckIDs = "aBcdefghIjklmnopqrsTuvxyz0123456"; |
11 $botCheckOPs = "bit"; | |
12 $botCheckROPs = "+-*"; | |
13 | |
14 | |
15 function stPrintFormData($button, $mode = "start") | |
16 { | |
17 echo | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
18 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
19 " ".stGetFormSubmitInput("continue", $button)."\n"; |
0 | 20 |
21 stPrintFormHiddenInput("mode", $mode); | |
22 | |
23 foreach (array("name", "groups", "email", "oneliner", "hash", "botcheck") as $name) | |
24 stPrintFormHiddenInput($name, stGetRequestItem($name)); | |
25 | |
26 echo "</form>\n"; | |
27 } | |
28 | |
29 | |
138 | 30 // Convert integer value to hash code |
0 | 31 function intValueToHash($val) |
32 { | |
33 global $botCheckIDs; | |
34 $str = ""; | |
35 do | |
36 { | |
37 $str = $botCheckIDs[$val & 31].$str; | |
38 $val >>= 5; | |
39 } | |
40 while ($val > 0); | |
41 return $str; | |
42 } | |
43 | |
44 | |
138 | 45 // Convert integer hash to integer value |
0 | 46 function intHashToValue($hash) |
47 { | |
48 global $botCheckIDs; | |
49 for ($val = 0, $i = 0; $i < strlen($hash); $i++) | |
50 { | |
51 $val *= 32; | |
52 $n = strpos($botCheckIDs, $hash[$i]); | |
53 if ($n !== FALSE) | |
54 $val += $n; | |
55 else | |
56 return -2; | |
57 } | |
58 return $val; | |
59 } | |
60 | |
61 | |
138 | 62 // Split hash into parts |
0 | 63 function splitHash($hash) |
64 { | |
65 global $botCheckOPs; | |
66 return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE); | |
67 } | |
68 | |
69 | |
70 function hashToCheckStr($hash) | |
71 { | |
72 global $botCheckOPs, $botCheckROPs; | |
73 $out = ""; | |
74 | |
75 foreach (splitHash($hash) as $val) | |
76 { | |
77 $i = strpos($botCheckOPs, $val); | |
78 if ($i !== FALSE) | |
79 $out .= " ".$botCheckROPs[$i]." "; | |
80 else | |
81 $out .= intHashToValue($val); | |
82 } | |
83 return $out; | |
84 } | |
85 | |
86 | |
87 function hashToAnswer($hash) | |
88 { | |
89 eval("\$res = ".hashToCheckStr($hash).";"); | |
90 return $res; | |
91 } | |
92 | |
138 | 93 // Check if user registration is available |
103
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
94 stCheckRegistrationAvailable(); |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
95 |
0 | 96 // Check if registration is enabled |
97 if (!stChkSetting("allowRegister")) | |
98 { | |
99 ?> | |
100 <h1>Sorry, registration disabled!</h1> | |
101 <p> | |
103
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
102 Registration to the event is not enabled at this time. |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
103 </p> |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
104 <? |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
105 } |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
106 else |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
107 if ($maxAttendeesHard > 0 && $numAttendees >= $maxAttendeesHard) |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
108 { |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
109 ?> |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
110 <h1>Sorry, registration disabled!</h1> |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
111 <p> |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
112 Registration to the event is not available at this time due to |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
113 number of attendees limit having been reached. <b>:(</b> |
0 | 114 </p> |
115 <? | |
116 } | |
117 else | |
118 if ($mode == "start") | |
119 { | |
138 | 120 // |
121 // Show registration form | |
122 // | |
123 // Generate bot-check | |
0 | 124 $botCheckHash = |
125 intValueToHash(rand(1,5)). | |
126 $botCheckOPs[rand(0,2)]. | |
127 intValueToHash(rand(1,5)). | |
128 $botCheckOPs[rand(0,2)]. | |
129 intValueToHash(5 * rand(1,5)); | |
130 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
131 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
132 "<h1>Registration</h1>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
133 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
134 " ".stGetFormHiddenInput("mode", "check")."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
135 " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
136 " <table>\n"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
137 stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
138 stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
139 stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
140 stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner"); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
141 stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
142 //" [".hashToAnswer($botCheckHash)."]". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
143 ")", 20, 20, "botcheck", "autocomplete=\"off\""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
144 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
145 " <tr><td colspan=\"2\"></td><td>".stGetFormSubmitInput("register", "Register")."</td></tr>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
146 " </table>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
147 "</form>\n"; |
0 | 148 |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
149 echo stGetSetting("registerInfoText"); |
0 | 150 } |
151 else | |
152 if ($mode == "check") | |
153 { | |
138 | 154 // |
155 // Check the registrant's details | |
156 // | |
0 | 157 if (stChkDataItem("name") || strlen(stGetRequestItem("name")) < 3) |
158 stError("Handle / name not given, or too short."); | |
159 | |
160 if (stChkDataItem("hash")) | |
161 stError("Invalid data."); | |
162 | |
16 | 163 $email = stGetRequestItem("email"); |
164 if (stGetSetting("requireEMail")) | |
165 { | |
166 if (stChkDataItem("email") || strlen($email) < 4) | |
167 stError("E-mail address not given, or it is too short."); | |
168 } | |
169 | |
48 | 170 if (strlen($email) > 0 && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE)) |
16 | 171 stError("E-mail address not in proper format."); |
172 | |
0 | 173 $hash = stGetRequestItem("hash"); |
174 $answer = stGetRequestItem("botcheck"); | |
175 if (hashToAnswer($hash) != intval($answer)) | |
176 stError("Incorrect answer to I.Q. / bot check."); | |
177 | |
178 if ($errorSet) | |
179 { | |
180 echo "<p>Following errors occured:</p>\n". | |
181 "<ul>\n".$errorMsg."</ul>\n"; | |
182 stPrintFormData("Go back"); | |
183 } | |
184 else | |
185 { | |
186 $sql = stPrepareSQL( | |
187 "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)", | |
188 time(), "name", "groups", "oneliner", "email"); | |
189 | |
190 if (stExecSQL($sql) !== FALSE) | |
191 { | |
16 | 192 echo "<h1>Registration successful</h1>\n". |
193 stGetSetting("registerPostText"); | |
194 | |
0 | 195 if (stChkDataItem("email")) |
16 | 196 echo stGetSetting("registerPostNoEmail"); |
0 | 197 } |
198 else | |
199 { | |
200 echo "<h1>An error occured.</h1>\n"; | |
201 echo "<p>Oh noes! SQL error happenstance!</p>"; | |
202 } | |
203 } | |
204 } | |
205 ?> |