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 if (!fetchUserData(determineReferalId())) {
66 // Not found so we set your refid!
67 setRequestPostElement('refid', getConfig('def_refid'));
68 setSession('refid', getConfig('def_refid'));
71 setRequestPostElement('refid', determineReferalId());
76 // First we only check the submitted data then we continue... :)
78 // Did he agree to our Terms Of Usage?
79 if (postRequestElement('agree') != 'Y') {
80 setRequestPostElement('agree', '!');
84 // Did he enter a valid email address? (we really don't care about
85 // that, he has to click on a confirmation link :P )
86 if ((!isPostRequestElementSet('email')) || (!isEmailValid(postRequestElement('email')))) {
87 setRequestPostElement('email', '!');
91 // And what about surname and family's name?
92 if (!isPostRequestElementSet('surname')) {
93 setRequestPostElement('surname', '!');
96 if (!isPostRequestElementSet('family')) {
97 setRequestPostElement('family', '!');
101 // Get temporary array for modification
102 $postArray = postRequestArray();
104 // Check for required fields
105 if ($isOkay === true) $isOkay = ifRequiredRegisterFieldsAreSet($postArray);
107 // Set it back in request
108 setPostRequestArray($postArray);
110 // Did he enter his password twice?
111 if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
112 if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
113 setRequestPostElement('pass1', '!');
114 setRequestPostElement('pass2', '!');
116 if (!isPostRequestElementSet('pass1')) { setRequestPostElement('pass1', '!'); } else { setRequestPostElement('pass1', ''); }
117 if (!isPostRequestElementSet('pass2')) { setRequestPostElement('pass2', '!'); } else { setRequestPostElement('pass2', ''); }
122 // Is the password long enouth?
123 if ((strlen(postRequestElement('pass1')) < getConfig('pass_len')) && ($isOkay === true)) {
128 // No admin? Admins can always register!
130 // Do this check only when no admin is logged in
131 foreach (postRequestElement('cat') as $id => $answer) {
132 if ($answer == 'Y') $cats++;
135 if ($cats < getConfig('least_cats')) {
141 if ((postRequestElement('email') != '!') && (getConfig('check_double_email') == 'Y')) {
142 // Does the email address already exists in our database?
143 $CHK = isEmailTaken(postRequestElement('email'));
145 setRequestPostElement('email', '?');
150 // Check for IP timeout?
151 if (getConfig('ip_timeout') > 0) {
152 // Check his IP number
153 $result = SQL_QUERY_ESC("SELECT
156 `{?_MYSQL_PREFIX?}_user_data`
158 `REMOTE_ADDR`='%s' AND
159 (`joined` > (UNIX_TIMESTAMP() - {?ip_timeout?}) OR `last_update` > (UNIX_TIMESTAMP() - {?ip_timeout?}))
161 array(detectRemoteAddr()), __FILE__, __LINE__);
162 if (SQL_NUMROWS($result) == 1) {
163 // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
164 // But admins are allowed to fake their own exchange service.
170 SQL_FREERESULT($result);
174 // Is the form sent and all went fine or admin logged in?
175 //* DEBUG: */ print intval(isFormSent()).'/'.intval($isOkay).'/'.intval(isAdmin()).'<br />';
176 if ((isFormSent()) && (($isOkay === true) || (isAdmin()))) {
177 // Prepapre month and day of birth
178 if (strlen(postRequestElement('day')) == 1) setRequestPostElement('day' , 0 . postRequestElement('day'));
179 if (strlen(postRequestElement('month')) == 1) setRequestPostElement('month', 0 . postRequestElement('month'));
182 // ... confirmed, ...
183 $confirmedUsers = countSumTotalData('CONFIRMED' , 'user_data', 'userid', 'status', true);
184 // ... unconfirmed ...
185 $unconfirmedUsers = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
186 // ... and locked users!
187 $lockedUsers = countSumTotalData('LOCKED' , 'user_data', 'userid', 'status', true);
189 // Generate hash which will be inserted into confirmation mail
190 $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')));
192 // Add design when extension sql_patches is v0.2.7 or greater
193 // @TODO Rewrite these all to a single filter
196 if (isExtensionInstalledAndNewer('theme', '0.0.8')) {
197 // Okay, add design here
198 $ADD1 = ', `curr_theme`';
199 $ADD2 = ", '".getCurrentTheme()."'";
202 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
204 // First comes first: begging rallye
205 if (isExtensionInstalledAndNewer('beg', '0.1.7')) {
206 // Okay, shall I disable now?
207 if (getConfig('beg_new_mem_notify') != 'Y') {
208 $ADD1 .= ', `beg_ral_notify`, `beg_ral_en_notify`';
209 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
213 // Second: active rallye
214 if (isExtensionInstalledAndNewer('bonus', '0.7.7')) {
215 // Okay, shall I disable now?
216 if (getConfig('bonus_new_mem_notify') != 'Y') {
217 $ADD1 .= ', `bonus_ral_notify`, `bonus_ral_en_notify`';
218 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
222 // Write user data to table
223 if (isExtensionActive('country')) {
224 // Save with new selectable country code
225 $countryRow = '`country_code`';
226 $countryData = bigintval(postRequestElement('country_code'));
228 // Old way with enterable two-char-code
229 $countryRow = '`country`';
230 $countryData = substr(postRequestElement('cntry'), 0, 2);
233 //////////////////////////////
234 // Create user's account... //
235 //////////////////////////////
237 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.")
238 VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
241 substr(postRequestElement('gender'), 0, 1),
242 postRequestElement('surname'),
243 postRequestElement('family'),
244 postRequestElement('street_nr'),
246 bigintval(postRequestElement('zip')),
247 postRequestElement('city'),
248 postRequestElement('email'),
249 bigintval(postRequestElement('day')),
250 bigintval(postRequestElement('month')),
251 bigintval(postRequestElement('year')),
252 generateHash(postRequestElement('pass1')),
253 bigintval(postRequestElement('max_mails')),
254 bigintval(postRequestElement('max_mails')),
255 bigintval(postRequestElement('refid')),
258 ), __FILE__, __LINE__);
261 $userid = SQL_INSERTID();
264 if ($userid == '0') {
265 // Something bad happened!
266 loadTemplate('admin_settings_saved', false, getMessage('USER_NOT_REGISTERED'));
270 // Is the refback extension there?
271 // @TODO Rewrite this to a filter
272 if (isExtensionActive('refback')) {
273 // Update refback table
274 updateRefbackTable($userid);
277 // Write his welcome-points
278 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`=0 LIMIT 1",
279 array(bigintval($userid)), __FILE__, __LINE__);
280 if (SQL_NUMROWS($result) == '0') {
281 // Add only when the line was not found (maybe some more secure?)
284 // Pay him later. First he has to confirm some mails!
285 if (getConfig('ref_payout') > 0) $locked = 'locked_points';
287 // @TODO Rewrite this to addPointsDirectly()
288 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `".$locked."`) VALUES (%s,0,'{?points_register?}')",
289 array(bigintval($userid)), __FILE__, __LINE__);
291 // Update mediadata as well
292 if ((isExtensionInstalledAndNewer('mediadata', '0.0.4')) && ($locked == 'points')) {
294 updateMediadataEntry(array('total_points'), 'add', getConfig('points_register'));
299 if ((is_array(postRequestElement('cat'))) && (count(postRequestElement('cat')))) {
300 foreach (postRequestElement('cat') as $cat => $joined) {
301 if ($joined == 'Y') {
302 // Insert category entry
303 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES (%s, %s)",
304 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
310 $gender = translateGender(postRequestElement('gender'));
312 // ... rewrite a zero referal id to the main title
313 if (postRequestElement('refid') == '0') setRequestPostElement('refid', getConfig('MAIN_TITLE'));
316 if (isPostRequestElementSet('zip')) {
317 // Prepare data array for the email template
318 // Start with the gender...
323 'surname' => SQL_ESCAPE(postRequestElement('surname')),
324 'family' => SQL_ESCAPE(postRequestElement('family')),
325 'email' => SQL_ESCAPE(postRequestElement('email')),
326 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
327 'city' => SQL_ESCAPE(postRequestElement('city')),
328 'zip' => bigintval(postRequestElement('zip')),
329 'country' => $countryData,
330 'refid' => SQL_ESCAPE(postRequestElement('refid')),
331 'pass' => SQL_ESCAPE(postRequestElement('pass1')),
334 // No ZIP code entered
339 'surname' => SQL_ESCAPE(postRequestElement('surname')),
340 'family' => SQL_ESCAPE(postRequestElement('family')),
341 'email' => SQL_ESCAPE(postRequestElement('email')),
342 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
343 'city' => SQL_ESCAPE(postRequestElement('city')),
345 'country' => $countryData,
346 'refid' => SQL_ESCAPE(postRequestElement('refid')),
347 'pass' => SQL_ESCAPE(postRequestElement('pass1')),
351 // Continue with birthday...
352 switch (getLanguage()) {
354 $content['birthday'] = bigintval(postRequestElement('day')) . '.' . bigintval(postRequestElement('month')) . '.' . bigintval(postRequestElement('year'));
358 $content['birthday'] = bigintval(postRequestElement('month')) . '/' . bigintval(postRequestElement('day')) . '/' . bigintval(postRequestElement('year'));
362 // Display information to the user that he got mail and send it away
363 $messageGuest = loadEmailTemplate('register-member', $content, $userid);
365 // Send mail to user (confirmation link!)
366 $email = $content['email'];
367 sendEmail($content['email'], getMessage('GUEST_SUBJECT_CONFIRM_LINK'), $messageGuest);
368 $content['email'] = $email;
370 // Send mail to admin
371 sendAdminNotification(getMessage('ADMIN_SUBJECT_NEW_ACCOUNT'), 'register-admin', $content, $userid);
373 // Output success registration
374 loadTemplate('admin_settings_saved', false, getMessage('REGISTRATION_DONE'));
376 if (postRequestElement('agree') == '!') {
377 registerOutputFailedMessage('HAVE_TO_AGREE');
380 if (postRequestElement('email') == '!') {
381 registerOutputFailedMessage('ENTER_EMAIL');
382 setRequestPostElement('email', '');
383 } elseif (postRequestElement('email') == '?') {
384 registerOutputFailedMessage('EMAIL_ALREADY_DB');
385 setRequestPostElement('email', '');
388 if (postRequestElement('surname') == '!') {
389 registerOutputFailedMessage('ENTER_SURNAME');
390 setRequestPostElement('surname', '');
393 if (postRequestElement('family') == '!') {
394 registerOutputFailedMessage('ENTER_FAMILY');
395 setRequestPostElement('family', '');
398 if ((postRequestElement('pass1') == '!') && (postRequestElement('pass2') == '!')) {
399 registerOutputFailedMessage('ENTER_BOTH_PASSWORDS');
400 } elseif (postRequestElement('pass1') == '!') {
401 registerOutputFailedMessage('ENTER_PASS1');
402 } elseif (postRequestElement('pass2') == '!') {
403 registerOutputFailedMessage('ENTER_PASS2');
406 if ($shortPass === true) {
407 registerOutputFailedMessage('SHORT_PASS', ': ' . getConfig('pass_len'));
410 if ($ipTimedOut === true) {
411 registerOutputFailedMessage('REMOTE_ADDR_TIMEOUT');
414 if ((!empty($cats)) && ($cats < getConfig('least_cats'))) {
415 registerOutputFailedMessage('', sprintf(getMessage('CATS_LEAST'), getConfig('least_cats')));
418 // Generate birthday selection
419 switch (getLanguage()) {
420 case 'de': // German date format
421 $content['birthday_selection'] = addSelectionBox('day', postRequestElement('day')).addSelectionBox('month', postRequestElement('month')).addSelectionBox('year', postRequestElement('year'));
424 default: // Default is the US date format... :)
425 $content['birthday_selection'] = addSelectionBox('month', postRequestElement('month')).addSelectionBox('day', postRequestElement('day')).addSelectionBox('year', postRequestElement('year'));
429 // Adds a table for the guests with all visible categories
430 $content['category_selection'] = registerGenerateCategoryTable('guest', true);
432 // Adds maximum receiveable mails list... :)
433 $content['max_receive_list'] = addMaxReceiveList('guest', '', true);
435 // Shall I display the refid or shall I make it editable?
436 if (getConfig('display_refid') == 'Y') {
437 // Load "hide" form template
438 $content['refid_content'] = loadTemplate('guest_register_refid_hide', true, determineReferalId());
440 // Load template to enter it
441 $content['refid_content'] = loadTemplate('guest_register_refid', true, determineReferalId());
444 // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
445 $content['header_content'] = loadTemplate('register_header', true);
448 $content['surname'] = SQL_ESCAPE(postRequestElement('surname'));
449 $content['family'] = SQL_ESCAPE(postRequestElement('family'));
450 $content['street_nr'] = SQL_ESCAPE(postRequestElement('street_nr'));
451 $content['zip'] = '';
452 if (isPostRequestElementSet('zip')) {
453 $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);