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?}) LIMIT 1") == 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 // Prepapre month and day of birth
259 if (strlen(postRequestElement('day')) == 1) setPostRequestElement('day' , '0' . postRequestElement('day'));
260 if (strlen(postRequestElement('month')) == 1) setPostRequestElement('month', '0' . postRequestElement('month'));
262 // Generate hash which will be inserted into confirmation mail
263 $hash = generateHash(sha1(
264 // Get total confirmed, ...
265 getTotalConfirmedUser() . getEncryptSeparator() .
266 // ... unconfirmed ...
267 getTotalUnconfirmedUser() . getEncryptSeparator() .
268 // ... and locked users!
269 getTotalLockedUser() . getEncryptSeparator() .
270 postRequestElement('month') . '-' .
271 postRequestElement('day') . '-' .
272 postRequestElement('year') . getEncryptSeparator() .
273 detectServerName() . getEncryptSeparator() .
274 detectRemoteAddr() . getEncryptSeparator() .
275 detectUserAgent() . '/' .
278 getConfig('CACHE_BUSTER')
281 // Old way with enterable two-char-code
282 $countryRow = '`country`';
283 $countryData = substr(postRequestElement('cntry'), 0, 2);
285 // Add design when extension ext-theme is v0.0.8 or greater
286 // @TODO Rewrite these all to a single filter
287 $GLOBALS['register_sql_columns'] = '';
288 $GLOBALS['register_sql_data'] = '';
289 if (isExtensionInstalledAndNewer('theme', '0.0.8')) {
290 // Okay, add design here
291 $GLOBALS['register_sql_columns'] .= ',`curr_theme`';
292 $GLOBALS['register_sql_data'] .= ", '{%%pipe,getCurrentTheme%%}'";
295 // Check if I shall disable sending mail to newly registered members out about active/begging rallye
297 // First comes first: begging rallye
298 if ((isExtensionInstalledAndNewer('beg', '0.2.7')) && (!isBegNewMemberNotifyEnabled())) {
299 $GLOBALS['register_sql_columns'] .= ',`beg_rallye_enable_notify`,`beg_rallye_disable_notify`';
300 $GLOBALS['register_sql_data'] .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
303 // Second: active rallye
304 if ((isExtensionActive('bonus')) && (!isBonusNewMemberNotifyEnabled())) {
305 $GLOBALS['register_sql_columns'] .= ',`bonus_rallye_enable_notify`,`bonus_rallye_disable_notify`';
306 $GLOBALS['register_sql_data'] .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
309 // Write user data to table
310 if (isExtensionActive('country')) {
311 // Save with new selectable country code
312 $countryRow = '`country_code`';
313 $countryData = bigintval(postRequestElement('country_code'));
316 // Create user's account...
317 SQL_QUERY_ESC("INSERT INTO
318 `{?_MYSQL_PREFIX?}_user_data`
341 ".$GLOBALS['register_sql_columns']."
360 '{%%pipe,detectRemoteAddr%%}',
364 ".$GLOBALS['register_sql_data'].")",
367 substr(postRequestElement('gender'), 0, 1),
368 postRequestElement('surname'),
369 postRequestElement('family'),
370 postRequestElement('street_nr'),
372 bigintval(postRequestElement('zip')),
373 postRequestElement('city'),
374 postRequestElement('email'),
375 bigintval(postRequestElement('day')),
376 bigintval(postRequestElement('month')),
377 bigintval(postRequestElement('year')),
378 generateHash(postRequestElement('pass1')),
379 bigintval(postRequestElement('max_mails')),
380 bigintval(postRequestElement('max_mails')),
381 makeZeroToNull(postRequestElement('refid')),
383 ), __FUNCTION__, __LINE__);
386 $userid = bigintval(SQL_INSERTID());
389 if ($userid == '0') {
390 // Something bad happened!
391 displayMessage('{--USER_NOT_REGISTERED--}');
397 // Shall we reset random refid? Only possible with latest ext-user
398 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
399 // Reset all accounts, registration is done
400 SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0', __FUNCTION__, __LINE__);
403 // Update referral table
404 updateReferralCounter($userid);
406 // Write his welcome-points
407 initReferralSystem();
408 addPointsThroughReferralSystem('register_welcome', $userid, getPointsRegister());
411 if ((is_array(postRequestElement('cat'))) && (count(postRequestElement('cat')))) {
412 foreach (postRequestElement('cat') as $categoryId => $joined) {
413 if ($joined == 'Y') {
414 // Insert category entry
415 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`,`cat_id`) VALUES (%s, %s)",
418 bigintval($categoryId)
419 ), __FUNCTION__, __LINE__);
424 // ... rewrite a zero referral id to the main title
425 if (!isValidUserId(postRequestElement('refid'))) {
426 setPostRequestElement('refid', getMainTitle());
430 if (isPostRequestElementSet('zip')) {
431 // Prepare data array for the email template
432 // Start with the gender...
436 'gender' => SQL_ESCAPE(postRequestElement('gender')),
437 'surname' => SQL_ESCAPE(postRequestElement('surname')),
438 'family' => SQL_ESCAPE(postRequestElement('family')),
439 'email' => SQL_ESCAPE(postRequestElement('email')),
440 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
441 'city' => SQL_ESCAPE(postRequestElement('city')),
442 'zip' => bigintval(postRequestElement('zip')),
443 'country' => $countryData,
444 'refid' => SQL_ESCAPE(postRequestElement('refid')),
445 'password' => SQL_ESCAPE(postRequestElement('pass1')),
448 // No ZIP code entered
452 'gender' => SQL_ESCAPE(postRequestElement('gender')),
453 'surname' => SQL_ESCAPE(postRequestElement('surname')),
454 'family' => SQL_ESCAPE(postRequestElement('family')),
455 'email' => SQL_ESCAPE(postRequestElement('email')),
456 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
457 'city' => SQL_ESCAPE(postRequestElement('city')),
459 'country' => $countryData,
460 'refid' => SQL_ESCAPE(postRequestElement('refid')),
461 'password' => SQL_ESCAPE(postRequestElement('pass1')),
465 // Continue with birthday...
466 switch (getLanguage()) {
468 $content['birthday'] = bigintval(postRequestElement('day')) . '.' . bigintval(postRequestElement('month')) . '.' . bigintval(postRequestElement('year'));
472 $content['birthday'] = bigintval(postRequestElement('month')) . '/' . bigintval(postRequestElement('day')) . '/' . bigintval(postRequestElement('year'));
476 // Display information to the user that he got mail and send it away
477 $messageGuest = loadEmailTemplate('guest_register_done', $content, $userid, false);
479 // Send mail to user (confirmation link!)
480 sendEmail($userid, '{--GUEST_CONFIRM_LINK_SUBJECT--}', $messageGuest);
482 // Send mail to admin
483 sendAdminNotification('{--ADMIN_NEW_ACCOUNT_SUBJECT--}', 'admin_register_done', $content, $userid);
486 //-----------------------------------------------------------------------------
487 // Wrapper functions for ext-register
488 //-----------------------------------------------------------------------------
490 // Getter for 'display_refid'
491 function getDisplayRefid () {
492 // Is the cache entry set?
493 if (!isset($GLOBALS[__FUNCTION__])) {
494 // No, so determine it
495 $GLOBALS[__FUNCTION__] = getConfig('display_refid');
498 // Return cached entry
499 return $GLOBALS[__FUNCTION__];
502 // Checks wether 'display_refid' is "YES"
503 function isDisplayRefidEnabled () {
504 // Is the cache entry set?
505 if (!isset($GLOBALS[__FUNCTION__])) {
506 // No, so determine it
507 $GLOBALS[__FUNCTION__] = (getDisplayRefid() == 'Y');
510 // Return cached entry
511 return $GLOBALS[__FUNCTION__];
514 // Getter for 'ip_timeout'
515 function getIpTimeout () {
516 // Is the cache entry set?
517 if (!isset($GLOBALS[__FUNCTION__])) {
518 // No, so determine it
519 $GLOBALS[__FUNCTION__] = getConfig('ip_timeout');
522 // Return cached entry
523 return $GLOBALS[__FUNCTION__];
526 // Getter for 'register_default'
527 function getRegisterDefault () {
528 // Is the cache entry set?
529 if (!isset($GLOBALS[__FUNCTION__])) {
530 // No, so determine it
531 $GLOBALS[__FUNCTION__] = getConfig('register_default');
534 // Return cached entry
535 return $GLOBALS[__FUNCTION__];
538 // Checks wether 'register_default' is "YES"
539 function isRegisterDefaultEnabled () {
540 // Is the cache entry set?
541 if (!isset($GLOBALS[__FUNCTION__])) {
542 // No, so determine it
543 $GLOBALS[__FUNCTION__] = (getRegisterDefault() == 'Y');
546 // Return cached entry
547 return $GLOBALS[__FUNCTION__];
550 // Getter for 'register_generate_password_empty'
551 function getRegisterGeneratePasswordEmpty () {
552 // Is the cache entry set?
553 if (!isset($GLOBALS[__FUNCTION__])) {
554 // No, so determine it
555 $GLOBALS[__FUNCTION__] = getConfig('register_generate_password_empty');
558 // Return cached entry
559 return $GLOBALS[__FUNCTION__];
562 // Checks wether 'register_generate_password_empty' is "YES"
563 function isRegisterGeneratePasswordEmptyEnabled () {
564 // Is the cache entry set?
565 if (!isset($GLOBALS[__FUNCTION__])) {
566 // No, so determine it
567 $GLOBALS[__FUNCTION__] = (getRegisterGeneratePasswordEmpty() == 'Y');
570 // Return cached entry
571 return $GLOBALS[__FUNCTION__];