Mercurial > hg > fapweb
annotate register.inc.php @ 103:c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
hard and soft limit completely.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 21 Oct 2013 14:52:06 +0300 |
parents | 1fccb8f031ed |
children | aeebfedb5709 |
rev | line source |
---|---|
0 | 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 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
12 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
13 " ".stGetFormSubmitInput("continue", $button)."\n"; |
0 | 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 | |
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
|
84 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
|
85 |
0 | 86 // Check if registration is enabled |
87 if (!stChkSetting("allowRegister")) | |
88 { | |
89 ?> | |
90 <h1>Sorry, registration disabled!</h1> | |
91 <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
|
92 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
|
93 </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
|
94 <? |
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 } |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
96 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
|
97 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
|
98 { |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
99 ?> |
c6b9041078ec
Add hard limit option for attendees, and add feature of using "0" to disable
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
100 <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
|
101 <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
|
102 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
|
103 number of attendees limit having been reached. <b>:(</b> |
0 | 104 </p> |
105 <? | |
106 } | |
107 else | |
108 if ($mode == "start") | |
109 { | |
110 $botCheckHash = | |
111 intValueToHash(rand(1,5)). | |
112 $botCheckOPs[rand(0,2)]. | |
113 intValueToHash(rand(1,5)). | |
114 $botCheckOPs[rand(0,2)]. | |
115 intValueToHash(5 * rand(1,5)); | |
116 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
117 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
118 "<h1>Registration</h1>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
119 stGetFormStart("register"). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
120 " ".stGetFormHiddenInput("mode", "check")."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
121 " ".stGetFormHiddenInput("hash", $botCheckHash)."\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
122 " <table>\n"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 //" [".hashToAnswer($botCheckHash)."]". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
129 ")", 20, 20, "botcheck", "autocomplete=\"off\""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
130 echo |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
131 " <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
|
132 " </table>\n". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
133 "</form>\n"; |
0 | 134 |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
135 echo stGetSetting("registerInfoText"); |
0 | 136 } |
137 else | |
138 if ($mode == "check") | |
139 { | |
140 if (stChkDataItem("name") || strlen(stGetRequestItem("name")) < 3) | |
141 stError("Handle / name not given, or too short."); | |
142 | |
143 if (stChkDataItem("hash")) | |
144 stError("Invalid data."); | |
145 | |
16 | 146 $email = stGetRequestItem("email"); |
147 if (stGetSetting("requireEMail")) | |
148 { | |
149 if (stChkDataItem("email") || strlen($email) < 4) | |
150 stError("E-mail address not given, or it is too short."); | |
151 } | |
152 | |
48 | 153 if (strlen($email) > 0 && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE)) |
16 | 154 stError("E-mail address not in proper format."); |
155 | |
0 | 156 $hash = stGetRequestItem("hash"); |
157 $answer = stGetRequestItem("botcheck"); | |
158 if (hashToAnswer($hash) != intval($answer)) | |
159 stError("Incorrect answer to I.Q. / bot check."); | |
160 | |
161 if ($errorSet) | |
162 { | |
163 echo "<p>Following errors occured:</p>\n". | |
164 "<ul>\n".$errorMsg."</ul>\n"; | |
165 stPrintFormData("Go back"); | |
166 } | |
167 else | |
168 { | |
169 $sql = stPrepareSQL( | |
170 "INSERT INTO attendees (regtime,name,groups,oneliner,email) VALUES (%d,%S,%S,%S,%S)", | |
171 time(), "name", "groups", "oneliner", "email"); | |
172 | |
173 if (stExecSQL($sql) !== FALSE) | |
174 { | |
16 | 175 echo "<h1>Registration successful</h1>\n". |
176 stGetSetting("registerPostText"); | |
177 | |
0 | 178 if (stChkDataItem("email")) |
16 | 179 echo stGetSetting("registerPostNoEmail"); |
0 | 180 } |
181 else | |
182 { | |
183 echo "<h1>An error occured.</h1>\n"; | |
184 echo "<p>Oh noes! SQL error happenstance!</p>"; | |
185 } | |
186 } | |
187 } | |
188 ?> |