Mercurial > hg > fapweb
annotate pages/register.inc.php @ 1011:b7916209da83
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Nov 2015 22:11:21 +0200 |
parents | b3f579c33b08 |
children | fd957c37fd80 |
rev | line source |
---|---|
0 | 1 <? |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
2 // |
571
ce11ea112a65
Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
3 // FAPWeb - Simple Web-based Demoparty Management System |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
4 // Attendee registration page |
1001 | 5 // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) |
136
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 | |
1011 | 14 $registerFormFields = |
15 [ | |
16 "name" => "Name", | |
17 "groups" => "Group(s)", | |
18 "email" => "E-mail", | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
19 "oneliner" => "Oneliner", |
1011 | 20 "hash" => FALSE, |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
21 "botcheck" => FALSE, |
1011 | 22 ]; |
0 | 23 |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
24 |
734
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
25 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
26 { |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
27 echo " <tr><th>".chentities($text1)."</th><td>". |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
28 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
29 "</td><td>".chentities($text2)."</td></tr>\n"; |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
30 } |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
31 |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
32 |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
33 function stPrintFormHiddenInput($name, $value) |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
34 { |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
35 echo " ".stGetFormHiddenInput($name, $value)."\n"; |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
36 } |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
37 |
26a168d3390f
Move functions into a more appropriate file.
Matti Hamalainen <ccr@tnsp.org>
parents:
716
diff
changeset
|
38 |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
39 function stPrintFormData($button, $mode = "start", $exclude = array()) |
0 | 40 { |
1011 | 41 global $registerFormFields; |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
42 |
0 | 43 echo |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
734
diff
changeset
|
44 stGetFormStart("register", "register"). |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
45 " ".stGetFormSubmitInput("continue", $button)."\n"; |
0 | 46 |
47 stPrintFormHiddenInput("mode", $mode); | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
48 |
1011 | 49 foreach ($registerFormFields as $name => $title) |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
50 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
51 if (!in_array($name, $exclude)) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
52 stPrintFormHiddenInput($name, stGetRequestItem($name)); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
53 } |
0 | 54 |
55 echo "</form>\n"; | |
56 } | |
57 | |
58 | |
138 | 59 // Convert integer value to hash code |
0 | 60 function intValueToHash($val) |
61 { | |
62 global $botCheckIDs; | |
63 $str = ""; | |
64 do | |
65 { | |
66 $str = $botCheckIDs[$val & 31].$str; | |
67 $val >>= 5; | |
68 } | |
69 while ($val > 0); | |
70 return $str; | |
71 } | |
72 | |
73 | |
138 | 74 // Convert integer hash to integer value |
0 | 75 function intHashToValue($hash) |
76 { | |
77 global $botCheckIDs; | |
78 for ($val = 0, $i = 0; $i < strlen($hash); $i++) | |
79 { | |
80 $val *= 32; | |
81 $n = strpos($botCheckIDs, $hash[$i]); | |
82 if ($n !== FALSE) | |
83 $val += $n; | |
84 else | |
85 return -2; | |
86 } | |
87 return $val; | |
88 } | |
89 | |
90 | |
138 | 91 // Split hash into parts |
0 | 92 function splitHash($hash) |
93 { | |
94 global $botCheckOPs; | |
95 return preg_split("/([".$botCheckOPs."])/", $hash, -1, PREG_SPLIT_DELIM_CAPTURE); | |
96 } | |
97 | |
98 | |
99 function hashToCheckStr($hash) | |
100 { | |
101 global $botCheckOPs, $botCheckROPs; | |
102 $out = ""; | |
103 | |
104 foreach (splitHash($hash) as $val) | |
105 { | |
106 $i = strpos($botCheckOPs, $val); | |
107 if ($i !== FALSE) | |
108 $out .= " ".$botCheckROPs[$i]." "; | |
109 else | |
110 $out .= intHashToValue($val); | |
111 } | |
112 return $out; | |
113 } | |
114 | |
115 | |
116 function hashToAnswer($hash) | |
117 { | |
118 eval("\$res = ".hashToCheckStr($hash).";"); | |
119 return $res; | |
120 } | |
121 | |
1010 | 122 |
138 | 123 // 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
|
124 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
|
125 |
1010 | 126 |
0 | 127 // Check if registration is enabled |
128 if (!stChkSetting("allowRegister")) | |
129 { | |
182
e227e6a3d46b
Move some texts to settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
130 echo stGetSetting("registerNotEnabled"); |
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
|
131 } |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
132 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
|
133 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
|
134 { |
182
e227e6a3d46b
Move some texts to settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
135 echo stGetSetting("registerLimitExceeded"); |
0 | 136 } |
137 else | |
138 if ($mode == "start") | |
139 { | |
138 | 140 // |
141 // Show registration form | |
142 // | |
143 // Generate bot-check | |
0 | 144 $botCheckHash = |
145 intValueToHash(rand(1,5)). | |
146 $botCheckOPs[rand(0,2)]. | |
147 intValueToHash(rand(1,5)). | |
148 $botCheckOPs[rand(0,2)]. | |
149 intValueToHash(5 * rand(1,5)); | |
150 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
151 echo |
659
1702a5e0b9c3
Add new settings for certain HTML pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
656
diff
changeset
|
152 stGetSetting("registerPageBlurb"). |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
734
diff
changeset
|
153 stGetFormStart("register", "register"). |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
154 " ".stGetFormHiddenInput("mode", "check")."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
155 " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
156 " <table class=\"register\">\n"; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
157 stPrintFormTextInput("Handle:", "(elite)", 20, SET_LEN_USERNAME, "name"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
158 stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 30, SET_LEN_GROUPS, "groups"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
159 stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 30, SET_LEN_EMAIL, "email"); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
160 stPrintFormTextInput("Oneliner:", "(whatever)", 30, SET_LEN_ONELINER, "oneliner"); |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
161 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
|
162 //" [".hashToAnswer($botCheckHash)."]". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
163 ")", 20, 20, "botcheck", "autocomplete=\"off\""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
164 echo |
195 | 165 " <tr><td colspan=\"2\"></td><td>".stGetFormSubmitInput("register", "Continue")."</td></tr>\n". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
166 " </table>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
167 "</form>\n"; |
0 | 168 |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
169 echo stGetSetting("registerInfoText"); |
0 | 170 } |
171 else | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
172 if ($mode == "check" || $mode == "register") |
0 | 173 { |
138 | 174 // |
175 // Check the registrant's details | |
176 // | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
177 stChkRequestItem("hash", $hash, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
178 array(CHK_GTEQ, VT_STR, 0, "Invalid data.")); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
179 |
646
2eeca16e9c96
Improve attendee adding/updating data validation.
Matti Hamalainen <ccr@tnsp.org>
parents:
594
diff
changeset
|
180 stValidateRequestUserData(FALSE, FALSE); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
181 |
0 | 182 $answer = stGetRequestItem("botcheck"); |
183 if (hashToAnswer($hash) != intval($answer)) | |
184 stError("Incorrect answer to I.Q. / bot check."); | |
185 | |
186 if ($errorSet) | |
187 { | |
1010 | 188 // There were errors or missing data |
183 | 189 echo |
714
014244a01d17
Use header tag instead of para.
Matti Hamalainen <ccr@tnsp.org>
parents:
659
diff
changeset
|
190 "<h1>Following errors occured:</h1>\n". |
210 | 191 "<ul>\n"; |
192 | |
193 foreach ($errorMsgs as $msg) | |
194 echo " <li>".$msg."</li>\n"; | |
195 | |
196 echo "</ul>\n"; | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
197 stPrintFormData("Go back", "start", array("botcheck")); |
0 | 198 } |
199 else | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
200 if ($mode == "register") |
0 | 201 { |
1010 | 202 // Data ok, registration mode |
716 | 203 $sql = stGetAttendeeRegistrationSQL(); |
0 | 204 if (stExecSQL($sql) !== FALSE) |
205 { | |
183 | 206 echo stGetSetting("registerPostText"); |
16 | 207 |
594 | 208 if (strlen(stGetRequestItem("email")) < 4) |
16 | 209 echo stGetSetting("registerPostNoEmail"); |
0 | 210 } |
211 else | |
212 { | |
183 | 213 echo |
214 "<h1>An error occured.</h1>\n". | |
215 "<p>Oh noes! SQL error happenstance!</p>"; | |
0 | 216 } |
217 } | |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
218 else |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
219 { |
1010 | 220 // Data ok, verify |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
221 echo |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
222 "<h1>Verify your information</h1>\n". |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
223 "<p>Is the following information correct?</p>\n". |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
224 "<table class=\"register\">\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
225 |
1011 | 226 foreach ($registerFormFields as $name => $title) |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
227 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
228 if ($title !== FALSE) |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
229 { |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
230 echo |
656
c6df2ea4d5bf
Use <th>-element instead of <td>.
Matti Hamalainen <ccr@tnsp.org>
parents:
646
diff
changeset
|
231 " <tr><th class=\"".$name."\">".chentities($title).":</th>". |
191
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
232 "<td>".chentities(stGetRequestItem($name))."</td></tr>\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
233 } |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
234 } |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
235 echo "</table>\n"; |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
236 |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
237 stPrintFormData("Go back", "start", array("botcheck")); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
238 stPrintFormData("Register", "register"); |
988e0ab2b77e
Improve registration process by adding information verification phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
239 } |
0 | 240 } |
241 ?> |