2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/10/2004 *
4 * =================== Last change: 07/10/2004 *
6 * -------------------------------------------------------------------- *
7 * File : register_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for register extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktion fuer register-Erweiterung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 function ifRequiredRegisterFieldsAreSet (&$array) {
45 // By default all is fine
47 foreach ($array as $key => $value) {
48 // Check all fields that must register
49 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_must_register` WHERE `field_name`='%s' AND `field_required`='Y' LIMIT 1",
50 array($key), __FUNCTION__, __LINE__);
53 if (SQL_NUMROWS($result) == 1) {
54 // Check if extension country is not found (you have to enter the 2-chars long country code) or
55 // if extensions is present check if country code was selected
56 // 01 2 21 12 3 32 234 5 54 4 43 34 4 4 5 5432 2 3 3210
57 $country = ((!isExtensionActive('country')) || ((isExtensionActive('country')) && (((empty($value)) && ($key == 'cntry')) || (($key == 'country_code') && (!empty($value)))) && (!empty($array['country_code']))));
58 if ((empty($value)) && ($country === false)) {
59 // Required field not set
66 SQL_FREERESULT($result);
73 // Generates a 'category table' for the registration form
74 function registerGenerateCategoryTable ($mode) {
78 // Guests are mostly not interested in how many members has
79 // choosen an individual category
80 $whereStatement = "WHERE `visible`='Y' ";
82 // Admins are allowed to see every category...
83 if (isAdmin()) $whereStatement = '';
85 // Look for categories
86 $result = SQL_QUERY('SELECT `id`,`cat`,`visible` FROM `{?_MYSQL_PREFIX?}_cats` ' . $whereStatement . ' ORDER BY `sort` ASC',
87 __FUNCTION__, __LINE__);
89 if (!SQL_HASZERONUMS($result)) {
90 // List alle visible modules (or all to the admin)
91 $OUT .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
92 while ($content = SQL_FETCHARRAY($result)) {
93 // Prepare array for the template
94 $content['default_yes'] = '';
95 $content['default_no'] = '';
98 if ((postRequestElement('cat', $content['id']) == 'Y') || ((isRegisterDefaultEnabled()) && (!isPostRequestElementSet('cat', $content['id'])))) {
99 $content['default_yes'] = ' checked="checked"';
101 $content['default_no'] = ' checked="checked"';
104 // Load template and switch color
105 $OUT .= loadTemplate('guest_cat_row', true, $content);
110 SQL_FREERESULT($result);
112 // No categories setted up so far...
113 $OUT .= displayMessage('{--NO_CATEGORIES_VISIBLE--}', true);
116 // Return generated HTML code
120 // Outputs a 'failed message'
121 function registerOutputFailedMessage ($messageId, $extra='') {
122 if (empty($messageId)) {
123 outputHtml('<div class="bad">' . $extra . '</div>');
125 outputHtml('<div class="bad">{--' . $messageId . '--}' . $extra . '</div>');
129 // Checks wether the registration data is complete
130 function isRegistrationDataComplete () {
132 $GLOBALS['registration_ip_timeout'] = false;
133 $GLOBALS['registration_short_password'] = false;
134 $GLOBALS['registration_selected_cats'] = '0';
139 // First we only check the submitted data then we continue... :)
141 // Did he agree to our Terms Of Usage?
142 if (postRequestElement('agree') != 'Y') {
143 setPostRequestElement('agree', '!');
147 // Did he enter a valid email address? (we really don't care about
148 // that, he has to click on a confirmation link :P )
149 if ((!isPostRequestElementSet('email')) || (!isEmailValid(postRequestElement('email')))) {
150 setPostRequestElement('email', '!');
154 // And what about surname and family's name?
155 if (!isPostRequestElementSet('surname')) {
156 setPostRequestElement('surname', '!');
159 if (!isPostRequestElementSet('family')) {
160 setPostRequestElement('family', '!');
164 // Get temporary array for modification
165 $postArray = postRequestArray();
167 // Check for required fields
168 $isOkay = ($isOkay && ifRequiredRegisterFieldsAreSet($postArray));
170 // Set it back in request
171 setPostRequestArray($postArray);
173 // Are both passwords zero length?
174 if ((strlen(postRequestElement('pass1')) == 0) && (strlen(postRequestElement('pass2')) == 0) && ($isOkay === true)) {
175 // Is the extension 'register' newer or equal 0.5.5?
176 if ((isExtensionInstalledAndNewer('register', '0.5.5')) && (isRegisterGeneratePasswordEmptyEnabled())) {
177 // Generate a random password
178 $randomPassword = generatePassword();
180 // Set it in both entries
181 setPostRequestElement('pass1', $randomPassword);
182 setPostRequestElement('pass2', $randomPassword);
184 // Not allowed or no recent extension version
185 setPostRequestElement('pass1', '!');
186 setPostRequestElement('pass2', '!');
188 // ... which is both not okay
193 // Did he enter his password twice?
194 if (((!isPostRequestElementSet('pass1')) || (!isPostRequestElementSet('pass2'))) || ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2')))) {
195 if ((postRequestElement('pass1') != postRequestElement('pass2')) && (isPostRequestElementSet('pass1')) && (isPostRequestElementSet('pass2'))) {
196 setPostRequestElement('pass1', '!');
197 setPostRequestElement('pass2', '!');
199 if (!isPostRequestElementSet('pass1')) {
200 setPostRequestElement('pass1', '!');
202 setPostRequestElement('pass1', '');
204 if (!isPostRequestElementSet('pass2')) {
205 setPostRequestElement('pass2', '!');
207 setPostRequestElement('pass2', '');
213 // Is the password long enouth?
214 if ((strlen(postRequestElement('pass1')) < getPassLen()) && ($isOkay === true)) {
215 $GLOBALS['registration_short_password'] = true;
219 // Do this check only when no admin is logged in
220 if (is_array(postRequestElement('cat'))) {
221 // Only continue with array
222 foreach (postRequestElement('cat') as $id => $answer) {
223 // Is this category choosen?
224 if ($answer == 'Y') {
225 $GLOBALS['registration_selected_cats']++;
230 // Enougth categories selected?
231 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay).',selected='.$GLOBALS['registration_selected_cats'].'/'.getLeastCats());
232 $isOkay = (($isOkay) && ($GLOBALS['registration_selected_cats'] >= getLeastCats()));
234 if ((postRequestElement('email') != '!') && (isCheckDoubleEmailEnabled())) {
235 // Does the email address already exists in our database?
236 if ((isEmailTaken(postRequestElement('email'))) && (!isAdmin())) {
237 setPostRequestElement('email', '?');
242 // Check for IP timeout?
243 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay));
244 if ((!isAdmin()) && (getIpTimeout() > 0)) {
245 // Check his IP number
246 $GLOBALS['registration_ip_timeout'] = (countSumTotalData(detectRemoteAddr() , 'user_data', 'userid', 'REMOTE_ADDR', true, ' AND ((UNIX_TIMESTAMP() - `joined`) < {?ip_timeout?} OR (UNIX_TIMESTAMP() - `last_update`) < {?ip_timeout?})') == 1);
247 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay).',timeout='.intval($GLOBALS['registration_ip_timeout']));
248 $isOkay = (($isOkay) && (!$GLOBALS['registration_ip_timeout']));
252 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isOkay='.intval($isOkay));
256 // Do the registration
257 function doRegistration () {
258 // Generate hash which will be inserted into confirmation mail
259 $hash = generateHash(sha1(
260 // Get total confirmed, ...
261 getTotalConfirmedUser() . getEncryptSeparator() .
262 // ... unconfirmed ...
263 getTotalUnconfirmedUser() . getEncryptSeparator() .
264 // ... and locked users
265 getTotalLockedUser() . getEncryptSeparator() .
266 postRequestElement('month') . '-' .
267 postRequestElement('day') . '-' .
268 postRequestElement('year') . getEncryptSeparator() .
269 detectServerName() . getEncryptSeparator() .
270 detectRemoteAddr() . getEncryptSeparator() .
271 detectUserAgent() . '/' .
274 getConfig('CACHE_BUSTER')
277 // Old way with enterable two-char-code
278 $countryRow = '`country`';
279 $countryData = substr(postRequestElement('cntry'), 0, 2);
281 // Add design when extension ext-theme is v0.0.8 or greater
282 // @TODO Rewrite these all to a single filter
283 $GLOBALS['register_sql_columns'] = '';
284 $GLOBALS['register_sql_data'] = '';
285 if (isExtensionInstalledAndNewer('theme', '0.0.8')) {
286 // Okay, add design here
287 $GLOBALS['register_sql_columns'] .= ', `curr_theme`';
288 $GLOBALS['register_sql_data'] .= ", '{%%pipe,getCurrentTheme%%}'";
291 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
293 // First comes first: begging rallye
294 if ((isExtensionInstalledAndNewer('beg', '0.2.7')) && (!isBegNewMemberNotifyEnabled())) {
295 $GLOBALS['register_sql_columns'] .= ', `beg_rallye_enable_notify`, `beg_rallye_disable_notify`';
296 $GLOBALS['register_sql_data'] .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
299 // Second: active rallye
300 if ((isExtensionActive('bonus')) && (!isBonusNewMemberNotifyEnabled())) {
301 $GLOBALS['register_sql_columns'] .= ', `bonus_rallye_enable_notify`, `bonus_rallye_disable_notify`';
302 $GLOBALS['register_sql_data'] .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
305 // Write user data to table
306 if (isExtensionActive('country')) {
307 // Save with new selectable country code
308 $countryRow = '`country_code`';
309 $countryData = bigintval(postRequestElement('country_code'));
312 // Create user's account...
313 SQL_QUERY_ESC("INSERT INTO
314 `{?_MYSQL_PREFIX?}_user_data`
337 ".$GLOBALS['register_sql_columns']."
356 '{%%pipe,detectRemoteAddr%%}',
360 ".$GLOBALS['register_sql_data'].")",
363 substr(postRequestElement('gender'), 0, 1),
364 postRequestElement('surname'),
365 postRequestElement('family'),
366 postRequestElement('street_nr'),
368 bigintval(postRequestElement('zip')),
369 postRequestElement('city'),
370 postRequestElement('email'),
371 bigintval(postRequestElement('day')),
372 bigintval(postRequestElement('month')),
373 bigintval(postRequestElement('year')),
374 generateHash(postRequestElement('pass1')),
375 bigintval(postRequestElement('max_mails')),
376 bigintval(postRequestElement('max_mails')),
377 convertZeroToNull(postRequestElement('refid')),
379 ), __FUNCTION__, __LINE__);
382 $userid = bigintval(SQL_INSERTID());
385 if ($userid == '0') {
386 // Something bad happened!
387 displayMessage('{--USER_NOT_REGISTERED--}');
393 // Shall we reset random refid? Only possible with latest ext-user
394 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
395 // Reset all accounts, registration is done
396 SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0', __FUNCTION__, __LINE__);
399 // Update referral table
400 updateReferralCounter($userid);
402 // Write his welcome-points
403 initReferralSystem();
404 addPointsThroughReferralSystem('register_welcome', $userid, getPointsRegister());
407 if ((is_array(postRequestElement('cat'))) && (count(postRequestElement('cat')))) {
408 foreach (postRequestElement('cat') as $categoryId => $joined) {
409 if ($joined == 'Y') {
410 // Insert category entry
411 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`,`cat_id`) VALUES (%s, %s)",
414 bigintval($categoryId)
415 ), __FUNCTION__, __LINE__);
420 // ... rewrite a zero referral id to the main title
421 if (!isValidUserId(postRequestElement('refid'))) {
422 setPostRequestElement('refid', getMainTitle());
426 if (isPostRequestElementSet('zip')) {
427 // Prepare data array for the email template
428 // Start with the gender...
432 'gender' => SQL_ESCAPE(postRequestElement('gender')),
433 'surname' => SQL_ESCAPE(postRequestElement('surname')),
434 'family' => SQL_ESCAPE(postRequestElement('family')),
435 'email' => SQL_ESCAPE(postRequestElement('email')),
436 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
437 'city' => SQL_ESCAPE(postRequestElement('city')),
438 'zip' => bigintval(postRequestElement('zip')),
439 'country' => $countryData,
440 'refid' => SQL_ESCAPE(postRequestElement('refid')),
441 'password' => SQL_ESCAPE(postRequestElement('pass1')),
444 // No ZIP code entered
448 'gender' => SQL_ESCAPE(postRequestElement('gender')),
449 'surname' => SQL_ESCAPE(postRequestElement('surname')),
450 'family' => SQL_ESCAPE(postRequestElement('family')),
451 'email' => SQL_ESCAPE(postRequestElement('email')),
452 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
453 'city' => SQL_ESCAPE(postRequestElement('city')),
455 'country' => $countryData,
456 'refid' => SQL_ESCAPE(postRequestElement('refid')),
457 'password' => SQL_ESCAPE(postRequestElement('pass1')),
461 // Continue with birthday...
462 switch (getLanguage()) {
464 $content['birthday'] = bigintval(postRequestElement('day')) . '.' . bigintval(postRequestElement('month')) . '.' . bigintval(postRequestElement('year'));
468 $content['birthday'] = bigintval(postRequestElement('month')) . '/' . bigintval(postRequestElement('day')) . '/' . bigintval(postRequestElement('year'));
472 // Display information to the user that he got mail and send it away
473 $messageGuest = loadEmailTemplate('guest_register_done', $content, $userid, false);
475 // Send mail to user (confirmation link!)
476 sendEmail($userid, '{--GUEST_CONFIRM_LINK_SUBJECT--}', $messageGuest);
478 // Send mail to admin
479 sendAdminNotification('{--ADMIN_NEW_ACCOUNT_SUBJECT--}', 'admin_register_done', $content, $userid);
482 //-----------------------------------------------------------------------------
483 // Wrapper functions for ext-register
484 //-----------------------------------------------------------------------------
486 // Getter for 'display_refid'
487 function getDisplayRefid () {
488 // Is the cache entry set?
489 if (!isset($GLOBALS[__FUNCTION__])) {
490 // No, so determine it
491 $GLOBALS[__FUNCTION__] = getConfig('display_refid');
494 // Return cached entry
495 return $GLOBALS[__FUNCTION__];
498 // Checks wether 'display_refid' is "YES"
499 function isDisplayRefidEnabled () {
500 // Is the cache entry set?
501 if (!isset($GLOBALS[__FUNCTION__])) {
502 // No, so determine it
503 $GLOBALS[__FUNCTION__] = (getDisplayRefid() == 'Y');
506 // Return cached entry
507 return $GLOBALS[__FUNCTION__];
510 // Getter for 'ip_timeout'
511 function getIpTimeout () {
512 // Is the cache entry set?
513 if (!isset($GLOBALS[__FUNCTION__])) {
514 // No, so determine it
515 $GLOBALS[__FUNCTION__] = getConfig('ip_timeout');
518 // Return cached entry
519 return $GLOBALS[__FUNCTION__];
522 // Getter for 'register_default'
523 function getRegisterDefault () {
524 // Is the cache entry set?
525 if (!isset($GLOBALS[__FUNCTION__])) {
526 // No, so determine it
527 $GLOBALS[__FUNCTION__] = getConfig('register_default');
530 // Return cached entry
531 return $GLOBALS[__FUNCTION__];
534 // Checks wether 'register_default' is "YES"
535 function isRegisterDefaultEnabled () {
536 // Is the cache entry set?
537 if (!isset($GLOBALS[__FUNCTION__])) {
538 // No, so determine it
539 $GLOBALS[__FUNCTION__] = (getRegisterDefault() == 'Y');
542 // Return cached entry
543 return $GLOBALS[__FUNCTION__];
546 // Getter for 'register_generate_password_empty'
547 function getRegisterGeneratePasswordEmpty () {
548 // Is the cache entry set?
549 if (!isset($GLOBALS[__FUNCTION__])) {
550 // No, so determine it
551 $GLOBALS[__FUNCTION__] = getConfig('register_generate_password_empty');
554 // Return cached entry
555 return $GLOBALS[__FUNCTION__];
558 // Checks wether 'register_generate_password_empty' is "YES"
559 function isRegisterGeneratePasswordEmptyEnabled () {
560 // Is the cache entry set?
561 if (!isset($GLOBALS[__FUNCTION__])) {
562 // No, so determine it
563 $GLOBALS[__FUNCTION__] = (getRegisterGeneratePasswordEmpty() == 'Y');
566 // Return cached entry
567 return $GLOBALS[__FUNCTION__];