2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/16/2004 *
4 * =================== Last change: 10/27/2004 *
6 * -------------------------------------------------------------------- *
7 * File : user_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for user extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktionen fuer die user-Erweiterung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 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')) {
43 // Add links for selecting some users
44 function addAlphabeticalSorting ($sortby) {
46 foreach (array('page', 'offset', 'do', 'status') as $param) {
47 if (isGetRequestElementSet($param)) {
48 $add .= '&' . $param . '=' . getRequestElement($param);
52 // Creates the list of letters and makes them a link.
53 $alphabet = explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,');
54 $num = count($alphabet) - 1;
56 // Add all letter links
58 while (list($counter, $ltr) = each($alphabet)) {
59 if (getRequestElement('letter') == $ltr) {
60 // Current letter is letter from URL
61 $OUT .= '<strong>' . $ltr . '</strong>';
63 // Output link to letter
64 $OUT .= '<a href="{%url=modules.php?module=admin&what=' . getWhat() . '&letter=' . $ltr . '&sortby=' . $sortby . $add . '%}">' . $ltr . '</a>';
67 if ((($counter / getUserAlpha()) == round($counter / getUserAlpha())) && ($counter > 0)) {
69 } elseif ($counter != $num) {
76 'alpha_selection' => $OUT,
80 $OUT = loadTemplate('admin_list_user_alpha', true, $content);
82 // Return generated code
86 // Add links for sorting
87 function addSortLinks ($letter, $sortby) {
89 if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', 0);
90 if (!isGetRequestElementSet('page')) setGetRequestElement('page' , 0);
92 // Add page and offset
93 $add = '&page=' . getRequestElement('page') . '&offset=' . getRequestElement('offset');
96 foreach (array('do','status') as $param) {
97 if (isGetRequestElementSet($param)) {
98 $add .= '&' . $param . '=' . getRequestElement($param);
102 // Makes order by links..
103 if ($letter == 'front') {
107 // Prepare array with all possible sorters
109 'userid' => '{--_USERID--}',
110 'family' => '{--FAMILY--}',
111 'email' => '{--EMAIL--}',
112 'REMOTE_ADDR' => '{--REMOTE_IP--}'
115 // Add nickname if extension is installed
116 if (isExtensionActive('nickname')) {
117 $list['nickname'] = '{--NICKNAME--}';
120 foreach ($list as $sort => $title) {
121 if ($sortby == $sort) {
122 $OUT .= '<strong>' . $title . '</strong>|';
124 $OUT .= '<a href="{%url=modules.php?module=admin&what=list_user&letter=' . $letter . '&sortby=' . $sort . $add . '%}">' . $title . '</a>|';
129 $content['list'] = substr($OUT, 0, -1);
132 $OUT = loadTemplate('admin_list_user_sort', true, $content);
138 // Add page navigation
139 function addPageNavigation ($numPages) {
140 // Start with empty content
143 // Create only the navigation if page count > 1
145 // Create navigation links for every page
146 for ($page = 1; $page <= $numPages; $page++) {
147 if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
150 if (!isGetRequestElementSet('letter')) setGetRequestElement('letter', '');
151 if (!isGetRequestElementSet('sortby')) setGetRequestElement('sortby', 'userid');
154 $OUT .= '<a href="{%url=modules.php?module=admin&what=' . getWhat();
157 foreach (array('do','status') as $param) {
158 if (isGetRequestElementSet($param)) {
159 $OUT .= '&' . $param . '=' . getRequestElement($param);
164 $OUT .= '&letter=' . getRequestElement('letter') . '&sortby=' . getRequestElement('sortby') . '&page=' . $page . '&offset=' . getUserLimit() . '%}">';
169 if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
170 $OUT .= '-</strong>';
175 if ($page < $numPages) {
181 $content['list'] = $OUT;
184 $OUT = loadTemplate('admin_list_user_pagenav', true, $content);
191 // Create email link to user's account
192 function generateUserEmailLink ($email, $mod = 'admin') {
193 // Show contact link only if user is confirmed by default
194 $locked = " AND `status`='CONFIRMED'";
196 // But admins shall always see it
201 // Search for the email address
202 $result = SQL_QUERY_ESC("SELECT
205 `{?_MYSQL_PREFIX?}_user_data`
210 array($email), __FUNCTION__, __LINE__);
212 // Do we have an entry?
213 if (SQL_NUMROWS($result) == 1) {
215 list($userid) = SQL_FETCHROW($result);
217 // Rewrite email address to contact link
218 $email = '{%url=modules.php?module=' . $mod . '&what=user_contct&userid=' . bigintval($userid) . '%}';
222 SQL_FREERESULT($result);
224 // Return rewritten (?) email address
228 // Selects a random user id as the new referral id if they have at least X confirmed mails in this run
229 function determineRandomReferralId () {
230 // Default is zero refid
233 // Is the extension version fine?
234 if ((isRandomReferralIdEnabled()) && (isExtensionInstalledAndNewer('user', '0.3.4'))) {
236 $totalUsers = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `rand_confirmed` >= {?user_min_confirmed?}'));
238 // Do we have at least one?
239 if ($totalUsers > 0) {
240 // Then choose random userid
241 $randUserid = mt_rand(0, ($totalUsers - 1));
243 // Look for random user
244 $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` " . runFilterChain('user_exclusion_sql', "WHERE `status`='CONFIRMED'") . ' AND `rand_confirmed` >= {?user_min_confirmed?} ORDER BY `rand_confirmed` DESC LIMIT %s, 1',
245 array($randUserid), __FUNCTION__, __LINE__);
247 // Do we have one entry there?
248 if (SQL_NUMROWS($result) == 1) {
249 // Use that userid as new referral id
250 list($refid) = SQL_FETCHROW($result);
253 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ' - choosen!');
257 SQL_FREERESULT($result);
266 function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.php?module=index&what=login&login=') {
284 if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
286 $isFound = fetchUserData($userid, 'nickname');
287 } elseif (isNicknameUsed($userid)) {
288 // No nickname installed
289 $errorCode = getCode('EXTENSION_PROBLEM');
292 // Direct userid entered
293 $isFound = fetchUserData($userid);
297 if (($errorCode == '0') && ($isFound === true)) {
298 // Get user data array and set userid (e.g. important if we login with nickname)
299 $content = getUserDataArray();
300 if (!empty($content['userid'])) {
301 $userid = bigintval($content['userid']);
306 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',isUserDataValid()=' . intval(isUserDataValid()) . ',userStatus=' . getUserData('status') . ',errorCode=' . $errorCode . ',ext=' . $ext . ',isFound=' . intval($isFound));
308 // Is there an entry?
309 if (($errorCode == '0') && (isUserDataValid()) && (getUserData('status') == 'CONFIRMED') && (!empty($content['userid']))) {
310 // Check for old MD5 passwords
311 if ((strlen(getUserData('password')) == 32) && (md5($passwd) == getUserData('password'))) {
312 // Just set the hash to the password from DB... :)
313 $content['hash'] = getUserData('password');
315 // Hash password with improved way for comparsion
316 $content['hash'] = generateHash($passwd, substr(getUserData('password'), 0, -40));
319 // Does the password match the hash?
320 if ($content['hash'] == getUserData('password')) {
321 // New hashed password found so let's generate a new one
322 $content['hash'] = generateHash($passwd);
324 // ... and update database
325 // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
326 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `password`='%s' WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
327 array($content['hash'], $userid), __FUNCTION__, __LINE__);
329 // No login bonus by default
330 $GLOBALS['bonus_payed'] = false;
332 // Is bonus up-to-date?
333 if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
334 // Probe for last online timemark
335 $probe = time() - getUserData('last_online');
336 if (getUserData('last_login') > 0) {
337 // Use timestamp from last login
338 $probe = time() - getUserData('last_login');
341 // Is the timeout reached?
342 if ($probe >= getConfig('login_timeout')) {
343 // Add login bonus to user's account
344 $add = ',`login_bonus`=`login_bonus`+{?login_bonus?}';
345 $GLOBALS['bonus_payed'] = true;
347 // Subtract login bonus from userid's account or jackpot
348 if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD')) {
349 handleBonusPoints('login_bonus', $userid);
354 // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
357 setMemberId($userid);
359 // Try to set session data (which shall normally always work!)
360 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',hash=' . $content['hash'] . '(' . strlen($content['hash']) . ')');
361 if ((setSession('userid', $userid )) && (setSession('u_hash', encodeHashForCookie($content['hash'])))) {
362 // Update database records
363 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `total_logins`=`total_logins`+1" . $add . " WHERE `userid`=%s LIMIT 1",
364 array($userid), __FUNCTION__, __LINE__);
365 if (!SQL_HASZEROAFFECTED()) {
366 // Is a success URL set?
367 if (empty($successUrl)) {
368 // Procedure to checking for login data
369 if (($GLOBALS['bonus_payed'] === true) && (isExtensionActive('bonus'))) {
370 // Bonus added (just displaying!)
371 $url = 'modules.php?module=chk_login&do=bonus';
374 $url = 'modules.php?module=chk_login&do=login';
381 // Cannot update counter!
382 $errorCode = getCode('CNTR_FAILED');
385 // Cookies not setable!
386 $errorCode = getCode('COOKIES_DISABLED');
388 } elseif (isExtensionInstalledAndNewer('sql_patches', '0.6.1')) {
389 // Update failure counter
390 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `login_failures`=`login_failures`+1,`last_failure`=NOW() WHERE `userid`=%s LIMIT 1",
391 array($userid), __FUNCTION__, __LINE__);
394 $errorCode = getCode('WRONG_PASS');
396 } elseif ((isUserDataValid()) && (getUserData('status') != 'CONFIRMED')) {
397 // Create an error code from given status
398 $errorCode = generateErrorCodeFromUserStatus(getUserData('status'));
400 // Set userid in session
401 setSession('userid', getUserData('userid'));
402 } elseif (!isUserDataValid()) {
404 $errorCode = getCode('WRONG_ID');
407 $errorCode = getCode('UNKNOWN_ERROR');
410 // Error code provided?
411 if ($errorCode > 0) {
412 // Then reconstruct the URL
413 $url = $errorUrl . $errorCode;
415 // Extension set? Then add it as well.
417 $url .= '&ext=' . $ext;
425 // Try to send a new password for the given user account
426 function doNewUserPassword ($email, $userid) {
427 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'email=' . $email . ',userid=' . $userid . ' - ENTERED!');
428 // Init found-status and error
430 $accountFound = false;
432 // Probe userid/nickname
433 if (!empty($email)) {
435 $accountFound = fetchUserData($email, 'email');
436 } elseif ((isExtensionActive('nickname')) && (isNicknameOrUserid($userid))) {
438 $accountFound = fetchUserData($userid, 'nickname');
439 } elseif ((isValidUserId($userid)) && (empty($email))) {
440 // Direct userid entered
441 $accountFound = fetchUserData($userid);
444 logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',email=' . $email . ': Important variables are empty.');
448 if ($accountFound === true) {
449 // Is the account confirmed
450 if (getUserData('status') == 'CONFIRMED') {
451 // Generate new password
452 $NEW_PASS = generatePassword();
455 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `password`='%s' WHERE `userid`=%s LIMIT 1",
456 array(generateHash($NEW_PASS), getUserData('userid')), __FUNCTION__, __LINE__);
458 // Prepare data and message for email
459 $message = loadEmailTemplate('guest_new_password',
461 'new_pass' => $NEW_PASS,
462 'nickname' => $userid
463 ), bigintval(getUserData('userid')));
465 // ... and send it away
466 sendEmail(bigintval(getUserData('userid')), '{--GUEST_NEW_PASSWORD--}', $message);
468 // Output note to user
469 displayMessage('{--GUEST_NEW_PASSWORD_SEND--}');
471 // Account is locked or unconfirmed
472 $errorCode = generateErrorCodeFromUserStatus(getUserData('status'));
475 redirectToUrl('modules.php?module=index&what=login&login=' . $errorCode);
478 // Id or email is wrong
479 displayMessage('<span class="bad">{--GUEST_WRONG_ID_EMAIL--}</span>');
482 // Return the error code
483 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'email=' . $email . ',userid=' . $userid . ',errorCode=' . $errorCode . ' - EXIT!');
487 // Get timestamp for given stats type and data
488 function getEpocheTimeFromUserStats ($statsType, $statsData, $userid = NULL) {
489 // Default timestamp is zero
490 $data['inserted'] = '0';
493 if ((isMemberIdSet()) && (is_null($userid))) {
494 $userid = getMemberId();
497 // Is the extension installed and updated?
498 if ((!isExtensionActive('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.6'))) {
500 return $data['inserted'];
503 // Try to find the entry
504 $result = SQL_QUERY_ESC("SELECT
505 UNIX_TIMESTAMP(`inserted`) AS inserted
507 `{?_MYSQL_PREFIX?}_user_stats_data`
510 `stats_type`='%s' AND
517 ), __FUNCTION__, __LINE__);
519 // Is the entry there?
520 if (SQL_NUMROWS($result) == 1) {
522 $data = SQL_FETCHARRAY($result);
526 SQL_FREERESULT($result);
529 return $data['inserted'];
532 // Inserts user stats
533 function insertUserStatsRecord ($userid, $statsType, $statsData) {
534 // Is the extension installed and updated?
535 if ((!isExtensionActive('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.6'))) {
540 // Default is not working
544 if ((!getEpocheTimeFromUserStats($statsType, $statsData, $userid)) && (!is_array($statsData))) {
546 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_stats_data` (`userid`,`stats_type`,`stats_data`) VALUES (%s,'%s','%s')",
551 ), __FUNCTION__, __LINE__);
553 // Does it have worked?
554 $return = (!SQL_HASZEROAFFECTED());
555 } elseif (is_array($statsData)) {
557 logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',type=' . $statsType . ',data=' . gettype($statsData) . ': Invalid statistics data type!');
564 // Confirms a user account
565 function doConfirmUserAccount ($hash) {
568 'message' => '{--GUEST_CONFIRMED_FAILED--}',
572 // Initialize the user id
575 // Search for an unconfirmed or confirmed account
576 $result = SQL_QUERY_ESC("SELECT `userid`,`refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
577 array($hash), __FILE__, __LINE__);
578 if (SQL_NUMROWS($result) == 1) {
579 // Ok, he want's to confirm now so we load some data
580 list($userid, $refid) = SQL_FETCHROW($result);
583 if (!fetchUserData($userid)) {
584 // Not found, should not happen
585 reportBug(__FILE__, __LINE__, 'User account ' . $userid . ' not found.');
588 // Load all data and add points
589 $content = getUserDataArray();
591 // Unlock his account (but only when it is on UNCONFIRMED!)
592 SQL_QUERY_ESC("UPDATE
593 `{?_MYSQL_PREFIX?}_user_data`
595 `status`='CONFIRMED',
599 `status`='UNCONFIRMED'
601 array($hash), __FILE__, __LINE__);
604 if (!SQL_HASZEROAFFECTED()) {
605 // Send email if updated
606 $message = loadEmailTemplate('guest_user_confirmed', $content, bigintval($userid));
608 // And send him right away the confirmation mail
609 sendEmail($userid, '{--GUEST_THANX_CONFIRM--}', $message);
611 // Maybe he got "referraled"?
612 if ((isValidUserId($refid)) && ($refid != $userid)) {
613 // Select the referral userid
614 if (fetchUserData($refid)) {
615 // Update ref counter...
616 updateReferralCounter($refid);
618 // If version matches add ref bonus to refid's account
619 if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
620 // Add points (directly only!)
621 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_ref`=`bonus_ref`+{?bonus_ref?} WHERE `userid`=%s LIMIT 1",
622 array(bigintval($refid)), __FILE__, __LINE__);
624 // Subtract points from system
625 handleBonusPoints(getConfig('bonus_ref'), $refid);
628 // Add one-time referral bonus over referral system or directly
629 initReferralSystem();
630 addPointsThroughReferralSystem('referral_bonus', $refid, getPointsRef(), bigintval($userid));
634 if (isExtensionActive('rallye')) {
635 // Add user to rallye (or not?)
636 addUserToReferralRallye(bigintval($userid));
639 // Account confirmed!
640 if (isExtensionActive('lead')) {
641 // Set special lead cookie
642 setSession('lead_userid', bigintval($userid));
644 // Lead-Code mode enabled
645 redirectToUrl('lead-confirm.php');
647 $content['message'] = '{--GUEST_CONFIRMED_DONE--}';
648 $content['userid'] = bigintval($userid);
650 } elseif (isExtensionActive('lead')) {
651 // Set special lead cookie
652 setSession('lead_userid', bigintval($userid));
654 // Lead-Code mode enabled
655 redirectToUrl('lead-confirm.php');
657 // Nobody was found unter this hash key... or our new member want's to confirm twice?
658 $content['message'] = '{--GUEST_CONFIRMED_TWICE--}';
661 // Nobody was found unter this hash key... or our new member want's to confirm twice?
662 $content['message'] = '{--GUEST_CONFIRMED_TWICE--}';
666 displayMessage($content['message']);
669 // Does resend the user's confirmation link for given email address
670 function doResendUserConfirmationLink ($email) {
671 // Email address not registered is default message
672 $message = '{--EMAIL_404--}';
674 // Confirmation link requested
675 if (fetchUserData($email, 'email')) {
676 // Email address found
677 $content = getUserDataArray();
679 // Is the account unconfirmed?
680 if ($content['status'] == 'UNCONFIRMED') {
681 // Load email template
682 $message = loadEmailTemplate('guest_request_confirm', array(), $content['userid']);
685 sendEmail($content['userid'], '{--GUEST_REQUEST_CONFIRM_LINK_SUBJECT--}', $message);
688 // Create message based on the status
689 $message = getConfirmationMessageFromUserStatus($content['status']);
693 displayMessage($message);
696 // Get a message (somewhat translation) from user status for confirmation link.
697 // This is different to translateUserStatus() in text messages.
698 function getConfirmationMessageFromUserStatus ($status) {
699 // Default is 'UNKNOWN'
700 $message = '{%message,GUEST_LOGIN_ID_UNKNOWN_STATUS=' . $status . '%}';
702 // Which status is it?
704 case 'UNCONFIRMED': // Account is unconfirmed
706 $message = '{--GUEST_CONFIRM_LINK_SENT--}';
709 case 'CONFIRMED': // Account already confirmed
710 $message = '{--GUEST_LOGIN_ID_CONFIRMED--}';
713 case 'LOCKED': // Account is locked
714 $message = '{--GUEST_LOGIN_ID_LOCKED--}';
717 default: // This should not happen
718 reportBug(__FUNCTION__, __LINE__, 'Unknown user status ' . $status . ' detected.');
726 // "Getter" for total tester accounts
727 function getTotalTesterUsers () {
729 if (!isset($GLOBALS[__FUNCTION__])) {
731 $GLOBALS[__FUNCTION__] = countSumTotalData('', 'user_data', 'userid', '', true, runFilterChain('user_inclusion_sql'));
735 return $GLOBALS[__FUNCTION__];
738 // Checks whether the admin is allowed to create more tester accounts
739 function isNewUserTesterAllowed () {
740 // By default only admins are allowed
742 // This should not happen and must be fixed
743 reportBug(__FUNCTION__, __LINE__, 'isAdmin()=false - Not allowed.');
746 // Are more tester accounts allowed?
747 $isAllowed = (getTotalTesterUsers() < bigintval(getTesterUserMaximum() + 1));
753 // "Getter" for next free tester account number
754 function getNextFreeTesterUserNumber () {
755 // Get current total amount because we start with zero
756 $nextTester = getTotalTesterUsers();
759 $nextTester = prependZeros($nextTester, 6);
765 // Wrapper function to return a selection box for tester user default referral id
766 function addTesterUserDefaultRefidSelectionBox ($fieldName = 'tester_user_default_refid') {
768 return addMemberSelectionBox(getConfig('tester_user_default_refid'), false, true, true, $fieldName, " WHERE `surname` LIKE '{?tester_user_surname_prefix?}%'");
771 // Checks whether given surname is a test user name
772 function isTesterUserName ($surname) {
774 return (substr($surname, 0, strlen(getTesterUserSurnamePrefix())) == getTesterUserSurnamePrefix());
777 // Creates a tester account from given POST data
778 function createTesterUserAccount () {
779 // Add generated surname
780 setPostRequestElement('surname', (getTesterUserSurnamePrefix() . getNextFreeTesterUserNumber()));
782 // Is the registration data complete?
783 if (!isRegistrationDataComplete()) {
785 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isRegistrationDataComplete()=false, please check if you e.g. have selected the required minimum of categories.');
790 $isCreated = doUserRegistration();
792 // Remove cache to force recalculation of total tester accounts
793 unset($GLOBALS['getTotalTesterUsers']);
799 //-----------------------------------------------------------------------------
801 //-----------------------------------------------------------------------------
803 // Expression call-back function for fetching user data
804 function doExpressionUser ($data) {
805 // Use current userid by default
806 $functionName = 'getMemberId()';
808 // User-related data, so is there a userid?
809 if (!empty($data['matches'][4][$data['key']])) {
810 // Do we have a userid or $userid?
811 if (substr($data['matches'][4][$data['key']], 0, 1) == '$') {
813 $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
814 } elseif (!empty($data['matches'][4][$data['key']])) {
815 // Do we have a number or a dollar sign in front of it?
816 if (preg_replace('/[^0123456789]/', '', $data['matches'][4][$data['key']]) != $data['matches'][4][$data['key']]) {
817 // Possible database column, so get it again
818 $data['matches'][4][$data['key']] = "getFetchedUserData('userid', getMemberId(), '" . $data['matches'][4][$data['key']] . "')";
822 $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
824 } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
825 // "Call-back" alias column for current logged in user's data
826 $functionName = "getUserData('" . $data['callback'] . "')";
829 // Do we have another function to run (e.g. translations)
830 if (!empty($data['extra_func'])) {
831 // Surround the original function call with it
832 $functionName = $data['extra_func'] . '(' . $functionName . ')';
834 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'functionName=' . $functionName);
837 $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}';
839 // Now replace the code
840 $code = replaceExpressionCode($data, $replacer);
842 // Return replaced code
846 //-----------------------------------------------------------------------------
847 // Template helper functions
848 //-----------------------------------------------------------------------------
850 // Template call-back function for list_user admin function
851 function doTemplateAdminListUserTitle ($template, $clear = false) {
852 // Init title with "all accounts"
853 $code = '{--ADMIN_LIST_ALL_ACCOUNTS--}';
855 // Do we have a 'status' or 'do' set?
856 if (isGetRequestElementSet('status')) {
857 // Set title according to the 'status'
858 $code = sprintf("{--ADMIN_LIST_STATUS_%s_ACCOUNTS--}", strtoupper(getRequestElement('status')));
859 } elseif (isGetRequestElementSet('do')) {
860 // Set title according to 'do'
861 $code = sprintf("{--ADMIN_LIST_DO_%s_ACCOUNTS--}", strtoupper(getRequestElement('do')));
868 // Template call-back function for displaying "username"
869 function doTemplateDisplayUsername ($template, $clear = false, $userid = NULL) {
871 if (!isValidUserId($userid)) {
872 // Please don't call this without a valid userid
873 reportBug(__FUNCTION__, __LINE__, 'template=' . $template . ',clear=' . intval($clear) . ',userid[' . gettype($userid) . ']=' . intval($userid) . ' - Invalid userid provided.');
877 if (!isset($GLOBALS[__FUNCTION__][$userid])) {
879 $GLOBALS[__FUNCTION__][$userid] = $userid . ' ({%user,nickname,fixEmptyContentToDashes=' . $userid . '%})';
883 return $GLOBALS[__FUNCTION__][$userid];
886 // ----------------------------------------------------------------------------
887 // Wrapper functions for configuration entries
888 // ----------------------------------------------------------------------------
890 // Getter for user_alpha
891 function getUserAlpha () {
893 if (!isset($GLOBALS[__FUNCTION__])) {
895 $GLOBALS[__FUNCTION__] = getConfig('user_alpha');
899 return $GLOBALS[__FUNCTION__];
902 // Getter for user_limit
903 function getUserLimit () {
905 if (!isset($GLOBALS[__FUNCTION__])) {
907 $GLOBALS[__FUNCTION__] = getConfig('user_limit');
911 return $GLOBALS[__FUNCTION__];
914 // Getter for tester_user_surname_prefix
915 function getTesterUserSurnamePrefix () {
917 if (!isset($GLOBALS[__FUNCTION__])) {
919 $GLOBALS[__FUNCTION__] = getConfig('tester_user_surname_prefix');
923 return $GLOBALS[__FUNCTION__];
926 // Getter for tester_user_maximum
927 function getTesterUserMaximum () {
929 if (!isset($GLOBALS[__FUNCTION__])) {
931 $GLOBALS[__FUNCTION__] = getConfig('tester_user_maximum');
935 return $GLOBALS[__FUNCTION__];
938 // Getter for tester_user_check_cat
939 function getTesterUserCheckCat () {
941 if (!isset($GLOBALS[__FUNCTION__])) {
943 $GLOBALS[__FUNCTION__] = getConfig('tester_user_check_cat');
947 return $GLOBALS[__FUNCTION__];
950 // Getter for tester_user_gender
951 function getTesterUserGender () {
953 if (!isset($GLOBALS[__FUNCTION__])) {
955 $GLOBALS[__FUNCTION__] = getConfig('tester_user_gender');
959 return $GLOBALS[__FUNCTION__];
962 // Getter for tester_user_family
963 function getTesterUserFamily () {
965 if (!isset($GLOBALS[__FUNCTION__])) {
967 $GLOBALS[__FUNCTION__] = getConfig('tester_user_family');
971 return $GLOBALS[__FUNCTION__];
974 // Getter for tester_user_password
975 function getTesterUserPassword () {
977 if (!isset($GLOBALS[__FUNCTION__])) {
979 $GLOBALS[__FUNCTION__] = getConfig('tester_user_password');
983 return $GLOBALS[__FUNCTION__];
986 // Getter for tester_user_street_nr
987 function getTesterUserStreetNr () {
989 if (!isset($GLOBALS[__FUNCTION__])) {
991 $GLOBALS[__FUNCTION__] = getConfig('tester_user_street_nr');
995 return $GLOBALS[__FUNCTION__];
998 // Getter for tester_user_zip
999 function getTesterUserZip () {
1000 // Do we have cache?
1001 if (!isset($GLOBALS[__FUNCTION__])) {
1003 $GLOBALS[__FUNCTION__] = getConfig('tester_user_zip');
1007 return $GLOBALS[__FUNCTION__];
1010 // Getter for tester_user_city
1011 function getTesterUserCity () {
1012 // Do we have cache?
1013 if (!isset($GLOBALS[__FUNCTION__])) {
1015 $GLOBALS[__FUNCTION__] = getConfig('tester_user_city');
1019 return $GLOBALS[__FUNCTION__];
1022 // Getter for tester_user_email
1023 function getTesterUserEmail () {
1024 // Do we have cache?
1025 if (!isset($GLOBALS[__FUNCTION__])) {
1027 $GLOBALS[__FUNCTION__] = getConfig('tester_user_email');
1031 return $GLOBALS[__FUNCTION__];