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="notice">' . $extra . '</div>');
125 outputHtml('<div class="notice">{--' . $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() . getEncryptSeperator() .
266 // ... unconfirmed ...
267 getTotalUnconfirmedUser() . getEncryptSeperator() .
268 // ... and locked users!
269 getTotalLockedUser() . getEncryptSeperator() .
270 postRequestElement('month') . '-' .
271 postRequestElement('day') . '-' .
272 postRequestElement('year') . getEncryptSeperator() .
273 detectServerName() . getEncryptSeperator() .
274 detectRemoteAddr() . getEncryptSeperator() .
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`
319 (`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`,`ref_payout`".$GLOBALS['register_sql_columns'].")
321 ('%s','%s','%s','%s','%s',%s,'%s','%s',%s, %s,%s,'%s',%s, %s,'%s','UNCONFIRMED','%s','{%%pipe,detectRemoteAddr%%}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), {?ref_payout?}".$GLOBALS['register_sql_data'].")",
324 substr(postRequestElement('gender'), 0, 1),
325 postRequestElement('surname'),
326 postRequestElement('family'),
327 postRequestElement('street_nr'),
329 bigintval(postRequestElement('zip')),
330 postRequestElement('city'),
331 postRequestElement('email'),
332 bigintval(postRequestElement('day')),
333 bigintval(postRequestElement('month')),
334 bigintval(postRequestElement('year')),
335 generateHash(postRequestElement('pass1')),
336 bigintval(postRequestElement('max_mails')),
337 bigintval(postRequestElement('max_mails')),
338 makeZeroToNull(postRequestElement('refid')),
340 ), __FUNCTION__, __LINE__);
343 $userid = bigintval(SQL_INSERTID());
346 if ($userid == '0') {
347 // Something bad happened!
348 displayMessage('{--USER_NOT_REGISTERED--}');
354 // Shall we reset random refid? Only possible with latest ext-user
355 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
356 // Reset all accounts, registration is done
357 SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `rand_confirmed`=0', __FUNCTION__, __LINE__);
360 // Update referal table
361 updateReferalCounter($userid);
363 // Write his welcome-points
365 addPointsThroughReferalSystem('register_welcome', $userid, getPointsRegister());
368 if ((is_array(postRequestElement('cat'))) && (count(postRequestElement('cat')))) {
369 foreach (postRequestElement('cat') as $categoryId => $joined) {
370 if ($joined == 'Y') {
371 // Insert category entry
372 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`,`cat_id`) VALUES (%s, %s)",
375 bigintval($categoryId)
376 ), __FUNCTION__, __LINE__);
381 // ... rewrite a zero referal id to the main title
382 if (!isValidUserId(postRequestElement('refid'))) {
383 setPostRequestElement('refid', getMainTitle());
387 if (isPostRequestElementSet('zip')) {
388 // Prepare data array for the email template
389 // Start with the gender...
393 'gender' => SQL_ESCAPE(postRequestElement('gender')),
394 'surname' => SQL_ESCAPE(postRequestElement('surname')),
395 'family' => SQL_ESCAPE(postRequestElement('family')),
396 'email' => SQL_ESCAPE(postRequestElement('email')),
397 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
398 'city' => SQL_ESCAPE(postRequestElement('city')),
399 'zip' => bigintval(postRequestElement('zip')),
400 'country' => $countryData,
401 'refid' => SQL_ESCAPE(postRequestElement('refid')),
402 'password' => SQL_ESCAPE(postRequestElement('pass1')),
405 // No ZIP code entered
409 'gender' => SQL_ESCAPE(postRequestElement('gender')),
410 'surname' => SQL_ESCAPE(postRequestElement('surname')),
411 'family' => SQL_ESCAPE(postRequestElement('family')),
412 'email' => SQL_ESCAPE(postRequestElement('email')),
413 'street' => SQL_ESCAPE(postRequestElement('street_nr')),
414 'city' => SQL_ESCAPE(postRequestElement('city')),
416 'country' => $countryData,
417 'refid' => SQL_ESCAPE(postRequestElement('refid')),
418 'password' => SQL_ESCAPE(postRequestElement('pass1')),
422 // Continue with birthday...
423 switch (getLanguage()) {
425 $content['birthday'] = bigintval(postRequestElement('day')) . '.' . bigintval(postRequestElement('month')) . '.' . bigintval(postRequestElement('year'));
429 $content['birthday'] = bigintval(postRequestElement('month')) . '/' . bigintval(postRequestElement('day')) . '/' . bigintval(postRequestElement('year'));
433 // Display information to the user that he got mail and send it away
434 $messageGuest = loadEmailTemplate('guest_register_done', $content, $userid, false);
436 // Send mail to user (confirmation link!)
437 sendEmail($userid, '{--GUEST_CONFIRM_LINK_SUBJECT--}', $messageGuest);
439 // Send mail to admin
440 sendAdminNotification('{--ADMIN_NEW_ACCOUNT_SUBJECT--}', 'admin_register_done', $content, $userid);
443 //-----------------------------------------------------------------------------
444 // Wrapper functions for ext-register
445 //-----------------------------------------------------------------------------
447 // Getter for 'display_refid'
448 function getDisplayRefid () {
449 // Is the cache entry set?
450 if (!isset($GLOBALS[__FUNCTION__])) {
451 // No, so determine it
452 $GLOBALS[__FUNCTION__] = getConfig('display_refid');
455 // Return cached entry
456 return $GLOBALS[__FUNCTION__];
459 // Checks wether 'display_refid' is "YES"
460 function isDisplayRefidEnabled () {
461 // Is the cache entry set?
462 if (!isset($GLOBALS[__FUNCTION__])) {
463 // No, so determine it
464 $GLOBALS[__FUNCTION__] = (getDisplayRefid() == 'Y');
467 // Return cached entry
468 return $GLOBALS[__FUNCTION__];
471 // Getter for 'ip_timeout'
472 function getIpTimeout () {
473 // Is the cache entry set?
474 if (!isset($GLOBALS[__FUNCTION__])) {
475 // No, so determine it
476 $GLOBALS[__FUNCTION__] = getConfig('ip_timeout');
479 // Return cached entry
480 return $GLOBALS[__FUNCTION__];
483 // Getter for 'register_default'
484 function getRegisterDefault () {
485 // Is the cache entry set?
486 if (!isset($GLOBALS[__FUNCTION__])) {
487 // No, so determine it
488 $GLOBALS[__FUNCTION__] = getConfig('register_default');
491 // Return cached entry
492 return $GLOBALS[__FUNCTION__];
495 // Checks wether 'register_default' is "YES"
496 function isRegisterDefaultEnabled () {
497 // Is the cache entry set?
498 if (!isset($GLOBALS[__FUNCTION__])) {
499 // No, so determine it
500 $GLOBALS[__FUNCTION__] = (getRegisterDefault() == 'Y');
503 // Return cached entry
504 return $GLOBALS[__FUNCTION__];
507 // Getter for 'register_generate_password_empty'
508 function getRegisterGeneratePasswordEmpty () {
509 // Is the cache entry set?
510 if (!isset($GLOBALS[__FUNCTION__])) {
511 // No, so determine it
512 $GLOBALS[__FUNCTION__] = getConfig('register_generate_password_empty');
515 // Return cached entry
516 return $GLOBALS[__FUNCTION__];
519 // Checks wether 'register_generate_password_empty' is "YES"
520 function isRegisterGeneratePasswordEmptyEnabled () {
521 // Is the cache entry set?
522 if (!isset($GLOBALS[__FUNCTION__])) {
523 // No, so determine it
524 $GLOBALS[__FUNCTION__] = (getRegisterGeneratePasswordEmpty() == 'Y');
527 // Return cached entry
528 return $GLOBALS[__FUNCTION__];