2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/10/2003 *
4 * =============== Last change: 11/26/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-register.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Registration form *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Anmeldeformular *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Add description as navigation point
45 addMenuDescription('guest', __FILE__);
47 if (!isExtensionActive('register')) {
48 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('register'));
50 } elseif (!isExtensionActive('country')) {
51 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('country'));
55 // Initialize variables
61 // Default refid is zero
62 setRequestPostElement('refid', 0);
63 if (determineReferalId() > 0) {
64 // Test if the refid is valid
65 $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
66 array(determineReferalId()), __FILE__, __LINE__);
69 //* DEBUG: */ die("refid={determineReferalId()}/numRows=".SQL_NUMROWS($result)."");
70 if (SQL_NUMROWS($result) == 0) {
71 // Not found so we set your refid!
72 setRequestPostElement('refid', getConfig('def_refid'));
73 setSession('refid', getConfig('def_refid'));
76 setRequestPostElement('refid', determineReferalId());
81 // First we only check the submitted data then we continue... :)
83 // Did he agree to our Terms Of Usage?
84 if (postRequestElement('agree') != 'Y') {
85 setRequestPostElement('agree', '!');
89 // Did he enter a valid email address? (we really don't care about
90 // that, he has to click on a confirmation link :P )
91 if ((!isPostRequestElementSet('email')) || (!isEmailValid(postRequestElement('email')))) {
92 setRequestPostElement('email', '!');
96 // And what about surname and family's name?
97 if (!isPostRequestElementSet('surname')) {
98 setRequestPostElement('surname', '!');
101 if (!isPostRequestElementSet('family')) {
102 setRequestPostElement('family', '!');
106 // Get temporary array for modification
107 $postArray = postRequestArray();
109 // Check for required fields
110 if ($isFailed === false) $isFailed = ifRequiredRegisterFieldsAreSet($postArray);
112 // Set it back in request
113 setPostRequestArray($postArray);
115 // Did he enter his password twice?
116 if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
117 if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
118 setRequestPostElement('pass1', '!');
119 setRequestPostElement('pass2', '!');
121 if (!isPostRequestElementSet('pass1')) { setRequestPostElement('pass1', '!'); } else { setRequestPostElement('pass1', ''); }
122 if (!isPostRequestElementSet('pass2')) { setRequestPostElement('pass2', '!'); } else { setRequestPostElement('pass2', ''); }
127 // Is the password long enouth?
128 if ((strlen(postRequestElement('pass1')) < getConfig('pass_len')) && ($isFailed === false)) {
133 // No admin? Admins can always register!
135 // Do this check only when no admin is logged in
136 foreach (postRequestElement('cat') as $id => $answer) {
137 if ($answer == 'Y') $cats++;
140 if ($cats < getConfig('least_cats')) {
146 if ((postRequestElement('email') != '!') && (getConfig('check_double_email') == 'Y')) {
147 // Does the email address already exists in our database?
148 $CHK = isEmailTaken(postRequestElement('email'));
150 setRequestPostElement('email', '?');
155 // Check for IP timeout?
156 if (getConfig('ip_timeout') > 0) {
157 // Check his IP number
158 $result = SQL_QUERY_ESC("SELECT
161 `{?_MYSQL_PREFIX?}_user_data`
163 `REMOTE_ADDR`='%s' AND
164 (`joined` > (UNIX_TIMESTAMP() - {?ip_timeout?}) OR `last_update` > (UNIX_TIMESTAMP() - {?ip_timeout?}))
166 array(detectRemoteAddr()), __FILE__, __LINE__);
167 if (SQL_NUMROWS($result) == 1) {
168 // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
169 // But admins are allowed to fake their own exchange service.
176 SQL_FREERESULT($result);
179 if ((isFormSent()) && (($isFailed === false) || (isAdmin()))) {
180 // Prepapre month and day of birth
181 if (strlen(postRequestElement('day')) == 1) setRequestPostElement('day' , '0'.postRequestElement('day'));
182 if (strlen(postRequestElement('month')) == 1) setRequestPostElement('month', '0'.postRequestElement('month'));
185 // ... confirmed, ...
186 $confirmedUsers = countSumTotalData('CONFIRMED' , 'user_data', 'userid', 'status', true);
187 // ... unconfirmed ...
188 $unconfirmedUsers = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
189 // ... and locked users!
190 $lockedUsers = countSumTotalData('LOCKED' , 'user_data', 'userid', 'status', true);
192 // Generate hash which will be inserted into confirmation mail
193 $hash = generateHash(sha1($confirmedUsers.getConfig('ENCRYPT_SEPERATOR').$unconfirmedUsers.getConfig('ENCRYPT_SEPERATOR').$lockedUsers.getConfig('ENCRYPT_SEPERATOR').postRequestElement('month') . '-'.postRequestElement('day') . '-'.postRequestElement('year').getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_NAME').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr().getConfig('ENCRYPT_SEPERATOR').detectUserAgent() . '/' . getConfig('SITE_KEY') . '/' . getConfig('DATE_KEY') . '/'. getConfig('CACHE_BUSTER')));
195 // Add design when extension sql_patches is v0.2.7 or greater
196 // @TODO Rewrite these all to a single filter
199 if (getExtensionVersion('theme') >= '0.0.8') {
200 // Okay, add design here
201 $ADD1 = ', `curr_theme`';
202 $ADD2 = ", '".getCurrentTheme()."'";
205 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
207 // First comes first: begging rallye
208 if (getExtensionVersion('beg') >= '0.1.7') {
209 // Okay, shall I disable now?
210 if (getConfig('beg_new_mem_notify') != 'Y') {
211 $ADD1 .= ', `beg_ral_notify`, `beg_ral_en_notify`';
212 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
216 // Second: active rallye
217 if (getExtensionVersion('bonus') >= '0.7.7') {
218 // Okay, shall I disable now?
219 if (getConfig('bonus_new_mem_notify') != 'Y') {
220 $ADD1 .= ', `bonus_ral_notify`, `bonus_ral_en_notify`';
221 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
225 // Write user data to table
226 if (isExtensionActive('country')) {
227 // Save with new selectable country code
228 $countryRow = '`country_code`';
229 $countryData = bigintval(postRequestElement('country_code'));
231 // Old way with enterable two-char-code
232 $countryRow = '`country`';
233 $countryData = substr(postRequestElement('cntry'), 0, 2);
236 //////////////////////////////
237 // Create user's account... //
238 //////////////////////////////
240 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_data` (gender, surname, family, street_nr,%s, zip, city, email, birth_day, birth_month, birth_year, password, max_mails, receive_mails, refid, status, user_hash, REMOTE_ADDR, joined, last_update".$ADD1.")
241 VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
244 substr(postRequestElement('gender'), 0, 1),
245 postRequestElement('surname'),
246 postRequestElement('family'),
247 postRequestElement('street_nr'),
249 bigintval(postRequestElement('zip')),
250 postRequestElement('city'),
251 postRequestElement('email'),
252 bigintval(postRequestElement('day')),
253 bigintval(postRequestElement('month')),
254 bigintval(postRequestElement('year')),
255 generateHash(postRequestElement('pass1')),
256 bigintval(postRequestElement('max_mails')),
257 bigintval(postRequestElement('max_mails')),
258 bigintval(postRequestElement('refid')),
261 ), __FILE__, __LINE__);
264 $userid = SQL_INSERTID();
268 // Something bad happened!
269 loadTemplate('admin_settings_saved', false, getMessage('USER_NOT_REGISTERED'));
273 // Is the refback extension there?
274 // @TODO Rewrite this to a filter
275 if (isExtensionActive('refback')) {
276 // Update refback table
277 updateRefbackTable($userid);
280 // Write his welcome-points
281 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`=0 LIMIT 1",
282 array(bigintval($userid)), __FILE__, __LINE__);
283 if (SQL_NUMROWS($result) == 0) {
284 // Add only when the line was not found (maybe some more secure?)
287 // Pay him later. First he has to confirm some mails!
288 if (getConfig('ref_payout') > 0) $locked = 'locked_points';
290 // @TODO Rewrite this to addPointsDirectly()
291 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `".$locked."`) VALUES (%s,0,'%s')",
292 array(bigintval($userid), getConfig('points_register')), __FILE__, __LINE__);
294 // Update mediadata as well
295 if ((getExtensionVersion('mediadata') >= '0.0.4') && ($locked == 'points')) {
297 updateMediadataEntry(array('total_points'), 'add', getConfig('points_register'));
302 if ((is_array(postRequestElement('cat'))) && (count(postRequestElement('cat')))) {
303 foreach (postRequestElement('cat') as $cat => $joined) {
304 if ($joined == 'Y') {
305 // Insert category entry
306 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES (%s, %s)",
307 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
313 $gender = translateGender(postRequestElement('gender'));
315 // ... rewrite a zero referal ID to the main title
316 if (postRequestElement('refid') == '0') setRequestPostElement('refid', getConfig('MAIN_TITLE'));
319 if (isPostRequestElementSet('zip')) {
320 // Prepare data array for the email template
321 // Start with the gender...
326 'surname' => SQL_ESCAPE(postRequestElement('surname')),
327 'family' => SQL_ESCAPE(postRequestElement('family')),
328 'email' => SQL_ESCAPE(postRequestElement('email')),
329 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
330 'city' => SQL_ESCAPE(postRequestElement('city')),
331 'zip' => bigintval(postRequestElement('zip')),
332 'country' => $countryData,
333 'refid' => SQL_ESCAPE(postRequestElement('refid')),
334 'pass' => SQL_ESCAPE(postRequestElement('pass1')),
337 // No ZIP code entered
342 'surname' => SQL_ESCAPE(postRequestElement('surname')),
343 'family' => SQL_ESCAPE(postRequestElement('family')),
344 'email' => SQL_ESCAPE(postRequestElement('email')),
345 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
346 'city' => SQL_ESCAPE(postRequestElement('city')),
348 'country' => $countryData,
349 'refid' => SQL_ESCAPE(postRequestElement('refid')),
350 'pass' => SQL_ESCAPE(postRequestElement('pass1')),
354 // Continue with birthday...
355 switch (getLanguage()) {
357 $content['birthday'] = bigintval(postRequestElement('day')) . '.' . bigintval(postRequestElement('month')) . '.' . bigintval(postRequestElement('year'));
361 $content['birthday'] = bigintval(postRequestElement('month')) . '/' . bigintval(postRequestElement('day')) . '/' . bigintval(postRequestElement('year'));
365 // Display information to the user that he got mail and send it away
366 $messageGuest = loadEmailTemplate('register-member', $content, $userid);
368 // Send mail to user (confirmation link!)
369 $email = $content['email'];
370 sendEmail($content['email'], getMessage('GUEST_SUBJECT_CONFIRM_LINK'), $messageGuest);
371 $content['email'] = $email;
373 // Send mail to admin
374 sendAdminNotification(getMessage('ADMIN_SUBJECT_NEW_ACCOUNT'), 'register-admin', $content, $userid);
376 // Output success registration
377 loadTemplate('admin_settings_saved', false, getMessage('REGISTRATION_DONE'));
379 if (postRequestElement('agree') == '!') {
380 registerOutputFailedMessage('HAVE_TO_AGREE');
383 if (postRequestElement('email') == '!') {
384 registerOutputFailedMessage('ENTER_EMAIL');
385 setRequestPostElement('email', '');
386 } elseif (postRequestElement('email') == '?') {
387 registerOutputFailedMessage('EMAIL_ALREADY_DB');
388 setRequestPostElement('email', '');
391 if (postRequestElement('surname') == '!') {
392 registerOutputFailedMessage('ENTER_SURNAME');
393 setRequestPostElement('surname', '');
396 if (postRequestElement('family') == '!') {
397 registerOutputFailedMessage('ENTER_FAMILY');
398 setRequestPostElement('family', '');
401 if ((postRequestElement('pass1') == '!') && (postRequestElement('pass2') == '!')) {
402 registerOutputFailedMessage('ENTER_BOTH_PASSWORDS');
403 } elseif (postRequestElement('pass1') == '!') {
404 registerOutputFailedMessage('ENTER_PASS1');
405 } elseif (postRequestElement('pass2') == '!') {
406 registerOutputFailedMessage('ENTER_PASS2');
409 if ($shortPass === true) {
410 registerOutputFailedMessage('SHORT_PASS', ": ".getConfig('pass_len'));
413 if ($ipTimedOut === true) {
414 registerOutputFailedMessage('REMOTE_ADDR_TIMEOUT');
417 if ((!empty($cats)) && ($cats < getConfig('least_cats'))) {
418 registerOutputFailedMessage(sprintf(getMessage('CATS_LEAST'), getConfig('least_cats')));
421 // Generate birthday selection
422 switch (getLanguage()) {
423 case 'de': // German date format
424 $content['birthday_selection'] = addSelectionBox('day', postRequestElement('day')).addSelectionBox('month', postRequestElement('month')).addSelectionBox('year', postRequestElement('year'));
427 default: // Default is the US date format... :)
428 $content['birthday_selection'] = addSelectionBox('month', postRequestElement('month')).addSelectionBox('day', postRequestElement('day')).addSelectionBox('year', postRequestElement('year'));
432 // Adds a table for the guests with all visible categories
433 $content['category_selection'] = registerGenerateCategoryTable('guest', true);
435 // Adds maximum receiveable mails list... :)
436 $content['max_receive_list'] = addMaxReceiveList('guest', '', true);
438 // Shall I display the refid or shall I make it editable?
439 if (getConfig('display_refid') == 'Y') {
440 // Load "hide" form template
441 $content['refid_content'] = loadTemplate('guest_register_refid_hide', true, determineReferalId());
443 // Load template to enter it
444 $content['refid_content'] = loadTemplate('guest_register_refid', true, determineReferalId());
447 // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
448 $content['header_content'] = loadTemplate('register_header', true);
451 $content['surname'] = SQL_ESCAPE(postRequestElement('surname'));
452 $content['family'] = SQL_ESCAPE(postRequestElement('family'));
453 $content['street_nr'] = SQL_ESCAPE(postRequestElement('street_nr'));
454 $content['zip'] = bigintval(postRequestElement('zip'));
455 $content['city'] = SQL_ESCAPE(postRequestElement('city'));
456 $content['email'] = SQL_ESCAPE(postRequestElement('email'));
458 // Prepare country selection box
459 $OUT = "<select name=\"country_code\" class=\"guest_select\" size=\"1\">\n";
460 $whereStatement = "WHERE `is_active`='Y'";
461 if (isAdmin()) $whereStatement = '';
462 $OUT .= generateOptionList('countries', 'id', 'descr', postRequestElement('country_code'), 'code', $whereStatement);
464 $content['country'] = $OUT;
466 // Set must-fillout fields
467 $content = runFilterChain('register_must_fillout', $content);
469 // Display registration form
470 loadTemplate('guest_register', false, $content);