]> git.mxchange.org Git - mailer.git/blob - inc/libs/user_functions.php
07c71ce74169aace4be92cfbf7d6e64e03abc01d
[mailer.git] / inc / libs / user_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 07/16/2004 *
4  * ===================                          Last change: 10/27/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2016 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Add links for selecting some users
44 function addAlphabeticalSorting ($sortby) {
45         $add = '';
46         foreach (array('page', 'offset', 'do', 'status') as $param) {
47                 if (isGetRequestElementSet($param)) {
48                         $add .= '&amp;' . $param . '=' . getRequestElement($param);
49                 } // END - if
50         } // END - foreach
51
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;
55
56         // Add all letter links
57         $OUT = '';
58         while (list($counter, $ltr) = each($alphabet)) {
59                 if (getRequestElement('letter') == $ltr) {
60                         // Current letter is letter from URL
61                         $OUT .= '<strong>' . $ltr . '</strong>';
62                 } else {
63                         // Output link to letter
64                         $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat() . '&amp;letter=' . $ltr . '&amp;sortby=' . $sortby . $add . '%}">' . $ltr . '</a>';
65                 }
66
67                 if ((($counter / getUserAlpha()) == round($counter / getUserAlpha())) && ($counter > 0)) {
68                         $OUT .= ']<br />[';
69                 } elseif ($counter != $num) {
70                         $OUT .= '|';
71                 }
72         } // END - while
73
74         // Prepare content
75         $content = array (
76                 'alpha_selection' => $OUT,
77         );
78
79         // Load template
80         $OUT = loadTemplate('admin_list_user_alpha', TRUE, $content);
81
82         // Return generated code
83         return $OUT;
84 }
85
86 // Add links for sorting
87 function addSortLinks ($letter, $sortby) {
88         $OUT = '';
89         if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', 0);
90         if (!isGetRequestElementSet('page'))   setGetRequestElement('page'  , 0);
91
92         // Add page and offset
93         $add = '&amp;page=' . getRequestElement('page') . '&amp;offset=' . getRequestElement('offset');
94
95         // Add status/ mode
96         foreach (array('do','status') as $param) {
97                 if (isGetRequestElementSet($param)) {
98                         $add .= '&amp;' . $param . '=' . getRequestElement($param);
99                 } // END - if
100         } // END - foreach
101
102         // Makes order by links..
103         if ($letter == 'front') {
104                 $letter = '';
105         } // END - if
106
107         // Prepare array with all possible sorters
108         $list = array(
109                 'userid'      => '{--_USERID--}',
110                 'family'      => '{--FAMILY--}',
111                 'email'       => '{--EMAIL--}',
112                 'REMOTE_ADDR' => '{--REMOTE_IP--}'
113         );
114
115         // Add nickname if extension is installed
116         if (isExtensionActive('nickname')) {
117                 $list['nickname'] = '{--NICKNAME--}';
118         } // END - if
119
120         foreach ($list as $sort => $title) {
121                 if ($sortby == $sort) {
122                         $OUT .= '<strong>' . $title . '</strong>|';
123                 } else {
124                         $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=list_user&amp;letter=' . $letter . '&amp;sortby=' . $sort . $add . '%}">' . $title . '</a>|';
125                 }
126         } // END - foreach
127
128         // Add output
129         $content['list'] = substr($OUT, 0, -1);
130
131         // Load template
132         $OUT = loadTemplate('admin_list_user_sort', TRUE, $content);
133
134         // Return code
135         return $OUT;
136 }
137
138 // Add page navigation
139 function addPageNavigation ($numPages) {
140         // Start with empty content
141         $OUT = '';
142
143         // Create only the navigation if page count > 1
144         if ($numPages > 1) {
145                 // Create navigation links for every page
146                 for ($page = 1; $page <= $numPages; $page++) {
147                         if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
148                                 $OUT .= '<strong>-';
149                         } else {
150                                 if (!isGetRequestElementSet('letter')) setGetRequestElement('letter', '');
151                                 if (!isGetRequestElementSet('sortby')) setGetRequestElement('sortby', 'userid');
152
153                                 // Base link
154                                 $OUT .= '<a href="{%url=modules.php?module=admin&amp;what=' . getWhat();
155
156                                 // Add status/mode
157                                 foreach (array('do','status') as $param) {
158                                         if (isGetRequestElementSet($param)) {
159                                                 $OUT .= '&amp;' . $param . '=' . getRequestElement($param);
160                                         } // END - if
161                                 } // END - foreach
162
163                                 // Letter and so on
164                                 $OUT .= '&amp;letter=' . getRequestElement('letter') . '&amp;sortby=' . getRequestElement('sortby') . '&amp;page=' . $page . '&amp;offset=' . getUserLimit() . '%}">';
165                         }
166
167                         $OUT .= $page;
168
169                         if (($page == getRequestElement('page')) || ((!isGetRequestElementSet('page')) && ($page == 1))) {
170                                 $OUT .= '-</strong>';
171                         } else  {
172                                 $OUT .= '</a>';
173                         }
174
175                         if ($page < $numPages) {
176                                 $OUT .= '|';
177                         } // END - if
178                 } // END - for
179
180                 // Add list output
181                 $content['list'] = $OUT;
182
183                 // Load template
184                 $OUT = loadTemplate('admin_list_user_pagenav', TRUE, $content);
185         } // END - if
186
187         // Return code
188         return $OUT;
189 }
190
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'";
195
196         // But admins shall always see it
197         if (isAdmin()) {
198                 $locked = '';
199         } // END - if
200
201         // Search for the email address
202         $result = sqlQueryEscaped("SELECT
203         `userid`
204 FROM
205         `{?_MYSQL_PREFIX?}_user_data`
206 WHERE
207         '%s' REGEXP `email`
208         " . $locked . "
209 LIMIT 1",
210                 array($email), __FUNCTION__, __LINE__);
211
212         // Is there an entry?
213         if (sqlNumRows($result) == 1) {
214                 // Load userid
215                 list($userid) = sqlFetchRow($result);
216
217                 // Rewrite email address to contact link
218                 $email = '{%url=modules.php?module=' . $mod . '&amp;what=user_contct&amp;userid=' . bigintval($userid) . '%}';
219         } // END - if
220
221         // Free memory
222         sqlFreeResult($result);
223
224         // Return rewritten (?) email address
225         return $email;
226 }
227
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
231         $refid = NULL;
232
233         // Is the extension version fine?
234         if ((isRandomReferralIdEnabled()) && (isExtensionInstalledAndNewer('user', '0.3.4'))) {
235                 // Get all user ids
236                 $totalUsers = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `rand_confirmed` >= {?user_min_confirmed?}'));
237
238                 // Is there at least one?
239                 if ($totalUsers > 0) {
240                         // Then choose random userid
241                         $randUserid = mt_rand(0, ($totalUsers - 1));
242
243                         // Look for random user
244                         $result = sqlQueryEscaped("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__);
246
247                         // Is there one entry there?
248                         if (sqlNumRows($result) == 1) {
249                                 // Use that userid as new referral id
250                                 list($refid) = sqlFetchRow($result);
251
252                                 // Debug message
253                                 /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'refid=' . $refid . ' - choosen!');
254                         } // END - if
255
256                         // Free result
257                         sqlFreeResult($result);
258                 } // END - if
259         } // END - if
260
261         // Return result
262         return $refid;
263 }
264
265 // Do the user login
266 function doUserLogin ($userid, $passwd, $successUrl = '', $errorUrl = 'modules.php?module=index&amp;what=login&amp;login=') {
267         // Init variables
268         $dmy = '';
269         $add = '';
270         $errorCode = '0';
271         $ext = '';
272         $isFound = FALSE;
273
274         // Init array
275         $content = array(
276                 'password'    => '',
277                 'userid'      => '',
278                 'last_online' => 0,
279                 'last_login'  => 0,
280                 'hash'        => ''
281         );
282
283         // Check login data
284         if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
285                 // Nickname entered
286                 $isFound = fetchUserData($userid, 'nickname');
287         } elseif (isNicknameUsed($userid)) {
288                 // No nickname installed
289                 $errorCode = getCode('EXTENSION_PROBLEM');
290                 $ext = 'nickname';
291         } else {
292                 // Direct userid entered
293                 $isFound = fetchUserData($userid);
294         }
295
296         // No error found?
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']);
302                 } // END - if
303         } // END - if
304
305         // Debug message
306         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',isValidUserData()=' . intval(isValidUserData()) . ',userStatus=' . getUserData('status') . ',errorCode=' . $errorCode . ',ext=' . $ext . ',isFound=' . intval($isFound));
307
308         // Is there an entry?
309         if (($errorCode == '0') && (isValidUserData()) && (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');
314                 } else {
315                         // Hash password with improved way for comparsion
316                         $content['hash'] = generateHash($passwd, substr(getUserData('password'), 0, -40));
317                 }
318
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);
323
324                         // ... and update database
325                         // @TODO Make this filter working: $ADDON = runFilterChain('post_login_update', $content);
326                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `password`='%s' WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
327                                 array($content['hash'], $userid), __FUNCTION__, __LINE__);
328
329                         // No login bonus by default
330                         $GLOBALS['bonus_payed'] = FALSE;
331
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');
339                                 } // END - if
340
341                                 // Is the timeout reached?
342                                 if ($probe >= getLoginTimeout()) {
343                                         // Add login bonus to user's account
344                                         $add = ',`login_bonus`=`login_bonus`+{?login_bonus?}';
345                                         $GLOBALS['bonus_payed'] = TRUE;
346
347                                         // Subtract login bonus from userid's account or jackpot
348                                         if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD')) {
349                                                 handleBonusPoints('login_bonus', $userid);
350                                         } // END - if
351                                 } // END - if
352                         } // END - if
353
354                         // @TODO Make this filter working: $url = runFilterChain('do_login', array('content' => $content, 'addon' => $ADDON));
355
356                         // Set member id
357                         setMemberId($userid);
358
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                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `total_logins`=`total_logins`+1" . $add . " WHERE `userid`=%s LIMIT 1",
364                                         array($userid), __FUNCTION__, __LINE__);
365                                 if (!ifSqlHasZeroAffectedRows()) {
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&amp;do=bonus';
372                                                 } else {
373                                                         // Bonus not added
374                                                         $url = 'modules.php?module=chk_login&amp;do=login';
375                                                 }
376                                         } else {
377                                                 // Use this URL
378                                                 $url = $successUrl;
379                                         }
380                                 } else {
381                                         // Cannot update counter!
382                                         $errorCode = getCode('CNTR_FAILED');
383                                 }
384                         } else {
385                                 // Cookies not setable!
386                                 $errorCode = getCode('COOKIES_DISABLED');
387                         }
388                 } elseif (isExtensionInstalledAndNewer('sql_patches', '0.6.1')) {
389                         // Update failure counter
390                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `login_failures`=`login_failures`+1,`last_failure`=NOW() WHERE `userid`=%s LIMIT 1",
391                                 array($userid), __FUNCTION__, __LINE__);
392
393                         // Wrong password!
394                         $errorCode = getCode('WRONG_PASS');
395                 }
396         } elseif ((isValidUserData()) && (getUserData('status') != 'CONFIRMED')) {
397                 // Create an error code from given status
398                 $errorCode = generateErrorCodeFromUserStatus(getUserData('status'));
399
400                 // Set userid in session
401                 setSession('userid', getUserData('userid'));
402         } elseif (!isValidUserData()) {
403                 // User id not found
404                 $errorCode = getCode('WRONG_ID');
405         } else {
406                 // Unknown error
407                 $errorCode = getCode('UNKNOWN_ERROR');
408         }
409
410         // Error code provided?
411         if ($errorCode > 0) {
412                 // Then reconstruct the URL
413                 $url = $errorUrl . $errorCode;
414
415                 // Extension set? Then add it as well.
416                 if (!empty($ext)) {
417                         $url .= '&amp;ext=' . $ext;
418                 } // END - if
419         } // END - if
420
421         // Return URL
422         return $url;
423 }
424
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
429         $errorCode = '';
430         $accountFound = FALSE;
431
432         // Probe userid/nickname
433         if (!empty($email)) {
434                 // Email entered
435                 $accountFound = fetchUserData($email, 'email');
436         } elseif ((isExtensionActive('nickname')) && (isNicknameOrUserid($userid))) {
437                 // Nickname entered
438                 $accountFound = fetchUserData($userid, 'nickname');
439         } elseif ((isValidId($userid)) && (empty($email))) {
440                 // Direct userid entered
441                 $accountFound = fetchUserData($userid);
442         } elseif (isDebugModeEnabled()) {
443                 // Userid not set!
444                 logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',email=' . $email . ': Important variables are empty.');
445         }
446
447         // Any entry found?
448         if ($accountFound === TRUE) {
449                 // Is the account confirmed
450                 if (getUserData('status') == 'CONFIRMED') {
451                         // Generate new password
452                         $newPassword = generatePassword();
453
454                         // Update database
455                         sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `password`='%s' WHERE `userid`=%s LIMIT 1",
456                                 array(
457                                         generateHash($newPassword),
458                                         getUserData('userid')
459                                 ), __FUNCTION__, __LINE__);
460
461                         // Prepare data and message for email
462                         $message = loadEmailTemplate('guest_new_password',
463                                 array(
464                                         'new_pass' => $newPassword,
465                                         'nickname' => $userid
466                                 ), getUserData('userid'));
467
468                         // ... and send it away
469                         sendEmail(bigintval(getUserData('userid')), '{--GUEST_NEW_PASSWORD_SUBJECT--}', $message);
470
471                         // Output note to user
472                         displayMessage('{--GUEST_NEW_PASSWORD_SEND--}');
473                 } else {
474                         // Account is locked or unconfirmed
475                         $errorCode = generateErrorCodeFromUserStatus(getUserData('status'));
476
477                         // Load URL
478                         redirectToUrl('modules.php?module=index&amp;what=login&amp;login=' . $errorCode);
479                 }
480         } else {
481                 // Id or email is wrong
482                 displayMessage('<span class="bad">{--GUEST_WRONG_ID_EMAIL--}</span>');
483         }
484
485         // Return the error code
486         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'email=' . $email . ',userid=' . $userid . ',errorCode=' . $errorCode . ' - EXIT!');
487         return $errorCode;
488 }
489
490 // Get timestamp for given stats type and data
491 function getEpocheTimeFromUserStats ($statsType, $statsData, $userid = NULL) {
492         // Default timestamp is zero
493         $data['inserted'] = '0';
494
495         // User id set?
496         if ((isMemberIdSet()) && (is_null($userid))) {
497                 $userid = getMemberId();
498         } // END - if
499
500         // Is the extension installed and updated?
501         if ((!isExtensionActive('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.6'))) {
502                 // Return zero here
503                 return $data['inserted'];
504         } // END - if
505
506         // Try to find the entry
507         $result = sqlQueryEscaped("SELECT
508         UNIX_TIMESTAMP(`inserted`) AS `inserted`
509 FROM
510         `{?_MYSQL_PREFIX?}_user_stats_data`
511 WHERE
512         `userid`=%s AND
513         `stats_type`='%s' AND
514         `stats_data`='%s'
515 LIMIT 1",
516                 array(
517                         bigintval($userid),
518                         $statsType,
519                         $statsData
520                 ), __FUNCTION__, __LINE__);
521
522         // Is the entry there?
523         if (sqlNumRows($result) == 1) {
524                 // Get this stamp
525                 $data = sqlFetchArray($result);
526         } // END - if
527
528         // Free result
529         sqlFreeResult($result);
530
531         // Return stamp
532         return $data['inserted'];
533 }
534
535 // Inserts user stats
536 function insertUserStatsRecord ($userid, $statsType, $statsData) {
537         // Is the extension installed and updated?
538         if ((!isExtensionActive('sql_patches')) || (isExtensionInstalledAndOlder('sql_patches', '0.5.6'))) {
539                 // Return zero here
540                 return FALSE;
541         } // END - if
542
543         // Default is not working
544         $return = FALSE;
545
546         // Does it exist?
547         if ((!getEpocheTimeFromUserStats($statsType, $statsData, $userid)) && (!is_array($statsData))) {
548                 // Then insert it!
549                 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_stats_data` (`userid`, `stats_type`, `stats_data`) VALUES (%s,'%s','%s')",
550                         array(
551                                 bigintval($userid),
552                                 $statsType,
553                                 $statsData
554                         ), __FUNCTION__, __LINE__);
555
556                 // Does it have worked?
557                 $return = (!ifSqlHasZeroAffectedRows());
558         } elseif (is_array($statsData)) {
559                 // Invalid data!
560                 logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',type=' . $statsType . ',data=' . gettype($statsData) . ': Invalid statistics data type!');
561         }
562
563         // Return status
564         return $return;
565 }
566
567 // Confirms a user account
568 function doConfirmUserAccount ($hash) {
569         // Init content
570         $content = array(
571                 'message' => '{--GUEST_CONFIRMED_FAILED--}',
572                 'userid'  => 0,
573         );
574
575         // Initialize the user id
576         $userid = NULL;
577
578         // Search for an unconfirmed or confirmed account
579         $result = sqlQueryEscaped("SELECT `userid`, `refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `user_hash`='%s' AND (`status`='UNCONFIRMED' OR `status`='CONFIRMED') LIMIT 1",
580                 array($hash), __FILE__, __LINE__);
581
582         // One result should be found
583         if (ifSqlHasZeroNumRows($result)) {
584                 // Nothing found or tried to confirm twice?
585                 displayMessage('{--GUEST_CONFIRMED_TWICE--}');
586                 return;
587         } // END - if
588
589         // Okay, the user want's to confirm now so we load some data
590         list($userid, $refid) = sqlFetchRow($result);
591
592         // Fetch user data
593         if (!fetchUserData($userid)) {
594                 // Not found, should not happen
595                 reportBug(__FILE__, __LINE__, 'User account ' . $userid . ' not found.');
596         } // END - if
597
598         // Load all data and add points
599         $content = merge_array($content, getUserDataArray());
600
601         // Is 'user' updated?
602         if (isExtensionInstalledAndNewer('user', '0.6.3')) {
603                 // Unlock his account (but only when it is on UNCONFIRMED!)
604                 sqlQueryEscaped("UPDATE
605         `{?_MYSQL_PREFIX?}_user_data`
606 SET
607         `status`='CONFIRMED',
608         `user_hash`=NULL,
609         `confirmed_timestamp`=NOW(),
610         `confirmed_ip_address`='%s'
611 WHERE
612         `user_hash`='%s' AND
613         `status`='UNCONFIRMED'
614 LIMIT 1",
615                         array(
616                                 determineRealRemoteAddress(),
617                                 $hash
618                         ), __FILE__, __LINE__
619                 );
620         } else {
621                 // Unlock his account (but only when it is on UNCONFIRMED!)
622                 sqlQueryEscaped("UPDATE
623         `{?_MYSQL_PREFIX?}_user_data`
624 SET
625         `status`='CONFIRMED',
626         `user_hash`=NULL
627 WHERE
628         `user_hash`='%s' AND
629         `status`='UNCONFIRMED'
630 LIMIT 1",
631                         array(
632                                 $hash
633                         ), __FILE__, __LINE__
634                 );
635         }
636
637         // Was it updated?
638         if (ifSqlHasZeroAffectedRows()) {
639                 // Nobody was found unter this hash key... or our new member want's to confirm twice?
640                 displayMessage('{--GUEST_CONFIRMED_TWICE--}');
641                 return;
642         } // END - if
643
644         // Load email template
645         $message = loadEmailTemplate('guest_user_confirmed', $content, bigintval($userid));
646
647         // And send him right away the confirmation mail
648         sendEmail($userid, '{--GUEST_THANX_CONFIRM--}', $message);
649
650         // Maybe he got "referraled"?
651         if ((isValidId($refid)) && ($refid != $userid)) {
652                 // Select the referral userid
653                 if (fetchUserData($refid)) {
654                         // Update ref counter...
655                         updateReferralCounter($refid);
656
657                         // If version matches add ref bonus to refid's account
658                         if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
659                                 // Add points (directly only!)
660                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_ref`=`bonus_ref`+{?bonus_ref?} WHERE `userid`=%s LIMIT 1",
661                                         array(bigintval($refid)), __FILE__, __LINE__);
662
663                                 // Subtract points from system
664                                 handleBonusPoints(getBonusRef(), $refid);
665                         } // END - if
666
667                         // Add one-time referral bonus over referral system or directly
668                         initReferralSystem();
669                         addPointsThroughReferralSystem('referral_bonus', $refid, getPointsRef(), bigintval($userid));
670                 } // END - if
671         } // END - if
672
673         // @TODO Rewrite this to 2 filters as a possible redirect must always come last
674         if (isExtensionActive('rallye')) {
675                 // Add user to rallye (or not?)
676                 addUserToReferralRallye(bigintval($userid));
677         } // END - if
678
679         // Account confirmed!
680         if (isExtensionActive('lead')) {
681                 // Set special lead cookie
682                 setSession('lead_userid', bigintval($userid));
683
684                 // Lead-Code mode enabled
685                 redirectToUrl('lead-confirm.php');
686         } else {
687                 // Regular confirmation
688                 $content['message'] = '{--GUEST_CONFIRMED_DONE--}';
689                 $content['userid']  = bigintval($userid);
690         }
691
692         // Load template
693         displayMessage($content['message']);
694 }
695
696 // Does resend the user's confirmation link for given email address
697 function doResendUserConfirmationLink ($email) {
698         // Email address not registered is default message
699         $message = '{--EMAIL_404--}';
700
701         // Confirmation link requested
702         if (fetchUserData($email, 'email')) {
703                 // Email address found
704                 $content = getUserDataArray();
705
706                 // Is the account unconfirmed?
707                 if ($content['status'] == 'UNCONFIRMED') {
708                         // Load email template
709                         $message = loadEmailTemplate('guest_request_confirm', [], $content['userid']);
710
711                         // Send email
712                         sendEmail($content['userid'], '{--GUEST_REQUEST_CONFIRM_LINK_SUBJECT--}', $message);
713                 } // END - if
714
715                 // Create message based on the status
716                 $message = getConfirmationMessageFromUserStatus($content['status']);
717         } // END - if
718
719         // Output message
720         displayMessage($message);
721 }
722
723 // Get a message (somewhat translation) from user status for confirmation link.
724 // This is different to translateUserStatus() in text messages.
725 function getConfirmationMessageFromUserStatus ($status) {
726         // Default is 'UNKNOWN'
727         $message = '{%message,GUEST_LOGIN_ID_UNKNOWN_STATUS=' . $status . '%}';
728
729         // Which status is it?
730         switch ($status) {
731                 case 'UNCONFIRMED': // Account is unconfirmed
732                         // And set message
733                         $message = '{--GUEST_CONFIRM_LINK_SENT--}';
734                         break;
735
736                 case 'CONFIRMED': // Account already confirmed
737                         $message = '{--GUEST_LOGIN_ID_CONFIRMED--}';
738                         break;
739
740                 case 'LOCKED': // Account is locked
741                         $message = '{--GUEST_LOGIN_ID_LOCKED--}';
742                         break;
743
744                 default: // This should not happen
745                         reportBug(__FUNCTION__, __LINE__, 'Unknown user status ' . $status . ' detected.');
746                         break;
747         } // END - switch
748
749         // Return message
750         return $message;
751 }
752
753 // "Getter" for total tester accounts
754 function getTotalTesterUsers () {
755         // Is there cache?
756         if (!isset($GLOBALS[__FUNCTION__])) {
757                 // Determine it
758                 $GLOBALS[__FUNCTION__] = countSumTotalData('', 'user_data', 'userid', '', TRUE, runFilterChain('user_inclusion_sql'));
759         } // END - if
760
761         // Return cache
762         return $GLOBALS[__FUNCTION__];
763 }
764
765 // Checks whether the admin is allowed to create more tester accounts
766 function isNewUserTesterAllowed () {
767         // By default only admins are allowed
768         if (!isAdmin()) {
769                 // This should not happen and must be fixed
770                 reportBug(__FUNCTION__, __LINE__, 'isAdmin()=false - Not allowed.');
771         } // END - if
772
773         // Are more tester accounts allowed?
774         $isAllowed = (getTotalTesterUsers() < bigintval(getTesterUserMaximum() + 1));
775
776         // Return result
777         return $isAllowed;
778 }
779
780 // "Getter" for next free tester account number
781 function getNextFreeTesterUserNumber () {
782         // Get current total amount because we start with zero
783         $nextTester = getTotalTesterUsers();
784
785         // Prepend zeros
786         $nextTester = padLeftZero($nextTester, 6);
787
788         // Return it
789         return $nextTester;
790 }
791
792 // Wrapper function to return a selection box for tester user default referral id
793 function addTesterUserDefaultRefidSelectionBox ($fieldName = 'tester_user_default_refid') {
794         // Return it
795         return addMemberSelectionBox(getConfig('tester_user_default_refid'), FALSE, TRUE, TRUE, $fieldName, " WHERE `surname` LIKE '{?tester_user_surname_prefix?}%'");
796 }
797
798 // Checks whether given surname is a test user name
799 function isTesterUserName ($surname) {
800         // Determine it
801         return (substr($surname, 0, strlen(getTesterUserSurnamePrefix())) == getTesterUserSurnamePrefix());
802 }
803
804 // Creates a tester account from given POST data
805 function createTesterUserAccount () {
806         // Add generated surname
807         setPostRequestElement('surname', (getTesterUserSurnamePrefix() . getNextFreeTesterUserNumber()));
808
809         // Is the registration data complete?
810         if (!isRegistrationDataComplete()) {
811                 // Then abort here
812                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isRegistrationDataComplete()=false, please check if you e.g. have selected the required minimum of categories.');
813                 return FALSE;
814         } // END - if
815
816         // Do registration
817         $isCreated = doUserRegistration();
818
819         // Remove cache to force recalculation of total tester accounts
820         unset($GLOBALS['getTotalTesterUsers']);
821
822         // Return status
823         return $isCreated;
824 }
825
826 // Checks whether the given sub id is fused by current member
827 function isMemberSubIdFree ($subId) {
828         // Only do this for logged-in members
829         assert(isMember());
830
831         // Check it
832         $isFree = (countSumTotalData(getMemberId(), 'user_subids', 'id', 'userid', TRUE, sprintf(" AND `subid`='%s'", $subId)) == 0);
833
834         // Return result
835         return $isFree;
836 }
837
838 // Checks whether the sub id is valid
839 function isValidSubId ($subId) {
840         // First convert any spaces/dashes to underscores
841         $subId = str_replace(' ', '_', str_replace('-', '_', $subId));
842
843         // Then filter out any unwanted characters
844         $subIdTest = preg_replace('/([^a-zA-Z0-9_])/', '', $subId);
845
846         // Is it valid?
847         return ($subId == $subIdTest);
848 } // END - if
849
850 // Prepares found sub id for updating in database
851 function prepareFoundSubId ($subId) {
852         // Then check if it is valid and available
853         if ((!isValidSubId($subId)) || (isMemberSubIdFree($subId))) {
854                 // Is not free or invalid
855                 $subId = FALSE;
856         } // END - if
857
858         // Return prepared sub id
859         return $subId;
860 }
861
862 // Validates sub id and returns FALSE if not valid
863 function validateSubId ($subId) {
864         // Then check if it is valid and available
865         if (!isValidSubId($subId)) {
866                 // Is not free or invalid
867                 $subId = FALSE;
868         } // END - if
869
870         // Return prepared sub id
871         return $subId;
872 }
873
874 // Prepares given sub id for inserting into database
875 function prepareSubId ($subId) {
876         // Then check if it is valid and available
877         if ((!isValidSubId($subId)) || (!isMemberSubIdFree($subId))) {
878                 // Is not free or invalid
879                 $subId = FALSE;
880         } // END - if
881
882         // Return prepared sub id
883         return $subId;
884 }
885
886 // Check whether given sub *id* is assigned to current member
887 function isUserSubIdAssignedToMember ($subId, $userid = NULL) {
888         // Is there cache?
889         if (!isset($GLOBALS[__FUNCTION__][$subId][$userid])) {
890                 // Determine it
891                 $GLOBALS[__FUNCTION__][$subId][$userid] = (
892                         (
893                                 // Is a userid set or current set?
894                                 (isValidId($userid)) || (isMember())
895                         ) && (
896                                 // .. and it assigned with subid's id?
897                                 countSumTotalData(
898                                         (isValidId($userid) ? $userid : getMemberId()),
899                                                 'user_subids',
900                                                 'id',
901                                                 'userid',
902                                                 TRUE,
903                                                 sprintf(' AND `id`=%s', bigintval($subId))
904                                 ) == 1
905                         )
906                 );
907         } // END - if
908
909         // Return cache
910         return $GLOBALS[__FUNCTION__][$subId][$userid];
911 }
912
913 // Getter for subid from given id number
914 function getSubId ($id) {
915         // Is there cache?
916         if (!isset($GLOBALS[__FUNCTION__][$id])) {
917                 // Check database for record
918                 $result = sqlQueryEscaped("SELECT `subid` FROM `{?_MYSQL_PREFIX?}_user_subids` WHERE `id`=%s LIMIT 1",
919                         array(bigintval($id)), __FUNCTION__, __LINE__);
920
921                 // Is there an entry?
922                 if (sqlNumRows($result) == 1) {
923                         // Load it
924                         list($GLOBALS[__FUNCTION__][$id]) = sqlFetchRow($result);
925                 } // END - if
926
927                 // Free result
928                 sqlFreeResult($result);
929         } // END - if
930
931         // Return cache
932         return $GLOBALS[__FUNCTION__][$id];
933 }
934
935 // "Getter for total count of current user's sub ids
936 function getTotalMemberSubIds () {
937         // Only do this for logged-in members
938         assert(isMember());
939
940         // Is there cache?
941         if (!isset($GLOBALS[__FUNCTION__])) {
942                 // Determine it
943                 $GLOBALS[__FUNCTION__] = countSumTotalData(getMemberId(), 'user_subids', 'id', 'userid', TRUE);
944         } // END - if
945
946         // Return cache
947         return $GLOBALS[__FUNCTION__];
948 }
949
950 // Displays generic user registration form
951 function doDisplayGenericUserRegistrationForm () {
952         // Do this only if form is sent
953         if (isFormSent()) {
954                 if (postRequestElement('agree') == '!') {
955                         registerOutputFailedMessage('HAVE_TO_AGREE');
956                 } // END - if
957
958                 if (postRequestElement('email') == '!') {
959                         registerOutputFailedMessage('ENTER_EMAIL');
960                         setPostRequestElement('email', '');
961                 } elseif (postRequestElement('email') == '?') {
962                         registerOutputFailedMessage('GUEST_EMAIL_IS_ALREADY_REGISTERED');
963                         setPostRequestElement('email', '');
964                 }
965
966                 if (postRequestElement('surname') == '!') {
967                         registerOutputFailedMessage('ENTER_SURNAME');
968                         setPostRequestElement('surname', '');
969                 } // END - if
970
971                 if (postRequestElement('family') == '!') {
972                         registerOutputFailedMessage('ENTER_FAMILY');
973                         setPostRequestElement('family', '');
974                 } // END - if
975
976                 if ((postRequestElement('password1') == '!') && (postRequestElement('password2') == '!')) {
977                         registerOutputFailedMessage('ENTER_BOTH_PASSWORDS');
978                 } elseif (postRequestElement('password1') == '!') {
979                         registerOutputFailedMessage('ENTER_PASSWORD1');
980                 } elseif (postRequestElement('password2') == '!') {
981                         registerOutputFailedMessage('ENTER_PASSWORD2');
982                 }
983
984                 if ((isset($GLOBALS['registration_weak_password'])) && ($GLOBALS['registration_weak_password'] === TRUE)) {
985                         registerOutputFailedMessage('GUEST_WEAK_PASSWORD');
986                 } // END - if
987
988                 if ((isset($GLOBALS['registration_ip_timeout'])) && ($GLOBALS['registration_ip_timeout'] === TRUE)) {
989                         registerOutputFailedMessage('REMOTE_ADDR_TIMEOUT');
990                 } // END - if
991
992                 if ((!empty($GLOBALS['registration_selected_cats'])) && ($GLOBALS['registration_selected_cats'] < getLeastCats())) {
993                         registerOutputFailedMessage('', '{--CHOOSE_MORE_CATEGORIES--}');
994                 } // END - if
995         } // END - if
996
997         // Generate birthday selection
998         $content['birthday_selection'] = generateDayMonthYearSelectionBox(postRequestElement('day'),postRequestElement('month'),postRequestElement('year'));
999
1000         // ZIP codes are numerical values
1001         $content['zip'] = '';
1002         if ((isPostRequestElementSet('zip')) && (isValidNumber(postRequestElement('zip')))) {
1003                 $content['zip'] = bigintval(postRequestElement('zip'));
1004         } // END - if
1005
1006         // Other values
1007         foreach (array('gender', 'surname', 'family', 'street_nr', 'city', 'email') as $entry) {
1008                 $content[$entry] = sqlEscapeString(postRequestElement($entry));
1009         } // END - foreach
1010
1011         // Set must-fillout fields
1012         $content = runFilterChain('register_must_fillout', $content);
1013
1014         // Display registration form
1015         loadTemplate('guest_register', FALSE, $content);
1016 }
1017
1018 //-----------------------------------------------------------------------------
1019 //                                EL code functions
1020 //-----------------------------------------------------------------------------
1021
1022 // Expression call-back function for fetching user data
1023 function doExpressionUser ($data) {
1024         // Use current userid by default
1025         $functionName = 'getMemberId()';
1026
1027         // User-related data, so is there a userid?
1028         if (!empty($data['matches'][4][$data['key']])) {
1029                 // Is there a userid or $userid?
1030                 if (substr($data['matches'][4][$data['key']], 0, 1) == '$') {
1031                         // Use dynamic call
1032                         $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
1033                 } elseif (!empty($data['matches'][4][$data['key']])) {
1034                         // Is there a number or a dollar sign in front of it?
1035                         if (preg_replace('/[^0123456789]/', '', $data['matches'][4][$data['key']]) != $data['matches'][4][$data['key']]) {
1036                                 // Possible database column, so get it again
1037                                 $data['matches'][4][$data['key']] = "getFetchedUserData('userid', getMemberId(), '" . $data['matches'][4][$data['key']] . "')";
1038                         } // END - if
1039
1040                         // Fix all together
1041                         $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
1042                 }
1043         } elseif ((!empty($data['callback'])) && (isValidUserData())) {
1044                 // "Call-back" alias column for current logged in user's data
1045                 $functionName = "getUserData('" . $data['callback'] . "')";
1046         }
1047
1048         // Is there another function to run (e.g. translations)
1049         if (!empty($data['extra_func'])) {
1050                 // Surround the original function call with it
1051                 $functionName = $data['extra_func'] . '(' . $functionName . ')';
1052         } // END - if
1053         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'functionName=' . $functionName);
1054
1055         // Generate replacer
1056         $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}';
1057
1058         // Now replace the code
1059         $code = replaceExpressionCode($data, $replacer);
1060
1061         // Return replaced code
1062         return $code;
1063 }
1064
1065 //-----------------------------------------------------------------------------
1066 //                             Template helper functions
1067 //-----------------------------------------------------------------------------
1068
1069 // Template call-back function for list_user admin function
1070 function doTemplateAdminListUserTitle ($template, $clear = FALSE) {
1071         // Init title with "all accounts"
1072         $code = '{--ADMIN_LIST_ALL_ACCOUNTS--}';
1073
1074         // Is there a 'status' or 'do' set?
1075         if (isGetRequestElementSet('status')) {
1076                 // Set title according to the 'status'
1077                 $code = sprintf("{--ADMIN_LIST_STATUS_%s_ACCOUNTS--}", strtoupper(getRequestElement('status')));
1078         } elseif (isGetRequestElementSet('do')) {
1079                 // Set title according to 'do'
1080                 $code = sprintf("{--ADMIN_LIST_DO_%s_ACCOUNTS--}", strtoupper(getRequestElement('do')));
1081         }
1082
1083         // Return the code
1084         return $code;
1085 }
1086
1087 // Template call-back function for displaying "username"
1088 function doTemplateDisplayUsername ($template, $clear = FALSE, $userid = NULL) {
1089         // Is a userid set?
1090         if (!isValidId($userid)) {
1091                 // Please don't call this without a valid userid
1092                 reportBug(__FUNCTION__, __LINE__, 'template=' . $template . ',clear=' . intval($clear) . ',userid[' . gettype($userid) . ']=' . intval($userid) . ' - Invalid userid provided.');
1093         } // END - if
1094
1095         // Is there cache?
1096         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1097                 // Generate code
1098                 $GLOBALS[__FUNCTION__][$userid] = $userid . ' ({%user,nickname,fixEmptyContentToDashes=' . $userid . '%})';
1099         } // END - if
1100
1101         // Return cache
1102         return $GLOBALS[__FUNCTION__][$userid];
1103 }
1104
1105 // ----------------------------------------------------------------------------
1106 //                             XML call-back functions
1107 // ----------------------------------------------------------------------------
1108
1109 // For 'doing' add subid, the column-index is required
1110 function addXmlSpecialMemberAddDoUserSubid () {
1111         // So set it all here
1112         $GLOBALS['__COLUMN_INDEX']['doXmlCallbackFunction']  = 'column';
1113         $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['column_index'] = 'column';
1114 }
1115
1116 // ----------------------------------------------------------------------------
1117 //                 Wrapper functions for configuration entries
1118 // ----------------------------------------------------------------------------
1119
1120 // Getter for user_alpha
1121 function getUserAlpha () {
1122         // Is there cache?
1123         if (!isset($GLOBALS[__FUNCTION__])) {
1124                 // Determine it
1125                 $GLOBALS[__FUNCTION__] = getConfig('user_alpha');
1126         } // END - if
1127
1128         // Return cache
1129         return $GLOBALS[__FUNCTION__];
1130 }
1131
1132 // Getter for user_limit
1133 function getUserLimit () {
1134         // Is there cache?
1135         if (!isset($GLOBALS[__FUNCTION__])) {
1136                 // Determine it
1137                 $GLOBALS[__FUNCTION__] = getConfig('user_limit');
1138         } // END - if
1139
1140         // Return cache
1141         return $GLOBALS[__FUNCTION__];
1142 }
1143
1144 // Getter for tester_user_surname_prefix
1145 function getTesterUserSurnamePrefix () {
1146         // Is there cache?
1147         if (!isset($GLOBALS[__FUNCTION__])) {
1148                 // Determine it
1149                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_surname_prefix');
1150         } // END - if
1151
1152         // Return cache
1153         return $GLOBALS[__FUNCTION__];
1154 }
1155
1156 // Getter for tester_user_maximum
1157 function getTesterUserMaximum () {
1158         // Is there cache?
1159         if (!isset($GLOBALS[__FUNCTION__])) {
1160                 // Determine it
1161                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_maximum');
1162         } // END - if
1163
1164         // Return cache
1165         return $GLOBALS[__FUNCTION__];
1166 }
1167
1168 // Getter for tester_user_check_cat
1169 function getTesterUserCheckCat () {
1170         // Is there cache?
1171         if (!isset($GLOBALS[__FUNCTION__])) {
1172                 // Determine it
1173                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_check_cat');
1174         } // END - if
1175
1176         // Return cache
1177         return $GLOBALS[__FUNCTION__];
1178 }
1179
1180 // Getter for tester_user_gender
1181 function getTesterUserGender () {
1182         // Is there cache?
1183         if (!isset($GLOBALS[__FUNCTION__])) {
1184                 // Determine it
1185                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_gender');
1186         } // END - if
1187
1188         // Return cache
1189         return $GLOBALS[__FUNCTION__];
1190 }
1191
1192 // Getter for tester_user_family
1193 function getTesterUserFamily () {
1194         // Is there cache?
1195         if (!isset($GLOBALS[__FUNCTION__])) {
1196                 // Determine it
1197                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_family');
1198         } // END - if
1199
1200         // Return cache
1201         return $GLOBALS[__FUNCTION__];
1202 }
1203
1204 // Getter for tester_user_password
1205 function getTesterUserPassword () {
1206         // Is there cache?
1207         if (!isset($GLOBALS[__FUNCTION__])) {
1208                 // Determine it
1209                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_password');
1210         } // END - if
1211
1212         // Return cache
1213         return $GLOBALS[__FUNCTION__];
1214 }
1215
1216 // Getter for tester_user_street_nr
1217 function getTesterUserStreetNr () {
1218         // Is there cache?
1219         if (!isset($GLOBALS[__FUNCTION__])) {
1220                 // Determine it
1221                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_street_nr');
1222         } // END - if
1223
1224         // Return cache
1225         return $GLOBALS[__FUNCTION__];
1226 }
1227
1228 // Getter for tester_user_zip
1229 function getTesterUserZip () {
1230         // Is there cache?
1231         if (!isset($GLOBALS[__FUNCTION__])) {
1232                 // Determine it
1233                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_zip');
1234         } // END - if
1235
1236         // Return cache
1237         return $GLOBALS[__FUNCTION__];
1238 }
1239
1240 // Getter for tester_user_city
1241 function getTesterUserCity () {
1242         // Is there cache?
1243         if (!isset($GLOBALS[__FUNCTION__])) {
1244                 // Determine it
1245                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_city');
1246         } // END - if
1247
1248         // Return cache
1249         return $GLOBALS[__FUNCTION__];
1250 }
1251
1252 // Getter for tester_user_email
1253 function getTesterUserEmail () {
1254         // Is there cache?
1255         if (!isset($GLOBALS[__FUNCTION__])) {
1256                 // Determine it
1257                 $GLOBALS[__FUNCTION__] = getConfig('tester_user_email');
1258         } // END - if
1259
1260         // Return cache
1261         return $GLOBALS[__FUNCTION__];
1262 }
1263
1264 // Getter for 'ap_subids' config entry
1265 function getApSubids () {
1266         // Is there cache?
1267         if (!isset($GLOBALS[__FUNCTION__])) {
1268                 // Determine it
1269                 $GLOBALS[__FUNCTION__] = getConfig('ap_subids');
1270         } // END - if
1271
1272         // Return cache
1273         return $GLOBALS[__FUNCTION__];
1274 }
1275
1276 // Determines whether 'ap_subids' is set to 'Y'
1277 function isApSubidsEnabled () {
1278         // Is there cache?
1279         if (!isset($GLOBALS[__FUNCTION__])) {
1280                 // Determine it
1281                 $GLOBALS[__FUNCTION__] = (getApSubids() == 'Y');
1282         } // END - if
1283
1284         // Return cache
1285         return $GLOBALS[__FUNCTION__];
1286 }
1287
1288 // Getter for 'ap_subids_since' config entry
1289 function getApSubidsSince () {
1290         // Is there cache?
1291         if (!isset($GLOBALS[__FUNCTION__])) {
1292                 // Determine it
1293                 $GLOBALS[__FUNCTION__] = getConfig('ap_subids_since');
1294         } // END - if
1295
1296         // Return cache
1297         return $GLOBALS[__FUNCTION__];
1298 }
1299
1300 // Getter for 'select_user_zero_refid' config entry
1301 function getSelectUserZeroRefid () {
1302         // Is there cache?
1303         if (!isset($GLOBALS[__FUNCTION__])) {
1304                 // Determine it
1305                 $GLOBALS[__FUNCTION__] = getConfig('select_user_zero_refid');
1306         } // END - if
1307
1308         // Return cache
1309         return $GLOBALS[__FUNCTION__];
1310 }
1311
1312 // [EOF]
1313 ?>