2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 setPostRequestParameter('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 setPostRequestParameter('refid', getConfig('def_refid'));
68 setSession('refid', getConfig('def_refid'));
71 setPostRequestParameter('refid', determineReferalId());
76 // First we only check the submitted data then we continue... :)
78 // Did he agree to our Terms Of Usage?
79 if (postRequestParameter('agree') != 'Y') {
80 setPostRequestParameter('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 ((!isPostRequestParameterSet('email')) || (!isEmailValid(postRequestParameter('email')))) {
87 setPostRequestParameter('email', '!');
91 // And what about surname and family's name?
92 if (!isPostRequestParameterSet('surname')) {
93 setPostRequestParameter('surname', '!');
96 if (!isPostRequestParameterSet('family')) {
97 setPostRequestParameter('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 (((!isPostRequestParameterSet('pass1')) || (!isPostRequestParameterSet('pass2'))) || ((postRequestParameter('pass1') != postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2')))) {
112 if ((postRequestParameter('pass1') != postRequestParameter('pass2')) && (isPostRequestParameterSet('pass1')) && (isPostRequestParameterSet('pass2'))) {
113 setPostRequestParameter('pass1', '!');
114 setPostRequestParameter('pass2', '!');
116 if (!isPostRequestParameterSet('pass1')) { setPostRequestParameter('pass1', '!'); } else { setPostRequestParameter('pass1', ''); }
117 if (!isPostRequestParameterSet('pass2')) { setPostRequestParameter('pass2', '!'); } else { setPostRequestParameter('pass2', ''); }
122 // Is the password long enouth?
123 if ((strlen(postRequestParameter('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 (postRequestParameter('cat') as $id => $answer) {
132 if ($answer == 'Y') $cats++;
135 if ($cats < getConfig('least_cats')) {
141 if ((postRequestParameter('email') != '!') && (getConfig('check_double_email') == 'Y')) {
142 // Does the email address already exists in our database?
143 if ((!isAdmin()) && (isEmailTaken(postRequestParameter('email')))) {
144 setPostRequestParameter('email', '?');
149 // Check for IP timeout?
150 if (getConfig('ip_timeout') > 0) {
151 // Check his IP number
152 $result = SQL_QUERY_ESC("SELECT
155 `{?_MYSQL_PREFIX?}_user_data`
157 `REMOTE_ADDR`='%s' AND
158 (`joined` > (UNIX_TIMESTAMP() - {?ip_timeout?}) OR `last_update` > (UNIX_TIMESTAMP() - {?ip_timeout?}))
160 array(detectRemoteAddr()), __FILE__, __LINE__);
161 if (SQL_NUMROWS($result) == 1) {
162 // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
163 // But admins are allowed to fake their own exchange service.
169 SQL_FREERESULT($result);
173 // Is the form sent and all went fine or admin logged in?
174 //* DEBUG: */ print intval(isFormSent()).'/'.intval($isOkay).'/'.intval(isAdmin()).'<br />';
175 if ((isFormSent()) && (($isOkay === true) || (isAdmin()))) {
176 // Prepapre month and day of birth
177 if (strlen(postRequestParameter('day')) == 1) setPostRequestParameter('day' , 0 . postRequestParameter('day'));
178 if (strlen(postRequestParameter('month')) == 1) setPostRequestParameter('month', 0 . postRequestParameter('month'));
181 // ... confirmed, ...
182 $confirmedUsers = countSumTotalData('CONFIRMED' , 'user_data', 'userid', 'status', true);
183 // ... unconfirmed ...
184 $unconfirmedUsers = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true);
185 // ... and locked users!
186 $lockedUsers = countSumTotalData('LOCKED' , 'user_data', 'userid', 'status', true);
188 // Generate hash which will be inserted into confirmation mail
189 $hash = generateHash(sha1($confirmedUsers.getConfig('ENCRYPT_SEPERATOR').$unconfirmedUsers.getConfig('ENCRYPT_SEPERATOR').$lockedUsers.getConfig('ENCRYPT_SEPERATOR').postRequestParameter('month') . '-'.postRequestParameter('day') . '-'.postRequestParameter('year').getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_NAME').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr().getConfig('ENCRYPT_SEPERATOR').detectUserAgent() . '/' . getConfig('SITE_KEY') . '/' . getConfig('DATE_KEY') . '/'. getConfig('CACHE_BUSTER')));
191 // Add design when extension sql_patches is v0.2.7 or greater
192 // @TODO Rewrite these all to a single filter
195 if (isExtensionInstalledAndNewer('theme', '0.0.8')) {
196 // Okay, add design here
197 $ADD1 = ', `curr_theme`';
198 $ADD2 = ", '".getCurrentTheme()."'";
201 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
203 // First comes first: begging rallye
204 if (isExtensionInstalledAndNewer('beg', '0.1.7')) {
205 // Okay, shall I disable now?
206 if (getConfig('beg_new_mem_notify') != 'Y') {
207 $ADD1 .= ', `beg_ral_notify`, `beg_ral_en_notify`';
208 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
212 // Second: active rallye
213 if (isExtensionInstalledAndNewer('bonus', '0.7.7')) {
214 // Okay, shall I disable now?
215 if (getConfig('bonus_new_mem_notify') != 'Y') {
216 $ADD1 .= ', `bonus_ral_notify`, `bonus_ral_en_notify`';
217 $ADD2 .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
221 // Write user data to table
222 if (isExtensionActive('country')) {
223 // Save with new selectable country code
224 $countryRow = '`country_code`';
225 $countryData = bigintval(postRequestParameter('country_code'));
227 // Old way with enterable two-char-code
228 $countryRow = '`country`';
229 $countryData = substr(postRequestParameter('cntry'), 0, 2);
232 //////////////////////////////
233 // Create user's account... //
234 //////////////////////////////
236 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.")
237 VALUES ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()".$ADD2.")",
240 substr(postRequestParameter('gender'), 0, 1),
241 postRequestParameter('surname'),
242 postRequestParameter('family'),
243 postRequestParameter('street_nr'),
245 bigintval(postRequestParameter('zip')),
246 postRequestParameter('city'),
247 postRequestParameter('email'),
248 bigintval(postRequestParameter('day')),
249 bigintval(postRequestParameter('month')),
250 bigintval(postRequestParameter('year')),
251 generateHash(postRequestParameter('pass1')),
252 bigintval(postRequestParameter('max_mails')),
253 bigintval(postRequestParameter('max_mails')),
254 bigintval(postRequestParameter('refid')),
257 ), __FILE__, __LINE__);
260 $userid = SQL_INSERTID();
263 if ($userid == '0') {
264 // Something bad happened!
265 loadTemplate('admin_settings_saved', false, getMessage('USER_NOT_REGISTERED'));
269 // Is the refback extension there?
270 // @TODO Rewrite this to a filter
271 if (isExtensionActive('refback')) {
272 // Update refback table
273 updateRefbackTable($userid);
276 // Write his welcome-points
277 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`=0 LIMIT 1",
278 array(bigintval($userid)), __FILE__, __LINE__);
279 if (SQL_NUMROWS($result) == '0') {
280 // Add only when the line was not found (maybe some more secure?)
283 // Pay him later. First he has to confirm some mails!
284 if (getConfig('ref_payout') > 0) $locked = 'locked_points';
286 // @TODO Rewrite this to addPointsDirectly()
287 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`, `ref_depth`, `".$locked."`) VALUES (%s,0,'{?points_register?}')",
288 array(bigintval($userid)), __FILE__, __LINE__);
290 // Update mediadata as well
291 if ((isExtensionInstalledAndNewer('mediadata', '0.0.4')) && ($locked == 'points')) {
293 updateMediadataEntry(array('total_points'), 'add', getConfig('points_register'));
298 if ((is_array(postRequestParameter('cat'))) && (count(postRequestParameter('cat')))) {
299 foreach (postRequestParameter('cat') as $cat => $joined) {
300 if ($joined == 'Y') {
301 // Insert category entry
302 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES (%s, %s)",
303 array(bigintval($userid), bigintval($cat)), __FILE__, __LINE__);
309 $gender = translateGender(postRequestParameter('gender'));
311 // ... rewrite a zero referal id to the main title
312 if (postRequestParameter('refid') == '0') setPostRequestParameter('refid', getConfig('MAIN_TITLE'));
315 if (isPostRequestParameterSet('zip')) {
316 // Prepare data array for the email template
317 // Start with the gender...
322 'surname' => SQL_ESCAPE(postRequestParameter('surname')),
323 'family' => SQL_ESCAPE(postRequestParameter('family')),
324 'email' => SQL_ESCAPE(postRequestParameter('email')),
325 'street' => SQL_ESCAPE(postRequestParameter('street_nr')),
326 'city' => SQL_ESCAPE(postRequestParameter('city')),
327 'zip' => bigintval(postRequestParameter('zip')),
328 'country' => $countryData,
329 'refid' => SQL_ESCAPE(postRequestParameter('refid')),
330 'pass' => SQL_ESCAPE(postRequestParameter('pass1')),
333 // No ZIP code entered
338 'surname' => SQL_ESCAPE(postRequestParameter('surname')),
339 'family' => SQL_ESCAPE(postRequestParameter('family')),
340 'email' => SQL_ESCAPE(postRequestParameter('email')),
341 'street' => SQL_ESCAPE(postRequestParameter('street_nr')),
342 'city' => SQL_ESCAPE(postRequestParameter('city')),
344 'country' => $countryData,
345 'refid' => SQL_ESCAPE(postRequestParameter('refid')),
346 'pass' => SQL_ESCAPE(postRequestParameter('pass1')),
350 // Continue with birthday...
351 switch (getLanguage()) {
353 $content['birthday'] = bigintval(postRequestParameter('day')) . '.' . bigintval(postRequestParameter('month')) . '.' . bigintval(postRequestParameter('year'));
357 $content['birthday'] = bigintval(postRequestParameter('month')) . '/' . bigintval(postRequestParameter('day')) . '/' . bigintval(postRequestParameter('year'));
361 // Display information to the user that he got mail and send it away
362 $messageGuest = loadEmailTemplate('register-member', $content, $userid);
364 // Send mail to user (confirmation link!)
365 $email = $content['email'];
366 sendEmail($content['email'], getMessage('GUEST_SUBJECT_CONFIRM_LINK'), $messageGuest);
367 $content['email'] = $email;
369 // Send mail to admin
370 sendAdminNotification(getMessage('ADMIN_SUBJECT_NEW_ACCOUNT'), 'register-admin', $content, $userid);
372 // Output success registration
373 loadTemplate('admin_settings_saved', false, getMessage('REGISTRATION_DONE'));
375 if (postRequestParameter('agree') == '!') {
376 registerOutputFailedMessage('HAVE_TO_AGREE');
379 if (postRequestParameter('email') == '!') {
380 registerOutputFailedMessage('ENTER_EMAIL');
381 setPostRequestParameter('email', '');
382 } elseif (postRequestParameter('email') == '?') {
383 registerOutputFailedMessage('EMAIL_ALREADY_DB');
384 setPostRequestParameter('email', '');
387 if (postRequestParameter('surname') == '!') {
388 registerOutputFailedMessage('ENTER_SURNAME');
389 setPostRequestParameter('surname', '');
392 if (postRequestParameter('family') == '!') {
393 registerOutputFailedMessage('ENTER_FAMILY');
394 setPostRequestParameter('family', '');
397 if ((postRequestParameter('pass1') == '!') && (postRequestParameter('pass2') == '!')) {
398 registerOutputFailedMessage('ENTER_BOTH_PASSWORDS');
399 } elseif (postRequestParameter('pass1') == '!') {
400 registerOutputFailedMessage('ENTER_PASS1');
401 } elseif (postRequestParameter('pass2') == '!') {
402 registerOutputFailedMessage('ENTER_PASS2');
405 if ($shortPass === true) {
406 registerOutputFailedMessage('SHORT_PASS', ': ' . getConfig('pass_len'));
409 if ($ipTimedOut === true) {
410 registerOutputFailedMessage('REMOTE_ADDR_TIMEOUT');
413 if ((!empty($cats)) && ($cats < getConfig('least_cats'))) {
414 registerOutputFailedMessage('', getMessage('CATS_LEAST'));
417 // Generate birthday selection
418 switch (getLanguage()) {
419 case 'de': // German date format
420 $content['birthday_selection'] = addSelectionBox('day', postRequestParameter('day')).addSelectionBox('month', postRequestParameter('month')).addSelectionBox('year', postRequestParameter('year'));
423 default: // Default is the US date format... :)
424 $content['birthday_selection'] = addSelectionBox('month', postRequestParameter('month')).addSelectionBox('day', postRequestParameter('day')).addSelectionBox('year', postRequestParameter('year'));
428 // Adds a table for the guests with all visible categories
429 $content['category_selection'] = registerGenerateCategoryTable('guest', true);
431 // Adds maximum receiveable mails list... :)
432 $content['max_receive_list'] = addMaxReceiveList('guest', '', true);
434 // Shall I display the refid or shall I make it editable?
435 if (getConfig('display_refid') == 'Y') {
436 // Load "hide" form template
437 $content['refid_content'] = loadTemplate('guest_register_refid_hide', true, determineReferalId());
439 // Load template to enter it
440 $content['refid_content'] = loadTemplate('guest_register_refid', true, determineReferalId());
443 // You may want to modify the register_header.tpl.xx file and not this script when you add your scripts etc. :-)
444 $content['header_content'] = loadTemplate('register_header', true);
447 $content['surname'] = SQL_ESCAPE(postRequestParameter('surname'));
448 $content['family'] = SQL_ESCAPE(postRequestParameter('family'));
449 $content['street_nr'] = SQL_ESCAPE(postRequestParameter('street_nr'));
450 $content['zip'] = '';
451 if (isPostRequestParameterSet('zip')) {
452 $content['zip'] = bigintval(postRequestParameter('zip'));
454 $content['city'] = SQL_ESCAPE(postRequestParameter('city'));
455 $content['email'] = SQL_ESCAPE(postRequestParameter('email'));
457 // Prepare country selection box
458 $OUT = "<select name=\"country_code\" class=\"guest_select\" size=\"1\">\n";
459 $whereStatement = "WHERE `is_active`='Y'";
460 if (isAdmin()) $whereStatement = '';
461 $OUT .= generateOptionList('countries', 'id', 'descr', postRequestParameter('country_code'), 'code', $whereStatement);
463 $content['country'] = $OUT;
465 // Set must-fillout fields
466 $content = runFilterChain('register_must_fillout', $content);
468 // Display registration form
469 loadTemplate('guest_register', false, $content);