Renamed all SQL-related functions to camel-case notation
[mailer.git] / inc / wrapper-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/04/2009 *
4  * ===================                          Last change: 04/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : wrapper-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Wrapper functions                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Wrapper-Funktionen                               *
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 - 2013 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         exit();
41 } // END - if
42
43 // Read a given file
44 function readFromFile ($FQFN) {
45         // Sanity-check if file is there (should be there, but just to make it sure)
46         if (!isFileReadable($FQFN)) {
47                 // This should not happen
48                 reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!');
49         } // END - if
50
51         // Load the file
52         if (function_exists('file_get_contents')) {
53                 // Use new function
54                 $fileContent = file_get_contents($FQFN);
55         } else {
56                 // Fall-back to implode-file chain
57                 $fileContent = implode('', file($FQFN));
58         }
59
60         // Return the content
61         return $fileContent;
62 }
63
64 // Writes content to a file
65 function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
66         // Is the file writeable?
67         if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
68                 // Not writeable!
69                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable or cannot change CHMOD to 0644.", basename($FQFN)));
70
71                 // Failed! :(
72                 return FALSE;
73         } // END - if
74
75         // By default all is failed...
76         $GLOBALS['file_readable'][$FQFN] = FALSE;
77         $return = FALSE;
78
79         // Is the function there?
80         if (function_exists('file_put_contents')) {
81                 // With lock?
82                 if ($aquireLock === TRUE) {
83                         // Write it directly with lock
84                         $return = file_put_contents($FQFN, $content, LOCK_EX);
85                 } else {
86                         // Write it directly
87                         $return = file_put_contents($FQFN, $content);
88                 }
89         } else {
90                 // Write it with fopen
91                 $fp = fopen($FQFN, 'w')
92                         or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
93
94                 // Aquire a lock?
95                 if ($aquireLock === TRUE) {
96                         // Aquire a lock.
97                         flock($fp, LOCK_EX);
98                 } // END - if
99
100                 // Write content
101                 $return = fwrite($fp, $content);
102
103                 // Close stream
104                 fclose($fp);
105         }
106
107         // Was something written?
108         if ($return !== FALSE) {
109                 // Mark it as readable
110                 $GLOBALS['file_readable'][$FQFN] = TRUE;
111         } // END - if
112
113         // Return status
114         return (($return !== FALSE) && (changeMode($FQFN, 0644)));
115 }
116
117 // Clears the output buffer. This function does *NOT* backup sent content.
118 function clearOutputBuffer () {
119         // Make sure this function is not called twice (no double-cleaning!)
120         if (isset($GLOBALS[__FUNCTION__])) {
121                 // This function is called twice
122                 reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.');
123         } elseif ((ob_get_length() > 0) && (!ob_end_clean())) {
124                 // Failed!
125                 reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.');
126         } // END - if
127
128         // Mark this function as called
129         $GLOBALS[__FUNCTION__] = TRUE;
130 }
131
132 // Encode strings
133 function encodeString ($str) {
134         $str = urlencode(base64_encode(compileUriCode($str)));
135         return $str;
136 }
137
138 // Decode strings encoded with encodeString()
139 function decodeString ($str) {
140         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
141         return $str;
142 }
143
144 // Decode entities in a nicer way
145 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
146         // Decode the entities to UTF-8 now
147         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
148
149         // Return decoded string
150         return $decodedString;
151 }
152
153 // Merges an array together but only if both are arrays
154 function merge_array ($array1, $array2, $keepIndex = FALSE) {
155         // Are both an array?
156         if ((!is_array($array1)) && (!is_array($array2))) {
157                 // Both are not arrays
158                 reportBug(__FUNCTION__, __LINE__, 'No arrays provided!');
159         } elseif (!is_array($array1)) {
160                 // Left one is not an array
161                 reportBug(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
162         } elseif (!is_array($array2)) {
163                 // Right one is not an array
164                 reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
165         }
166
167         // Maintain index of array2?
168         if ($keepIndex === TRUE) {
169                 // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
170                 foreach ($array2 as $key => $value) {
171                         // Add it
172                         $array1[$key] = $value;
173                 } // END - foreach
174
175                 // Return it
176                 return $array1;
177         } else {
178                 // Merge both together normally
179                 return array_merge($array1, $array2);
180         }
181 }
182
183 // Check if given FQFN is a readable file
184 function isFileReadable ($FQFN) {
185         // Is there cache?
186         if (!isset($GLOBALS['file_readable'][$FQFN])) {
187                 // Check all...
188                 $GLOBALS['file_readable'][$FQFN] = ((is_file($FQFN)) && (file_exists($FQFN)) && (is_readable($FQFN)));
189         } // END - if
190
191         // Return result
192         return $GLOBALS['file_readable'][$FQFN];
193 }
194
195 // Checks whether the given FQFN is a directory and not ., .. or .svn
196 function isDirectory ($FQFN) {
197         // Is there cache?
198         if (!isset($GLOBALS[__FUNCTION__][$FQFN])) {
199                 // Generate baseName
200                 $baseName = basename($FQFN);
201
202                 // Check it
203                 $GLOBALS[__FUNCTION__][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
204         } // END - if
205
206         // Return the result
207         return $GLOBALS[__FUNCTION__][$FQFN];
208 }
209
210 // "Getter" for the real remote IP number
211 function detectRealIpAddress ($alwaysReal = FALSE) {
212         // Get remote ip from environment
213         $remoteAddr = determineRealRemoteAddress();
214
215         // Is removeip installed?
216         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
217                 // Then anonymize it
218                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
219         } // END - if
220
221         // Return it
222         return $remoteAddr;
223 }
224
225 // "Getter" for remote IP number
226 function detectRemoteAddr ($alwaysReal = FALSE) {
227         // Get remote ip from environment
228         $remoteAddr = determineRealRemoteAddress(TRUE);
229
230         // Is removeip installed?
231         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
232                 // Then anonymize it
233                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
234         } // END - if
235
236         // Return it
237         return $remoteAddr;
238 }
239
240 // "Getter" for remote hostname
241 function detectRemoteHostname ($alwaysReal = FALSE) {
242         // Get remote ip from environment
243         $remoteHost = getenv('REMOTE_HOST');
244
245         // Is removeip installed?
246         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
247                 // Then anonymize it
248                 $remoteHost = getAnonymousRemoteHost($remoteHost);
249         } // END - if
250
251         // Return it
252         return $remoteHost;
253 }
254
255 // "Getter" for user agent
256 function detectUserAgent ($alwaysReal = FALSE) {
257         // Get remote ip from environment
258         $userAgent = getenv('HTTP_USER_AGENT');
259
260         // Is removeip installed?
261         if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
262                 // Then anonymize it
263                 $userAgent = getAnonymousUserAgent($userAgent);
264         } // END - if
265
266         // Return it
267         return $userAgent;
268 }
269
270 // "Getter" for referer
271 function detectReferer ($alwaysReal = FALSE) {
272         // Get remote ip from environment
273         $referer = getenv('HTTP_REFERER');
274
275         // Is removeip installed?
276         if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
277                 // Then anonymize it
278                 $referer = getAnonymousReferer($referer);
279         } // END - if
280
281         // Return it
282         return $referer;
283 }
284
285 // "Getter" for request URI
286 function detectRequestUri () {
287         // Return it
288         return (getenv('REQUEST_URI'));
289 }
290
291 // "Getter" for query string
292 function detectQueryString () {
293         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
294 }
295
296 // "Getter" for SERVER_NAME
297 function detectServerName () {
298         // Return it
299         return (getenv('SERVER_NAME'));
300 }
301
302 // Removes any  existing www. from SERVER_NAME. This is very silly but enough
303 // for our purpose here.
304 function detectDomainName () {
305         // Is there cache?
306         if (!isset($GLOBALS[__FUNCTION__])) {
307                 // Get server name
308                 $domainName = detectServerName();
309
310                 // Is there any www. ?
311                 if (substr($domainName, 0, 4) == 'www.') {
312                         // Remove it
313                         $domainName = substr($domainName, 4);
314                 } // END - if
315
316                 // Set cache
317                 $GLOBALS[__FUNCTION__] = $domainName;
318         } // END - if
319
320         // Return cache
321         return $GLOBALS[__FUNCTION__];
322 }
323
324 // Check whether we are installing
325 function isInstalling () {
326         // Determine whether we are installing
327         if (!isset($GLOBALS['__mailer_installing'])) {
328                 // Check URL (css.php/js.php need this)
329                 $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isGetRequestElementSet('level')) && (getRequestElement('level') == 'install')));
330         } // END - if
331
332         // Return result
333         return $GLOBALS['__mailer_installing'];
334 }
335
336 // Check whether this script is installed
337 function isInstalled () {
338         // Is there cache?
339         if (!isset($GLOBALS[__FUNCTION__])) {
340                 // Determine whether this script is installed
341                 $GLOBALS[__FUNCTION__] = (
342                 (
343                         // First is config
344                         (
345                                 (
346                                         isConfigEntrySet('MAILER_INSTALLED')
347                                 ) && (
348                                         getConfig('MAILER_INSTALLED') == 'Y'
349                                 )
350                         )
351                 ) || (
352                         // New config file found and loaded
353                         isIncludeReadable(getCachePath() . 'config-local.php')
354                 ) || (
355                         (
356                                 // New config file found, but not yet read
357                                 isIncludeReadable(getCachePath() . 'config-local.php')
358                         ) && (
359                                 (
360                                         // Only new config file is found
361                                         !isIncludeReadable('inc/config.php')
362                                 ) || (
363                                         // Is installation mode
364                                         !isInstalling()
365                                 )
366                         )
367                 ));
368         } // END - if
369
370         // Then use the cache
371         return $GLOBALS[__FUNCTION__];
372 }
373
374 // Check whether an admin is registered
375 function isAdminRegistered () {
376         // Is cache set?
377         if (!isset($GLOBALS[__FUNCTION__])) {
378                 // Simply check it
379                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
380         } // END - if
381
382         // Return it
383         return $GLOBALS[__FUNCTION__];
384 }
385
386 // Checks whether the hourly reset mode is active
387 function isHourlyResetEnabled () {
388         // Now simply check it
389         return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
390 }
391
392 // Checks whether the daily reset mode is active
393 function isDailyResetEnabled () {
394         // Now simply check it
395         return ((isset($GLOBALS['daily_enabled'])) && ($GLOBALS['daily_enabled'] === TRUE));
396 }
397
398 // Checks whether the weekly reset mode is active
399 function isWeeklyResetEnabled () {
400         // Now simply check it
401         return ((isset($GLOBALS['weekly_enabled'])) && ($GLOBALS['weekly_enabled'] === TRUE));
402 }
403
404 // Checks whether the monthly reset mode is active
405 function isMonthlyResetEnabled () {
406         // Now simply check it
407         return ((isset($GLOBALS['monthly_enabled'])) && ($GLOBALS['monthly_enabled'] === TRUE));
408 }
409
410 // Checks whether one of the reset modes is enabled
411 function isResetModeEnabled () {
412         // Now simply check it
413         return ((isHourlyResetEnabled()) || (isDailyResetEnabled()) || (isWeeklyResetEnabled()) || (isMonthlyResetEnabled()));
414 }
415
416 // Checks whether the debug mode is enabled
417 function isDebugModeEnabled () {
418         // Is cache set?
419         if (!isset($GLOBALS[__FUNCTION__])) {
420                 // Simply check it
421                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
422         } // END - if
423
424         // Return it
425         return $GLOBALS[__FUNCTION__];
426 }
427
428 // Checks whether the debug hourly is enabled
429 function isDebugHourlyEnabled () {
430         // Is cache set?
431         if (!isset($GLOBALS[__FUNCTION__])) {
432                 // Simply check it
433                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_HOURLY')) && (getConfig('DEBUG_HOURLY') == 'Y'));
434         } // END - if
435
436         // Return it
437         return $GLOBALS[__FUNCTION__];
438 }
439
440 // Checks whether the debug daily is enabled
441 function isDebugDailyEnabled () {
442         // Is cache set?
443         if (!isset($GLOBALS[__FUNCTION__])) {
444                 // Simply check it
445                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_DAILY')) && (getConfig('DEBUG_DAILY') == 'Y'));
446         } // END - if
447
448         // Return it
449         return $GLOBALS[__FUNCTION__];
450 }
451
452 // Checks whether the debug weekly is enabled
453 function isDebugWeeklyEnabled () {
454         // Is cache set?
455         if (!isset($GLOBALS[__FUNCTION__])) {
456                 // Simply check it
457                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
458         } // END - if
459
460         // Return it
461         return $GLOBALS[__FUNCTION__];
462 }
463
464 // Checks whether the debug monthly is enabled
465 function isDebugMonthlyEnabled () {
466         // Is cache set?
467         if (!isset($GLOBALS[__FUNCTION__])) {
468                 // Simply check it
469                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
470         } // END - if
471
472         // Return it
473         return $GLOBALS[__FUNCTION__];
474 }
475
476 // Checks whether SQL debugging is enabled
477 function isSqlDebuggingEnabled () {
478         // Is cache set?
479         if (!isset($GLOBALS[__FUNCTION__])) {
480                 // Determine if SQL debugging is enabled
481                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_SQL')) && (getConfig('DEBUG_SQL') == 'Y'));
482         } // END - if
483
484         // Return it
485         return $GLOBALS[__FUNCTION__];
486 }
487
488 // Checks whether we shall debug regular expressions
489 function isDebugRegularExpressionEnabled () {
490         // Is cache set?
491         if (!isset($GLOBALS[__FUNCTION__])) {
492                 // Simply check it
493                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
494         } // END - if
495
496         // Return it
497         return $GLOBALS[__FUNCTION__];
498 }
499
500 // Checks whether debugging of build mails is enabled
501 function isDebugBuildMailsEnabled () {
502         // Is cache set?
503         if (!isset($GLOBALS[__FUNCTION__])) {
504                 // Simply check it
505                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y'));
506         } // END - if
507
508         // Return it
509         return $GLOBALS[__FUNCTION__];
510 }
511
512 // Checks whether the cache instance is valid
513 function isCacheInstanceValid () {
514         // Is there cache?
515         if (!isset($GLOBALS[__FUNCTION__])) {
516                 // Determine it
517                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
518         } // END - if
519
520         // Return cache
521         return $GLOBALS[__FUNCTION__];
522 }
523
524 // Copies a file from source to destination and verifies if that goes fine.
525 // This function should wrap the copy() command and make a nicer debug backtrace
526 // even if there is no xdebug extension installed.
527 function copyFileVerified ($source, $dest, $chmod = '') {
528         // Failed is the default
529         $status = FALSE;
530
531         // Is the source file there?
532         if (!isFileReadable($source)) {
533                 // Then abort here
534                 reportBug(__FUNCTION__, __LINE__, 'Cannot read from source file ' . basename($source) . '.');
535         } // END - if
536
537         // Is the target directory there?
538         if (!isDirectory(dirname($dest))) {
539                 // Then abort here
540                 reportBug(__FUNCTION__, __LINE__, 'Cannot find directory ' . str_replace(getPath(), '', dirname($dest)) . '.');
541         } // END - if
542
543         // Now try to copy it
544         if (!copy($source, $dest)) {
545                 // Something went wrong
546                 reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
547         } else {
548                 // Reset cache
549                 $GLOBALS['file_readable'][$dest] = TRUE;
550         }
551
552         // All fine by default
553         $status = TRUE;
554
555         // If there are chmod rights set, apply them
556         if (!empty($chmod)) {
557                 // Try to apply them
558                 $status = changeMode($dest, $chmod);
559         } // END - if
560
561         // All fine
562         return $status;
563 }
564
565 // Wrapper function for chmod()
566 // @TODO Do some more sanity check here
567 function changeMode ($FQFN, $mode) {
568         // Is the file/directory there?
569         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
570                 // Neither, so abort here
571                 reportBug(__FUNCTION__, __LINE__, 'Cannot chmod() on ' . basename($FQFN) . '.');
572         } // END - if
573
574         // Try to set them
575         return chmod($FQFN, $mode);
576 }
577
578 // Wrapper for unlink()
579 function removeFile ($FQFN) {
580         // Is the file there?
581         if (isFileReadable($FQFN)) {
582                 // Reset cache first
583                 $GLOBALS['file_readable'][$FQFN] = FALSE;
584
585                 // Yes, so remove it
586                 return unlink($FQFN);
587         } // END - if
588
589         // All fine if no file was removed. If we change this to 'false' or rewrite
590         // above if() block it would be to restrictive.
591         return TRUE;
592 }
593
594 // Wrapper for $_POST['sel']
595 function countPostSelection ($element = 'sel') {
596         // Is there cache?
597         if (!isset($GLOBALS[__FUNCTION__][$element])) {
598                 // Default is zero
599                 $GLOBALS[__FUNCTION__][$element] = '0';
600
601                 // Is it set?
602                 if (isPostRequestElementSet($element)) {
603                         // Return counted elements
604                         $GLOBALS[__FUNCTION__][$element] = countSelection(postRequestElement($element));
605                 } // END - if
606         } // END - if
607
608         // Return cached value
609         return $GLOBALS[__FUNCTION__][$element];
610 }
611
612 // Checks whether the config-local.php is loaded
613 function isConfigLocalLoaded () {
614         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
615 }
616
617 // Checks whether a nickname or userid was entered and caches the result
618 function isNicknameUsed ($userid) {
619         // Is the cache there
620         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
621                 // Determine it
622                 $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
623         } // END - if
624
625         // Return the result
626         return $GLOBALS[__FUNCTION__][$userid];
627 }
628
629 // Getter for 'what' value
630 function getWhat ($strict = TRUE) {
631         // Default is null
632         $what = NULL;
633
634         // Is the value set?
635         if (isWhatSet($strict)) {
636                 // Then use it
637                 $what = $GLOBALS['__what'];
638         } // END - if
639
640         // Return it
641         return $what;
642 }
643
644 // Setter for 'what' value
645 function setWhat ($newWhat) {
646         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newWhat=' . $newWhat);
647         $GLOBALS['__what'] = $newWhat;
648 }
649
650 // Setter for 'what' from configuration
651 function setWhatFromConfig ($configEntry) {
652         // Get 'what' from config
653         $what = getConfig($configEntry);
654
655         // Set it
656         setWhat($what);
657 }
658
659 // Checks whether what is set and optionally aborts on miss
660 function isWhatSet ($strict = FALSE) {
661         // Check for it
662         $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
663
664         // Should we abort here?
665         if (($strict === TRUE) && ($isset === FALSE)) {
666                 // Output backtrace
667                 debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
668         } // END - if
669
670         // Return it
671         return $isset;
672 }
673
674 // Getter for 'action' value
675 function getAction ($strict = TRUE) {
676         // Default is null
677         $action = NULL;
678
679         // Is the value set?
680         if (isActionSet(($strict) && (isHtmlOutputMode()))) {
681                 // Then use it
682                 $action = $GLOBALS['__action'];
683         } // END - if
684
685         // Return it
686         return $action;
687 }
688
689 // Setter for 'action' value
690 function setAction ($newAction) {
691         $GLOBALS['__action'] = $newAction;
692 }
693
694 // Checks whether action is set and optionally aborts on miss
695 function isActionSet ($strict = FALSE) {
696         // Check for it
697         $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
698
699         // Should we abort here?
700         if (($strict === TRUE) && ($isset === FALSE)) {
701                 // Output backtrace
702                 reportBug(__FUNCTION__, __LINE__, 'action is empty.');
703         } // END - if
704
705         // Return it
706         return $isset;
707 }
708
709 // Getter for 'module' value
710 function getModule ($strict = TRUE) {
711         // Default is null
712         $module = NULL;
713
714         // Is the value set?
715         if (isModuleSet($strict)) {
716                 // Then use it
717                 $module = $GLOBALS['__module'];
718         } // END - if
719
720         // Return it
721         return $module;
722 }
723
724 // Setter for 'module' value
725 function setModule ($newModule) {
726         // Secure it and make all modules lower-case
727         $GLOBALS['__module'] = strtolower($newModule);
728 }
729
730 // Wrapper to get extra module names
731 function getExtraModule () {
732         // Default is 'NULL'
733         $extra = 'NULL';
734
735         // Is 'tab/step' set?
736         if (isPostRequestElementSet('tab')) {
737                 // Use this
738                 $extra = 'tab=' . postRequestElement('tab');
739         } elseif (isPostRequestElementSet('step')) {
740                 // Use this
741                 $extra = 'step=' . postRequestElement('step');
742         } elseif ((isActionSet()) && (isWhatSet())) {
743                 // Use 'action/what'
744                 $extra = 'action=' . getAction() . ':what=' . getWhat();
745         }
746
747         // Return it
748         return $extra;
749 }
750
751 // Checks whether module is set and optionally aborts on miss
752 function isModuleSet ($strict = FALSE) {
753         // Check for it
754         $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
755
756         // Should we abort here?
757         if (($strict === TRUE) && ($isset === FALSE)) {
758                 // Output backtrace
759                 reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
760         } // END - if
761
762         // Return it
763         return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
764 }
765
766 // Getter for 'output_mode' value
767 function getScriptOutputMode () {
768         // Is cache set?
769         if (!isset($GLOBALS[__FUNCTION__])) {
770                 // Is the output mode set?
771                 if (!isOutputModeSet()) {
772                         // No, then abort here
773                         reportBug(__FUNCTION__, __LINE__, 'Output mode not set.');
774                 } // END - if
775
776                 // Set it in cache
777                 $GLOBALS[__FUNCTION__] = $GLOBALS['__output_mode'];
778         } // END - if
779
780         // Return cache
781         return $GLOBALS[__FUNCTION__];
782 }
783
784 // Setter for 'output_mode' value
785 function setScriptOutputMode ($newOutputMode) {
786         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode);
787         $GLOBALS['__output_mode'] = (int) $newOutputMode;
788 }
789
790 // Checks whether output_mode is set and optionally aborts on miss
791 function isOutputModeSet ($strict = FALSE) {
792         // Check for it
793         $isset = (isset($GLOBALS['__output_mode']));
794
795         // Should we abort here?
796         if (($strict === TRUE) && ($isset === FALSE)) {
797                 // Output backtrace
798                 reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
799         } // END - if
800
801         // Return it
802         return $isset;
803 }
804
805 // Enables block-mode
806 function enableBlockMode ($enabled = TRUE) {
807         $GLOBALS['__block_mode'] = $enabled;
808 }
809
810 // Checks whether block-mode is enabled
811 function isBlockModeEnabled () {
812         // Abort if not set
813         if (!isset($GLOBALS['__block_mode'])) {
814                 // Needs to be fixed
815                 reportBug(__FUNCTION__, __LINE__, 'Block_mode is not set.');
816         } // END - if
817
818         // Return it
819         return $GLOBALS['__block_mode'];
820 }
821
822 // Wrapper for redirectToUrl but URL comes from a configuration entry
823 function redirectToConfiguredUrl ($configEntry) {
824         // Load the URL
825         redirectToUrl(getConfig($configEntry));
826 }
827
828 // Wrapper function to redirect from member-only modules to index
829 function redirectToIndexMemberOnlyModule () {
830         // Do the redirect here
831         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEMBER_ONLY') . '&amp;mod=' . getModule());
832 }
833
834 // Wrapper function to redirect to current URL
835 function redirectToRequestUri () {
836         redirectToUrl(basename(detectRequestUri()));
837 }
838
839 // Wrapper function to redirect to de-refered URL
840 function redirectToDereferedUrl ($url) {
841         // Redirect to to
842         redirectToUrl(generateDereferrerUrl($url));
843 }
844
845 // Wrapper function for checking if extension is installed and newer or same version
846 function isExtensionInstalledAndNewer ($ext_name, $ext_ver) {
847         // Is an cache entry found?
848         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
849                 // Determine it
850                 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE));
851         } else {
852                 // Cache hits should be incremented twice
853                 incrementStatsEntry('cache_hits', 2);
854         }
855
856         // Return it
857         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=&gt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
858         return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
859 }
860
861 // Wrapper function for checking if extension is installed and older than given version
862 function isExtensionInstalledAndOlder ($ext_name, $ext_ver) {
863         // Is an cache entry found?
864         if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) {
865                 // Determine it
866                 $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '<') === TRUE));
867         } else {
868                 // Cache hits should be incremented twice
869                 incrementStatsEntry('cache_hits', 2);
870         }
871
872         // Return it
873         //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '&lt;' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver]));
874         return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver];
875 }
876
877 // Set username
878 function setUsername ($userName) {
879         $GLOBALS['username'] = (string) $userName;
880 }
881
882 // Get username
883 function getUsername () {
884         // User name set?
885         if (!isset($GLOBALS['username'])) {
886                 // No, so it has to be a guest
887                 $GLOBALS['username'] = '{--USERNAME_GUEST--}';
888         } // END - if
889
890         // Return it
891         return $GLOBALS['username'];
892 }
893
894 // Wrapper function for installation phase
895 function isInstallationPhase () {
896         // Is there cache?
897         if (!isset($GLOBALS[__FUNCTION__])) {
898                 // Determine it
899                 $GLOBALS[__FUNCTION__] = ((!isInstalled()) || (isInstalling()));
900         } // END - if
901
902         // Return result
903         return $GLOBALS[__FUNCTION__];
904 }
905
906 // Checks whether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
907 function isDemoModeActive () {
908         // Is cache set?
909         if (!isset($GLOBALS[__FUNCTION__])) {
910                 // Simply check it
911                 $GLOBALS[__FUNCTION__] = ((isExtensionActive('demo')) && (getCurrentAdminLogin() == 'demo'));
912         } // END - if
913
914         // Return it
915         return $GLOBALS[__FUNCTION__];
916 }
917
918 // Getter for PHP caching value
919 function getPhpCaching () {
920         return $GLOBALS['php_caching'];
921 }
922
923 // Checks whether the admin hash is set
924 function isAdminHashSet ($adminId) {
925         // Is the array there?
926         if (!isset($GLOBALS['cache_array']['admin'])) {
927                 // Missing array should be reported
928                 reportBug(__FUNCTION__, __LINE__, 'Cache not set.');
929         } // END - if
930
931         // Check for admin hash
932         return isset($GLOBALS['cache_array']['admin']['password'][$adminId]);
933 }
934
935 // Setter for admin hash
936 function setAdminHash ($adminId, $hash) {
937         $GLOBALS['cache_array']['admin']['password'][$adminId] = $hash;
938 }
939
940 // Getter for current admin login
941 function getCurrentAdminLogin () {
942         // Log debug message
943         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
944
945         // Is there cache?
946         if (!isset($GLOBALS[__FUNCTION__])) {
947                 // Determine it
948                 $GLOBALS[__FUNCTION__] = getAdminLogin(getCurrentAdminId());
949         } // END - if
950
951         // Return it
952         return $GLOBALS[__FUNCTION__];
953 }
954
955 // Setter for admin id (and current)
956 function setAdminId ($adminId) {
957         // Log debug message
958         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId);
959
960         // Set session
961         $status = setSession('admin_id', bigintval($adminId));
962
963         // Set current id
964         setCurrentAdminId($adminId);
965
966         // Return status
967         return $status;
968 }
969
970 // Setter for admin_last
971 function setAdminLast ($adminLast) {
972         // Log debug message
973         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminLast=' . $adminLast);
974
975         // Set session
976         $status = setSession('admin_last', $adminLast);
977
978         // Return status
979         return $status;
980 }
981
982 // Setter for admin_md5
983 function setAdminMd5 ($adminMd5) {
984         // Log debug message
985         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminMd5=' . $adminMd5);
986
987         // Set session
988         $status = setSession('admin_md5', $adminMd5);
989
990         // Return status
991         return $status;
992 }
993
994 // Getter for admin_md5
995 function getAdminMd5 () {
996         // Log debug message
997         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'called!');
998
999         // Get session
1000         return getSession('admin_md5');
1001 }
1002
1003 // Init user data array
1004 function initUserData () {
1005         // User id should not be zero
1006         if (!isValidId(getCurrentUserId())) {
1007                 // Should be always valid
1008                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1009         } // END - if
1010
1011         // Init the user
1012         unset($GLOBALS['is_userdata_valid'][getCurrentUserId()]);
1013         $GLOBALS['user_data'][getCurrentUserId()] = array();
1014 }
1015
1016 // Getter for user data
1017 function getUserData ($column) {
1018         // User id should not be zero
1019         if (!isValidId(getCurrentUserId())) {
1020                 // Should be always valid
1021                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . getCurrentUserId());
1022         } // END - if
1023
1024         // Default is empty
1025         $data = NULL;
1026
1027         if (isset($GLOBALS['user_data'][getCurrentUserId()][$column])) {
1028                 // Return the value
1029                 $data = $GLOBALS['user_data'][getCurrentUserId()][$column];
1030         } // END - if
1031
1032         // Return it
1033         return $data;
1034 }
1035
1036 // Checks whether given user data is set to 'Y'
1037 function isUserDataEnabled ($column) {
1038         // Is there cache?
1039         if (!isset($GLOBALS[__FUNCTION__][getCurrentUserId()][$column])) {
1040                 // Determine it
1041                 $GLOBALS[__FUNCTION__][getCurrentUserId()][$column] = (getUserData($column) == 'Y');
1042         } // END - if
1043
1044         // Return cache
1045         return $GLOBALS[__FUNCTION__][getCurrentUserId()][$column];
1046 }
1047
1048 // Geter for whole user data array
1049 function getUserDataArray () {
1050         // Get user id
1051         $userid = getCurrentUserId();
1052
1053         // Is the current userid valid?
1054         if (!isValidId($userid)) {
1055                 // Should be always valid
1056                 reportBug(__FUNCTION__, __LINE__, 'Current user id is invalid: ' . $userid);
1057         } // END - if
1058
1059         // Get the whole array if found
1060         if (isset($GLOBALS['user_data'][$userid])) {
1061                 // Found, so return it
1062                 return $GLOBALS['user_data'][$userid];
1063         } else {
1064                 // Return empty array
1065                 return array();
1066         }
1067 }
1068
1069 // Checks if the user data is valid, this may indicate that the user has logged
1070 // in, but you should use isMember() if you want to find that out.
1071 function isUserDataValid () {
1072         // User id should not be zero so abort here
1073         if (!isCurrentUserIdSet()) {
1074                 // Debug message, may be noisy
1075                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
1076
1077                 // Abort here
1078                 return FALSE;
1079         } // END - if
1080
1081         // Is it cached?
1082         if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
1083                 // Determine it
1084                 $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
1085         } // END - if
1086
1087         // Return the result
1088         return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
1089 }
1090
1091 // Setter for current userid
1092 function setCurrentUserId ($userid) {
1093         // Debug message
1094         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - ENTERED!');
1095
1096         // Is the cache from below functions different?
1097         if (((isset($GLOBALS['getCurrentUserId'])) && ($GLOBALS['getCurrentUserId'] != $userid)) || ((!isset($GLOBALS['current_userid'])) && (isset($GLOBALS['isCurrentUserIdSet'])))) {
1098                 // Then unset both
1099                 unsetCurrentUserId();
1100         } // END - if
1101
1102         // Set userid
1103         $GLOBALS['current_userid'] = bigintval($userid);
1104
1105         // Unset it to re-determine the actual state
1106         unset($GLOBALS['is_userdata_valid'][$userid]);
1107
1108         // Debug message
1109         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid[' . gettype($userid) . ']=' . $userid . ' - EXIT!');
1110 }
1111
1112 // Getter for current userid
1113 function getCurrentUserId () {
1114         // Is cache set?
1115         if (!isset($GLOBALS[__FUNCTION__])) {
1116                 // Userid must be set before it can be used
1117                 if (!isCurrentUserIdSet()) {
1118                         // Not set
1119                         reportBug(__FUNCTION__, __LINE__, 'User id is not set.');
1120                 } // END - if
1121
1122                 // Set userid in cache
1123                 $GLOBALS[__FUNCTION__] = $GLOBALS['current_userid'];
1124         } // END - if
1125
1126         // Return cache
1127         return $GLOBALS[__FUNCTION__];
1128 }
1129
1130 // Checks if current userid is set
1131 function isCurrentUserIdSet () {
1132         // Is there cache?
1133         if (!isset($GLOBALS[__FUNCTION__])) {
1134                 // Determine it
1135                 $GLOBALS[__FUNCTION__] = ((isset($GLOBALS['current_userid'])) && (isValidId($GLOBALS['current_userid'])));
1136         } // END - if
1137
1138         // Return cache
1139         return $GLOBALS[__FUNCTION__];
1140 }
1141
1142 // Unsets current userid
1143 function unsetCurrentUserId () {
1144         // Is it set?
1145         if (isset($GLOBALS['current_userid'])) {
1146                 // Unset this, too
1147                 unset($GLOBALS['isValidId'][$GLOBALS['current_userid']]);
1148         } // END - if
1149
1150         // Unset all cache entries
1151         unset($GLOBALS['current_userid']);
1152         unset($GLOBALS['getCurrentUserId']);
1153         unset($GLOBALS['isCurrentUserIdSet']);
1154 }
1155
1156 // Checks whether we are debugging template cache
1157 function isDebugTemplateCacheEnabled () {
1158         // Is there cache?
1159         if (!isset($GLOBALS[__FUNCTION__])) {
1160                 // Determine it
1161                 $GLOBALS[__FUNCTION__] = (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
1162         } // END - if
1163
1164         // Return cache
1165         return $GLOBALS[__FUNCTION__];
1166 }
1167
1168 // Wrapper for fetchUserData() and getUserData() calls
1169 function getFetchedUserData ($keyColumn, $userid, $valueColumn) {
1170         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ' - ENTERED!');
1171         // Is it cached?
1172         if (!isset($GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn])) {
1173                 // Default is NULL
1174                 $data = NULL;
1175
1176                 // Can we fetch the user data?
1177                 if ((isValidId($userid)) && (fetchUserData($userid, $keyColumn))) {
1178                         // Now get the data back
1179                         $data = getUserData($valueColumn);
1180                 } // END - if
1181
1182                 // Cache it
1183                 $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] = $data;
1184         } // END - if
1185
1186         // Return it
1187         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyColumn=' . $keyColumn . ',userid=' . $userid . ',valueColumn=' . $valueColumn . ',value=' . $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn] . ' - EXIT!');
1188         return $GLOBALS[__FUNCTION__][$userid][$keyColumn][$valueColumn];
1189 }
1190
1191 // Wrapper for strpos() to ease porting from deprecated ereg() function
1192 function isInString ($needle, $haystack) {
1193         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
1194         return (strpos($haystack, $needle) !== FALSE);
1195 }
1196
1197 // Wrapper for strpos() to ease porting from deprecated eregi() function
1198 // This function is case-insensitive
1199 function isInStringIgnoreCase ($needle, $haystack) {
1200         return (isInString(strtolower($needle), strtolower($haystack)));
1201 }
1202
1203 // Wrapper to check for if fatal errors where detected
1204 function ifFatalErrorsDetected () {
1205         // Just call the inner function
1206         return (getTotalFatalErrors() > 0);
1207 }
1208
1209 // Checks whether a HTTP status has been set
1210 function isHttpStatusSet () {
1211         // Is it set and not empty?
1212         return ((isset($GLOBALS['http_status'])) && (!empty($GLOBALS['http_status'])));
1213 }
1214
1215 // Setter for HTTP status
1216 function setHttpStatus ($status) {
1217         $GLOBALS['http_status'] = (string) $status;
1218 }
1219
1220 // Getter for HTTP status
1221 function getHttpStatus () {
1222         // Is the status set?
1223         if (!isHttpStatusSet()) {
1224                 // Abort here
1225                 reportBug(__FUNCTION__, __LINE__, 'No HTTP status set!');
1226         } // END - if
1227
1228         // Return it
1229         return $GLOBALS['http_status'];
1230 }
1231
1232 /**
1233  * Send a HTTP redirect to the browser. This function was taken from DokuWiki
1234  * (GNU GPL 2; http://www.dokuwiki.org) and modified to fit into mailer project.
1235  *
1236  * ----------------------------------------------------------------------------
1237  * If you want to redirect, please use redirectToUrl(); instead
1238  * ----------------------------------------------------------------------------
1239  *
1240  * Works arround Microsoft IIS cookie sending bug. Does exit the script.
1241  *
1242  * @link    http://support.microsoft.com/kb/q176113/
1243  * @author  Andreas Gohr <andi@splitbrain.org>
1244  * @access  private
1245  */
1246 function sendRawRedirect ($url) {
1247         // Clear output buffer
1248         clearOutputBuffer();
1249
1250         // Clear own output buffer
1251         $GLOBALS['__output'] = '';
1252
1253         // To make redirects working (no content type), output mode must be raw
1254         setScriptOutputMode(-1);
1255
1256         // Send helping header
1257         setHttpStatus('302 Found');
1258
1259         // always close the session
1260         session_write_close();
1261
1262         // Revert entity &amp;
1263         $url = str_replace('&amp;', '&', $url);
1264
1265         // check if running on IIS < 6 with CGI-PHP
1266         if ((isset($_SERVER['SERVER_SOFTWARE'])) && (isset($_SERVER['GATEWAY_INTERFACE'])) &&
1267                 (isInString('CGI', $_SERVER['GATEWAY_INTERFACE'])) &&
1268                 (preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
1269                 ($matches[1] < 6)) {
1270                 // Send the IIS header
1271                 addHttpHeader('Refresh: 0;url=' . $url);
1272         } else {
1273                 // Send generic header
1274                 addHttpHeader('Location: ' . $url);
1275         }
1276
1277         // Shutdown here
1278         doShutdown();
1279 }
1280
1281 // Determines the country of the given user id
1282 function determineCountry ($userid) {
1283         // Is there cache?
1284         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
1285                 // Default is 'invalid'
1286                 $GLOBALS[__FUNCTION__][$userid] = 'invalid';
1287
1288                 // Is extension country active?
1289                 if (isExtensionActive('country')) {
1290                         // Determine the right country code through the country id
1291                         $id = getUserData('country_code');
1292
1293                         // Then handle it over
1294                         $GLOBALS[__FUNCTION__][$userid] = generateCountryInfo($id);
1295                 } else {
1296                         // Get raw code from user data
1297                         $GLOBALS[__FUNCTION__][$userid] = getUserData('country');
1298                 }
1299         } // END - if
1300
1301         // Return cache
1302         return $GLOBALS[__FUNCTION__][$userid];
1303 }
1304
1305 // "Getter" for total confirmed user accounts
1306 function getTotalConfirmedUser () {
1307         // Is it cached?
1308         if (!isset($GLOBALS[__FUNCTION__])) {
1309                 // Then do it
1310                 if (isExtensionActive('user')) {
1311                         $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1312                 } else {
1313                         $GLOBALS[__FUNCTION__] = 0;
1314                 }
1315         } // END - if
1316
1317         // Return cached value
1318         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1319         return $GLOBALS[__FUNCTION__];
1320 }
1321
1322 // "Getter" for total unconfirmed user accounts
1323 function getTotalUnconfirmedUser () {
1324         // Is it cached?
1325         if (!isset($GLOBALS[__FUNCTION__])) {
1326                 // Then do it
1327                 if (isExtensionActive('user')) {
1328                         $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1329                 } else {
1330                         $GLOBALS[__FUNCTION__] = 0;
1331                 }
1332         } // END - if
1333
1334         // Return cached value
1335         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1336         return $GLOBALS[__FUNCTION__];
1337 }
1338
1339 // "Getter" for total locked user accounts
1340 function getTotalLockedUser () {
1341         // Is it cached?
1342         if (!isset($GLOBALS[__FUNCTION__])) {
1343                 // Then do it
1344                 if (isExtensionActive('user')) {
1345                         $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
1346                 } else {
1347                         $GLOBALS[__FUNCTION__] = 0;
1348                 }
1349         } // END - if
1350
1351         // Return cached value
1352         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1353         return $GLOBALS[__FUNCTION__];
1354 }
1355
1356 // "Getter" for total locked user accounts
1357 function getTotalRandomRefidUser () {
1358         // Is it cached?
1359         if (!isset($GLOBALS[__FUNCTION__])) {
1360                 // Then do it
1361                 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
1362                         $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
1363                 } else {
1364                         $GLOBALS[__FUNCTION__] = 0;
1365                 }
1366         } // END - if
1367
1368         // Return cached value
1369         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
1370         return $GLOBALS[__FUNCTION__];
1371 }
1372
1373 // Is given id number valid?
1374 function isValidId ($id) {
1375         // Debug message
1376         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id[' . gettype($id) . ']=' . $id);
1377
1378         // Is there cache?
1379         if (!isset($GLOBALS[__FUNCTION__][$id])) {
1380                 // Check it out
1381                 $GLOBALS[__FUNCTION__][$id] = ((!is_null($id)) && (!is_bool($id)) && (!empty($id)) && ($id != 'NULL') && ($id > 0));
1382         } // END - if
1383
1384         // Return cache
1385         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $id . ',result=' . intval($GLOBALS[__FUNCTION__][$id]));
1386         return $GLOBALS[__FUNCTION__][$id];
1387 }
1388
1389 // Encodes entities
1390 function encodeEntities ($str) {
1391         // Secure it first
1392         $str = secureString($str, TRUE, TRUE);
1393
1394         // Encode dollar sign as well
1395         $str = str_replace('$', '&#36;', $str);
1396
1397         // Return it
1398         return $str;
1399 }
1400
1401 // "Getter" for date from patch_ctime
1402 function getDateFromRepository () {
1403         // Is it cached?
1404         if (!isset($GLOBALS[__FUNCTION__])) {
1405                 // Then set it
1406                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '5');
1407         } // END - if
1408
1409         // Return cache
1410         return $GLOBALS[__FUNCTION__];
1411 }
1412
1413 // "Getter" for date/time from patch_ctime
1414 function getDateTimeFromRepository () {
1415         // Is it cached?
1416         if (!isset($GLOBALS[__FUNCTION__])) {
1417                 // Then set it
1418                 $GLOBALS[__FUNCTION__] = generateDateTime(getConfig('CURRENT_REPOSITORY_DATE'), '2');
1419         } // END - if
1420
1421         // Return cache
1422         return $GLOBALS[__FUNCTION__];
1423 }
1424
1425 // Getter for current year (default)
1426 function getYear ($timestamp = NULL) {
1427         // Is it cached?
1428         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1429                 // If NULL is set, use time()
1430                 if (is_null($timestamp)) {
1431                         $timestamp = time();
1432                 } // END - if
1433
1434                 // Then create it
1435                 $GLOBALS[__FUNCTION__][$timestamp] = date('Y', $timestamp);
1436         } // END - if
1437
1438         // Return cache
1439         return $GLOBALS[__FUNCTION__][$timestamp];
1440 }
1441
1442 // Getter for current month (default)
1443 function getMonth ($timestamp = NULL) {
1444         // Is it cached?
1445         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1446                 // If NULL is set, use time()
1447                 if (is_null($timestamp)) {
1448                         // Use time() which is current timestamp
1449                         $timestamp = time();
1450                 } // END - if
1451
1452                 // Then create it
1453                 $GLOBALS[__FUNCTION__][$timestamp] = date('m', $timestamp);
1454         } // END - if
1455
1456         // Return cache
1457         return $GLOBALS[__FUNCTION__][$timestamp];
1458 }
1459
1460 // Getter for current hour (default)
1461 function getHour ($timestamp = NULL) {
1462         // Is it cached?
1463         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1464                 // null is time()
1465                 if (is_null($timestamp)) {
1466                         $timestamp = time();
1467                 } // END - if
1468
1469                 // Then create it
1470                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1471         } // END - if
1472
1473         // Return cache
1474         return $GLOBALS[__FUNCTION__][$timestamp];
1475 }
1476
1477 // Getter for current day (default)
1478 function getDay ($timestamp = NULL) {
1479         // Is it cached?
1480         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1481                 // null is time()
1482                 if (is_null($timestamp)) {
1483                         $timestamp = time();
1484                 } // END - if
1485
1486                 // Then create it
1487                 $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);
1488         } // END - if
1489
1490         // Return cache
1491         return $GLOBALS[__FUNCTION__][$timestamp];
1492 }
1493
1494 // Getter for current week (default)
1495 function getWeek ($timestamp = NULL) {
1496         // Is it cached?
1497         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1498                 // null is time()
1499                 if (is_null($timestamp)) $timestamp = time();
1500
1501                 // Then create it
1502                 $GLOBALS[__FUNCTION__][$timestamp] = date('W', $timestamp);
1503         } // END - if
1504
1505         // Return cache
1506         return $GLOBALS[__FUNCTION__][$timestamp];
1507 }
1508
1509 // Getter for current short_hour (default)
1510 function getShortHour ($timestamp = NULL) {
1511         // Is it cached?
1512         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1513                 // null is time()
1514                 if (is_null($timestamp)) $timestamp = time();
1515
1516                 // Then create it
1517                 $GLOBALS[__FUNCTION__][$timestamp] = date('G', $timestamp);
1518         } // END - if
1519
1520         // Return cache
1521         return $GLOBALS[__FUNCTION__][$timestamp];
1522 }
1523
1524 // Getter for current long_hour (default)
1525 function getLongHour ($timestamp = NULL) {
1526         // Is it cached?
1527         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1528                 // null is time()
1529                 if (is_null($timestamp)) $timestamp = time();
1530
1531                 // Then create it
1532                 $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp);
1533         } // END - if
1534
1535         // Return cache
1536         return $GLOBALS[__FUNCTION__][$timestamp];
1537 }
1538
1539 // Getter for current second (default)
1540 function getSecond ($timestamp = NULL) {
1541         // Is it cached?
1542         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1543                 // null is time()
1544                 if (is_null($timestamp)) $timestamp = time();
1545
1546                 // Then create it
1547                 $GLOBALS[__FUNCTION__][$timestamp] = date('s', $timestamp);
1548         } // END - if
1549
1550         // Return cache
1551         return $GLOBALS[__FUNCTION__][$timestamp];
1552 }
1553
1554 // Getter for current minute (default)
1555 function getMinute ($timestamp = NULL) {
1556         // Is it cached?
1557         if (!isset($GLOBALS[__FUNCTION__][$timestamp])) {
1558                 // null is time()
1559                 if (is_null($timestamp)) $timestamp = time();
1560
1561                 // Then create it
1562                 $GLOBALS[__FUNCTION__][$timestamp] = date('i', $timestamp);
1563         } // END - if
1564
1565         // Return cache
1566         return $GLOBALS[__FUNCTION__][$timestamp];
1567 }
1568
1569 // Checks whether the title decoration is enabled
1570 function isTitleDecorationEnabled () {
1571         // Is there cache?
1572         if (!isset($GLOBALS[__FUNCTION__])) {
1573                 // Just check it
1574                 $GLOBALS[__FUNCTION__] = (getConfig('enable_title_deco') == 'Y');
1575         } // END - if
1576
1577         // Return cache
1578         return $GLOBALS[__FUNCTION__];
1579 }
1580
1581 // Checks whether filter usage updates are enabled (expensive queries!)
1582 function isFilterUsageUpdateEnabled () {
1583         // Is there cache?
1584         if (!isset($GLOBALS[__FUNCTION__])) {
1585                 // Determine it
1586                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.6.0')) && (isConfigEntrySet('update_filter_usage')) && (getConfig('update_filter_usage') == 'Y'));
1587         } // END - if
1588
1589         // Return cache
1590         return $GLOBALS[__FUNCTION__];
1591 }
1592
1593 // Checks whether debugging of weekly resets is enabled
1594 function isWeeklyResetDebugEnabled () {
1595         // Is there cache?
1596         if (!isset($GLOBALS[__FUNCTION__])) {
1597                 // Determine it
1598                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_WEEKLY')) && (getConfig('DEBUG_WEEKLY') == 'Y'));
1599         } // END - if
1600
1601         // Return cache
1602         return $GLOBALS[__FUNCTION__];
1603 }
1604
1605 // Checks whether debugging of monthly resets is enabled
1606 function isMonthlyResetDebugEnabled () {
1607         // Is there cache?
1608         if (!isset($GLOBALS[__FUNCTION__])) {
1609                 // Determine it
1610                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_MONTHLY')) && (getConfig('DEBUG_MONTHLY') == 'Y'));
1611         } // END - if
1612
1613         // Return cache
1614         return $GLOBALS[__FUNCTION__];
1615 }
1616
1617 // Checks whether displaying of debug SQLs are enabled
1618 function isDisplayDebugSqlEnabled () {
1619         // Is there cache?
1620         if (!isset($GLOBALS[__FUNCTION__])) {
1621                 // Determine it
1622                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.2.2')) && (getDisplayDebugSqls() == 'Y'));
1623         } // END - if
1624
1625         // Return cache
1626         return $GLOBALS[__FUNCTION__];
1627 }
1628
1629 // Checks whether module title is enabled
1630 function isModuleTitleEnabled () {
1631         // Is there cache?
1632         if (!isset($GLOBALS[__FUNCTION__])) {
1633                 // Determine it
1634                 $GLOBALS[__FUNCTION__] = (getConfig('enable_mod_title') == 'Y');
1635         } // END - if
1636
1637         // Return cache
1638         return $GLOBALS[__FUNCTION__];
1639 }
1640
1641 // Checks whether what title is enabled
1642 function isWhatTitleEnabled () {
1643         // Is there cache?
1644         if (!isset($GLOBALS[__FUNCTION__])) {
1645                 // Determine it
1646                 $GLOBALS[__FUNCTION__] = (getConfig('enable_what_title') == 'Y');
1647         } // END - if
1648
1649         // Return cache
1650         return $GLOBALS[__FUNCTION__];
1651 }
1652
1653 // "Getter" for internal_stats
1654 function getInternalStats () {
1655         // Is there cache?
1656         if (!isset($GLOBALS[__FUNCTION__])) {
1657                 // Determine it
1658                 $GLOBALS[__FUNCTION__] = getConfig('internal_stats');
1659         } // END - if
1660
1661         // Return cache
1662         return $GLOBALS[__FUNCTION__];
1663 }
1664
1665 // Checks whether stats are enabled
1666 function ifInternalStatsEnabled () {
1667         // Is there cache?
1668         if (!isset($GLOBALS[__FUNCTION__])) {
1669                 // Then determine it, do not add isExtensionInstalledAndNewer() here as it breaks very first SQL query
1670                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('internal_stats')) && (getInternalStats() == 'Y'));
1671         } // END - if
1672
1673         // Return cached value
1674         return $GLOBALS[__FUNCTION__];
1675 }
1676
1677 // Checks whether admin-notification of certain user actions is enabled
1678 function isAdminNotificationEnabled () {
1679         // Is there cache?
1680         if (!isset($GLOBALS[__FUNCTION__])) {
1681                 // Determine it
1682                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('other', '0.3.0')) && (getAdminNotify() == 'Y'));
1683         } // END - if
1684
1685         // Return cache
1686         return $GLOBALS[__FUNCTION__];
1687 }
1688
1689 // Checks whether random referral id selection is enabled
1690 function isRandomReferralIdEnabled () {
1691         // Is there cache?
1692         if (!isset($GLOBALS[__FUNCTION__])) {
1693                 // Determine it
1694                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getSelectUserZeroRefid() == 'Y'));
1695         } // END - if
1696
1697         // Return cache
1698         return $GLOBALS[__FUNCTION__];
1699 }
1700
1701 // "Getter" for default language
1702 function getDefaultLanguage () {
1703         // Is there cache?
1704         if (!isset($GLOBALS[__FUNCTION__])) {
1705                 // Determine it
1706                 $GLOBALS[__FUNCTION__] = getConfig('DEFAULT_LANG');
1707         } // END - if
1708
1709         // Return cache
1710         return $GLOBALS[__FUNCTION__];
1711 }
1712
1713 // "Getter" for default referral id
1714 function getDefRefid () {
1715         // Is there cache?
1716         if (!isset($GLOBALS[__FUNCTION__])) {
1717                 // Determine it
1718                 $GLOBALS[__FUNCTION__] = getConfig('def_refid');
1719         } // END - if
1720
1721         // Return cache
1722         return $GLOBALS[__FUNCTION__];
1723 }
1724
1725 // "Getter" for path
1726 function getPath () {
1727         // Is there cache?
1728         if (!isset($GLOBALS[__FUNCTION__])) {
1729                 // Determine it
1730                 $GLOBALS[__FUNCTION__] = getConfig('PATH');
1731         } // END - if
1732
1733         // Return cache
1734         return $GLOBALS[__FUNCTION__];
1735 }
1736
1737 // "Getter" for url
1738 function getUrl () {
1739         // Is there cache?
1740         if (!isset($GLOBALS[__FUNCTION__])) {
1741                 // Determine it
1742                 $GLOBALS[__FUNCTION__] = getConfig('URL');
1743         } // END - if
1744
1745         // Return cache
1746         return $GLOBALS[__FUNCTION__];
1747 }
1748
1749 // "Getter" for cache_path
1750 function getCachePath () {
1751         // Is there cache?
1752         if (!isset($GLOBALS[__FUNCTION__])) {
1753                 // Determine it
1754                 $GLOBALS[__FUNCTION__] = getConfig('CACHE_PATH');
1755         } // END - if
1756
1757         // Return cache
1758         return $GLOBALS[__FUNCTION__];
1759 }
1760
1761 // "Getter" for WRITE_FOOTER
1762 function getWriteFooter () {
1763         // Is there cache?
1764         if (!isset($GLOBALS[__FUNCTION__])) {
1765                 // Determine it
1766                 $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER');
1767         } // END - if
1768
1769         // Return cache
1770         return $GLOBALS[__FUNCTION__];
1771 }
1772
1773 // "Getter" for secret_key
1774 function getSecretKey () {
1775         // Is there cache?
1776         if (!isset($GLOBALS[__FUNCTION__])) {
1777                 // Determine it
1778                 $GLOBALS[__FUNCTION__] = getConfig('secret_key');
1779         } // END - if
1780
1781         // Return cache
1782         return $GLOBALS[__FUNCTION__];
1783 }
1784
1785 // "Getter" for SITE_KEY
1786 function getSiteKey () {
1787         // Is there cache?
1788         if (!isset($GLOBALS[__FUNCTION__])) {
1789                 // Determine it
1790                 $GLOBALS[__FUNCTION__] = getConfig('SITE_KEY');
1791         } // END - if
1792
1793         // Return cache
1794         return $GLOBALS[__FUNCTION__];
1795 }
1796
1797 // "Getter" for DATE_KEY
1798 function getDateKey () {
1799         // Is there cache?
1800         if (!isset($GLOBALS[__FUNCTION__])) {
1801                 // Determine it
1802                 $GLOBALS[__FUNCTION__] = getConfig('DATE_KEY');
1803         } // END - if
1804
1805         // Return cache
1806         return $GLOBALS[__FUNCTION__];
1807 }
1808
1809 // "Getter" for master_salt
1810 function getMasterSalt () {
1811         // Is there cache?
1812         if (!isset($GLOBALS[__FUNCTION__])) {
1813                 // Determine it
1814                 $GLOBALS[__FUNCTION__] = getConfig('master_salt');
1815         } // END - if
1816
1817         // Return cache
1818         return $GLOBALS[__FUNCTION__];
1819 }
1820
1821 // "Getter" for prime
1822 function getPrime () {
1823         // Is there cache?
1824         if (!isset($GLOBALS[__FUNCTION__])) {
1825                 // Determine it
1826                 $GLOBALS[__FUNCTION__] = getConfig('_PRIME');
1827         } // END - if
1828
1829         // Return cache
1830         return $GLOBALS[__FUNCTION__];
1831 }
1832
1833 // "Getter" for encrypt_separator
1834 function getEncryptSeparator () {
1835         // Is there cache?
1836         if (!isset($GLOBALS[__FUNCTION__])) {
1837                 // Determine it
1838                 $GLOBALS[__FUNCTION__] = getConfig('ENCRYPT_SEPARATOR');
1839         } // END - if
1840
1841         // Return cache
1842         return $GLOBALS[__FUNCTION__];
1843 }
1844
1845 // "Getter" for mysql_prefix
1846 function getMysqlPrefix () {
1847         // Is there cache?
1848         if (!isset($GLOBALS[__FUNCTION__])) {
1849                 // Determine it
1850                 $GLOBALS[__FUNCTION__] = getConfig('_MYSQL_PREFIX');
1851         } // END - if
1852
1853         // Return cache
1854         return $GLOBALS[__FUNCTION__];
1855 }
1856
1857 // "Getter" for table_type
1858 function getTableType () {
1859         // Is there cache?
1860         if (!isset($GLOBALS[__FUNCTION__])) {
1861                 // Determine it
1862                 $GLOBALS[__FUNCTION__] = getConfig('_TABLE_TYPE');
1863         } // END - if
1864
1865         // Return cache
1866         return $GLOBALS[__FUNCTION__];
1867 }
1868
1869 // "Getter" for salt_length
1870 function getSaltLength () {
1871         // Is there cache?
1872         if (!isset($GLOBALS[__FUNCTION__])) {
1873                 // Determine it
1874                 $GLOBALS[__FUNCTION__] = getConfig('salt_length');
1875         } // END - if
1876
1877         // Return cache
1878         return $GLOBALS[__FUNCTION__];
1879 }
1880
1881 // "Getter" for output_mode
1882 function getOutputMode () {
1883         // Is there cache?
1884         if (!isset($GLOBALS[__FUNCTION__])) {
1885                 // Determine it
1886                 $GLOBALS[__FUNCTION__] = getConfig('OUTPUT_MODE');
1887         } // END - if
1888
1889         // Return cache
1890         return $GLOBALS[__FUNCTION__];
1891 }
1892
1893 // "Getter" for full_version
1894 function getFullVersion () {
1895         // Is there cache?
1896         if (!isset($GLOBALS[__FUNCTION__])) {
1897                 // Determine it
1898                 $GLOBALS[__FUNCTION__] = getConfig('FULL_VERSION');
1899         } // END - if
1900
1901         // Return cache
1902         return $GLOBALS[__FUNCTION__];
1903 }
1904
1905 // "Getter" for title
1906 function getTitle () {
1907         // Is there cache?
1908         if (!isset($GLOBALS[__FUNCTION__])) {
1909                 // Determine it
1910                 $GLOBALS[__FUNCTION__] = getConfig('TITLE');
1911         } // END - if
1912
1913         // Return cache
1914         return $GLOBALS[__FUNCTION__];
1915 }
1916
1917 // "Getter" for curr_svn_revision
1918 function getCurrentRepositoryRevision () {
1919         // Is there cache?
1920         if (!isset($GLOBALS[__FUNCTION__])) {
1921                 // Determine it
1922                 $GLOBALS[__FUNCTION__] = getConfig('CURRENT_REPOSITORY_REVISION');
1923         } // END - if
1924
1925         // Return cache
1926         return $GLOBALS[__FUNCTION__];
1927 }
1928
1929 // "Getter" for server_url
1930 function getServerUrl () {
1931         // Is there cache?
1932         if (!isset($GLOBALS[__FUNCTION__])) {
1933                 // Determine it
1934                 $GLOBALS[__FUNCTION__] = getConfig('SERVER_URL');
1935         } // END - if
1936
1937         // Return cache
1938         return $GLOBALS[__FUNCTION__];
1939 }
1940
1941 // "Getter" for mt_word
1942 function getMtWord () {
1943         // Is there cache?
1944         if (!isset($GLOBALS[__FUNCTION__])) {
1945                 // Determine it
1946                 $GLOBALS[__FUNCTION__] = getConfig('mt_word');
1947         } // END - if
1948
1949         // Return cache
1950         return $GLOBALS[__FUNCTION__];
1951 }
1952
1953 // "Getter" for mt_word2
1954 function getMtWord2 () {
1955         // Is there cache?
1956         if (!isset($GLOBALS[__FUNCTION__])) {
1957                 // Determine it
1958                 $GLOBALS[__FUNCTION__] = getConfig('mt_word2');
1959         } // END - if
1960
1961         // Return cache
1962         return $GLOBALS[__FUNCTION__];
1963 }
1964
1965 // "Getter" for mt_word3
1966 function getMtWord3 () {
1967         // Is there cache?
1968         if (!isset($GLOBALS[__FUNCTION__])) {
1969                 // Determine it
1970                 $GLOBALS[__FUNCTION__] = getConfig('mt_word3');
1971         } // END - if
1972
1973         // Return cache
1974         return $GLOBALS[__FUNCTION__];
1975 }
1976
1977 // "Getter" for START_TDAY
1978 function getStartTday () {
1979         // Is there cache?
1980         if (!isset($GLOBALS[__FUNCTION__])) {
1981                 // Determine it
1982                 $GLOBALS[__FUNCTION__] = getConfig('START_TDAY');
1983         } // END - if
1984
1985         // Return cache
1986         return $GLOBALS[__FUNCTION__];
1987 }
1988
1989 // "Getter" for START_YDAY
1990 function getStartYday () {
1991         // Is there cache?
1992         if (!isset($GLOBALS[__FUNCTION__])) {
1993                 // Determine it
1994                 $GLOBALS[__FUNCTION__] = getConfig('START_YDAY');
1995         } // END - if
1996
1997         // Return cache
1998         return $GLOBALS[__FUNCTION__];
1999 }
2000
2001 // "Getter" for main_title
2002 function getMainTitle () {
2003         // Is there cache?
2004         if (!isset($GLOBALS[__FUNCTION__])) {
2005                 // Determine it
2006                 $GLOBALS[__FUNCTION__] = getConfig('MAIN_TITLE');
2007         } // END - if
2008
2009         // Return cache
2010         return $GLOBALS[__FUNCTION__];
2011 }
2012
2013 // "Getter" for file_hash
2014 function getFileHash () {
2015         // Is there cache?
2016         if (!isset($GLOBALS[__FUNCTION__])) {
2017                 // Determine it
2018                 $GLOBALS[__FUNCTION__] = getConfig('file_hash');
2019         } // END - if
2020
2021         // Return cache
2022         return $GLOBALS[__FUNCTION__];
2023 }
2024
2025 // "Getter" for pass_scramble
2026 function getPassScramble () {
2027         // Is there cache?
2028         if (!isset($GLOBALS[__FUNCTION__])) {
2029                 // Determine it
2030                 $GLOBALS[__FUNCTION__] = getConfig('pass_scramble');
2031         } // END - if
2032
2033         // Return cache
2034         return $GLOBALS[__FUNCTION__];
2035 }
2036
2037 // "Getter" for ap_inactive_since
2038 function getApInactiveSince () {
2039         // Is there cache?
2040         if (!isset($GLOBALS[__FUNCTION__])) {
2041                 // Determine it
2042                 $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_since');
2043         } // END - if
2044
2045         // Return cache
2046         return $GLOBALS[__FUNCTION__];
2047 }
2048
2049 // "Getter" for user_min_confirmed
2050 function getUserMinConfirmed () {
2051         // Is there cache?
2052         if (!isset($GLOBALS[__FUNCTION__])) {
2053                 // Determine it
2054                 $GLOBALS[__FUNCTION__] = getConfig('user_min_confirmed');
2055         } // END - if
2056
2057         // Return cache
2058         return $GLOBALS[__FUNCTION__];
2059 }
2060 // "Getter" for points
2061 function getPoints () {
2062         // Is there cache?
2063         if (!isset($GLOBALS[__FUNCTION__])) {
2064                 // Determine it
2065                 $GLOBALS[__FUNCTION__] = getConfig('POINTS');
2066         } // END - if
2067
2068         // Return cache
2069         return $GLOBALS[__FUNCTION__];
2070 }
2071
2072 // "Getter" for slogan
2073 function getSlogan () {
2074         // Is there cache?
2075         if (!isset($GLOBALS[__FUNCTION__])) {
2076                 // Determine it
2077                 $GLOBALS[__FUNCTION__] = getConfig('SLOGAN');
2078         } // END - if
2079
2080         // Return cache
2081         return $GLOBALS[__FUNCTION__];
2082 }
2083
2084 // "Getter" for copy
2085 function getCopy () {
2086         // Is there cache?
2087         if (!isset($GLOBALS[__FUNCTION__])) {
2088                 // Determine it
2089                 $GLOBALS[__FUNCTION__] = getConfig('COPY');
2090         } // END - if
2091
2092         // Return cache
2093         return $GLOBALS[__FUNCTION__];
2094 }
2095
2096 // "Getter" for webmaster
2097 function getWebmaster () {
2098         // Is there cache?
2099         if (!isset($GLOBALS[__FUNCTION__])) {
2100                 // Determine it
2101                 $GLOBALS[__FUNCTION__] = getConfig('WEBMASTER');
2102         } // END - if
2103
2104         // Return cache
2105         return $GLOBALS[__FUNCTION__];
2106 }
2107
2108 // "Getter" for sql_count
2109 function getSqlCount () {
2110         // Is there cache?
2111         if (!isset($GLOBALS[__FUNCTION__])) {
2112                 // Determine it
2113                 $GLOBALS[__FUNCTION__] = getConfig('sql_count');
2114         } // END - if
2115
2116         // Return cache
2117         return $GLOBALS[__FUNCTION__];
2118 }
2119
2120 // "Getter" for num_templates
2121 function getNumTemplates () {
2122         // Is there cache?
2123         if (!isset($GLOBALS[__FUNCTION__])) {
2124                 // Determine it
2125                 $GLOBALS[__FUNCTION__] = getConfig('num_templates');
2126         } // END - if
2127
2128         // Return cache
2129         return $GLOBALS[__FUNCTION__];
2130 }
2131
2132 // "Getter" for dns_cache_timeout
2133 function getDnsCacheTimeout () {
2134         // Is there cache?
2135         if (!isset($GLOBALS[__FUNCTION__])) {
2136                 // Determine it
2137                 $GLOBALS[__FUNCTION__] = getConfig('dns_cache_timeout');
2138         } // END - if
2139
2140         // Return cache
2141         return $GLOBALS[__FUNCTION__];
2142 }
2143
2144 // "Getter" for menu_blur_spacer
2145 function getMenuBlurSpacer () {
2146         // Is there cache?
2147         if (!isset($GLOBALS[__FUNCTION__])) {
2148                 // Determine it
2149                 $GLOBALS[__FUNCTION__] = getConfig('menu_blur_spacer');
2150         } // END - if
2151
2152         // Return cache
2153         return $GLOBALS[__FUNCTION__];
2154 }
2155
2156 // "Getter" for points_register
2157 function getPointsRegister () {
2158         // Is there cache?
2159         if (!isset($GLOBALS[__FUNCTION__])) {
2160                 // Determine it
2161                 $GLOBALS[__FUNCTION__] = getConfig('points_register');
2162         } // END - if
2163
2164         // Return cache
2165         return $GLOBALS[__FUNCTION__];
2166 }
2167
2168 // "Getter" for points_ref
2169 function getPointsRef () {
2170         // Is there cache?
2171         if (!isset($GLOBALS[__FUNCTION__])) {
2172                 // Determine it
2173                 $GLOBALS[__FUNCTION__] = getConfig('points_ref');
2174         } // END - if
2175
2176         // Return cache
2177         return $GLOBALS[__FUNCTION__];
2178 }
2179
2180 // "Getter" for ref_payout
2181 function getRefPayout () {
2182         // Is there cache?
2183         if (!isset($GLOBALS[__FUNCTION__])) {
2184                 // Determine it
2185                 $GLOBALS[__FUNCTION__] = getConfig('ref_payout');
2186         } // END - if
2187
2188         // Return cache
2189         return $GLOBALS[__FUNCTION__];
2190 }
2191
2192 // "Getter" for online_timeout
2193 function getOnlineTimeout () {
2194         // Is there cache?
2195         if (!isset($GLOBALS[__FUNCTION__])) {
2196                 // Determine it
2197                 $GLOBALS[__FUNCTION__] = getConfig('online_timeout');
2198         } // END - if
2199
2200         // Return cache
2201         return $GLOBALS[__FUNCTION__];
2202 }
2203
2204 // "Getter" for index_home
2205 function getIndexHome () {
2206         // Is there cache?
2207         if (!isset($GLOBALS[__FUNCTION__])) {
2208                 // Determine it
2209                 $GLOBALS[__FUNCTION__] = getConfig('index_home');
2210         } // END - if
2211
2212         // Return cache
2213         return $GLOBALS[__FUNCTION__];
2214 }
2215
2216 // "Getter" for one_day
2217 function getOneDay () {
2218         // Is there cache?
2219         if (!isset($GLOBALS[__FUNCTION__])) {
2220                 // Determine it
2221                 $GLOBALS[__FUNCTION__] = getConfig('ONE_DAY');
2222         } // END - if
2223
2224         // Return cache
2225         return $GLOBALS[__FUNCTION__];
2226 }
2227
2228 // "Getter" for img_type
2229 function getImgType () {
2230         // Is there cache?
2231         if (!isset($GLOBALS[__FUNCTION__])) {
2232                 // Determine it
2233                 $GLOBALS[__FUNCTION__] = getConfig('img_type');
2234         } // END - if
2235
2236         // Return cache
2237         return $GLOBALS[__FUNCTION__];
2238 }
2239
2240 // "Getter" for code_length
2241 function getCodeLength () {
2242         // Is there cache?
2243         if (!isset($GLOBALS[__FUNCTION__])) {
2244                 // Determine it
2245                 $GLOBALS[__FUNCTION__] = getConfig('code_length');
2246         } // END - if
2247
2248         // Return cache
2249         return $GLOBALS[__FUNCTION__];
2250 }
2251
2252 // "Getter" for pass_len
2253 function getPassLen () {
2254         // Is there cache?
2255         if (!isset($GLOBALS[__FUNCTION__])) {
2256                 // Determine it
2257                 $GLOBALS[__FUNCTION__] = getConfig('pass_len');
2258         } // END - if
2259
2260         // Return cache
2261         return $GLOBALS[__FUNCTION__];
2262 }
2263
2264 // "Getter" for admin_menu
2265 function getAdminMenu () {
2266         // Is there cache?
2267         if (!isset($GLOBALS[__FUNCTION__])) {
2268                 // Determine it
2269                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu');
2270         } // END - if
2271
2272         // Return cache
2273         return $GLOBALS[__FUNCTION__];
2274 }
2275
2276 // "Getter" for last_hourly
2277 function getLastHourly () {
2278         // Is there cache?
2279         if (!isset($GLOBALS[__FUNCTION__])) {
2280                 // Determine it
2281                 $GLOBALS[__FUNCTION__] = getConfig('last_hourly');
2282         } // END - if
2283
2284         // Return cache
2285         return $GLOBALS[__FUNCTION__];
2286 }
2287
2288 // "Getter" for last_daily
2289 function getLastDaily () {
2290         // Is there cache?
2291         if (!isset($GLOBALS[__FUNCTION__])) {
2292                 // Determine it
2293                 $GLOBALS[__FUNCTION__] = getConfig('last_daily');
2294         } // END - if
2295
2296         // Return cache
2297         return $GLOBALS[__FUNCTION__];
2298 }
2299
2300 // "Getter" for last_weekly
2301 function getLastWeekly () {
2302         // Is there cache?
2303         if (!isset($GLOBALS[__FUNCTION__])) {
2304                 // Determine it
2305                 $GLOBALS[__FUNCTION__] = getConfig('last_weekly');
2306         } // END - if
2307
2308         // Return cache
2309         return $GLOBALS[__FUNCTION__];
2310 }
2311
2312 // "Getter" for last_monthly
2313 function getLastMonthly () {
2314         // Is there cache?
2315         if (!isset($GLOBALS[__FUNCTION__])) {
2316                 // Determine it
2317                 $GLOBALS[__FUNCTION__] = getConfig('last_monthly');
2318         } // END - if
2319
2320         // Return cache
2321         return $GLOBALS[__FUNCTION__];
2322 }
2323
2324 // "Getter" for mails_page
2325 function getMailsPage () {
2326         // Is there cache?
2327         if (!isset($GLOBALS[__FUNCTION__])) {
2328                 // Determine it
2329                 $GLOBALS[__FUNCTION__] = getConfig('mails_page');
2330         } // END - if
2331
2332         // Return cache
2333         return $GLOBALS[__FUNCTION__];
2334 }
2335
2336 // "Getter" for rand_no
2337 function getRandNo () {
2338         // Is there cache?
2339         if (!isset($GLOBALS[__FUNCTION__])) {
2340                 // Determine it
2341                 $GLOBALS[__FUNCTION__] = getConfig('rand_no');
2342         } // END - if
2343
2344         // Return cache
2345         return $GLOBALS[__FUNCTION__];
2346 }
2347
2348 // "Getter" for __DB_NAME
2349 function getDbName () {
2350         // Is there cache?
2351         if (!isset($GLOBALS[__FUNCTION__])) {
2352                 // Determine it
2353                 $GLOBALS[__FUNCTION__] = getConfig('__DB_NAME');
2354         } // END - if
2355
2356         // Return cache
2357         return $GLOBALS[__FUNCTION__];
2358 }
2359
2360 // "Getter" for DOMAIN
2361 function getDomain () {
2362         // Is there cache?
2363         if (!isset($GLOBALS[__FUNCTION__])) {
2364                 // Determine it
2365                 $GLOBALS[__FUNCTION__] = getConfig('DOMAIN');
2366         } // END - if
2367
2368         // Return cache
2369         return $GLOBALS[__FUNCTION__];
2370 }
2371
2372 // "Getter" for proxy_username
2373 function getProxyUsername () {
2374         // Is there cache?
2375         if (!isset($GLOBALS[__FUNCTION__])) {
2376                 // Determine it
2377                 $GLOBALS[__FUNCTION__] = getConfig('proxy_username');
2378         } // END - if
2379
2380         // Return cache
2381         return $GLOBALS[__FUNCTION__];
2382 }
2383
2384 // "Getter" for proxy_password
2385 function getProxyPassword () {
2386         // Is there cache?
2387         if (!isset($GLOBALS[__FUNCTION__])) {
2388                 // Determine it
2389                 $GLOBALS[__FUNCTION__] = getConfig('proxy_password');
2390         } // END - if
2391
2392         // Return cache
2393         return $GLOBALS[__FUNCTION__];
2394 }
2395
2396 // "Getter" for proxy_host
2397 function getProxyHost () {
2398         // Is there cache?
2399         if (!isset($GLOBALS[__FUNCTION__])) {
2400                 // Determine it
2401                 $GLOBALS[__FUNCTION__] = getConfig('proxy_host');
2402         } // END - if
2403
2404         // Return cache
2405         return $GLOBALS[__FUNCTION__];
2406 }
2407
2408 // "Getter" for proxy_port
2409 function getProxyPort () {
2410         // Is there cache?
2411         if (!isset($GLOBALS[__FUNCTION__])) {
2412                 // Determine it
2413                 $GLOBALS[__FUNCTION__] = getConfig('proxy_port');
2414         } // END - if
2415
2416         // Return cache
2417         return $GLOBALS[__FUNCTION__];
2418 }
2419
2420 // "Getter" for SMTP_HOSTNAME
2421 function getSmtpHostname () {
2422         // Is there cache?
2423         if (!isset($GLOBALS[__FUNCTION__])) {
2424                 // Determine it
2425                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_HOSTNAME');
2426         } // END - if
2427
2428         // Return cache
2429         return $GLOBALS[__FUNCTION__];
2430 }
2431
2432 // "Getter" for SMTP_USER
2433 function getSmtpUser () {
2434         // Is there cache?
2435         if (!isset($GLOBALS[__FUNCTION__])) {
2436                 // Determine it
2437                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_USER');
2438         } // END - if
2439
2440         // Return cache
2441         return $GLOBALS[__FUNCTION__];
2442 }
2443
2444 // "Getter" for SMTP_PASSWORD
2445 function getSmtpPassword () {
2446         // Is there cache?
2447         if (!isset($GLOBALS[__FUNCTION__])) {
2448                 // Determine it
2449                 $GLOBALS[__FUNCTION__] = getConfig('SMTP_PASSWORD');
2450         } // END - if
2451
2452         // Return cache
2453         return $GLOBALS[__FUNCTION__];
2454 }
2455
2456 // "Getter" for points_word
2457 function getPointsWord () {
2458         // Is there cache?
2459         if (!isset($GLOBALS[__FUNCTION__])) {
2460                 // Determine it
2461                 $GLOBALS[__FUNCTION__] = getConfig('points_word');
2462         } // END - if
2463
2464         // Return cache
2465         return $GLOBALS[__FUNCTION__];
2466 }
2467
2468 // "Getter" for profile_lock
2469 function getProfileLock () {
2470         // Is there cache?
2471         if (!isset($GLOBALS[__FUNCTION__])) {
2472                 // Determine it
2473                 $GLOBALS[__FUNCTION__] = getConfig('profile_lock');
2474         } // END - if
2475
2476         // Return cache
2477         return $GLOBALS[__FUNCTION__];
2478 }
2479
2480 // "Getter" for url_tlock
2481 function getUrlTlock () {
2482         // Is there cache?
2483         if (!isset($GLOBALS[__FUNCTION__])) {
2484                 // Determine it
2485                 $GLOBALS[__FUNCTION__] = getConfig('url_tlock');
2486         } // END - if
2487
2488         // Return cache
2489         return $GLOBALS[__FUNCTION__];
2490 }
2491
2492 // "Getter" for title_left
2493 function getTitleLeft () {
2494         // Is there cache?
2495         if (!isset($GLOBALS[__FUNCTION__])) {
2496                 // Determine it
2497                 $GLOBALS[__FUNCTION__] = getConfig('title_left');
2498         } // END - if
2499
2500         // Return cache
2501         return $GLOBALS[__FUNCTION__];
2502 }
2503
2504 // "Getter" for title_right
2505 function getTitleRight () {
2506         // Is there cache?
2507         if (!isset($GLOBALS[__FUNCTION__])) {
2508                 // Determine it
2509                 $GLOBALS[__FUNCTION__] = getConfig('title_right');
2510         } // END - if
2511
2512         // Return cache
2513         return $GLOBALS[__FUNCTION__];
2514 }
2515
2516 // "Getter" for title_middle
2517 function getTitleMiddle () {
2518         // Is there cache?
2519         if (!isset($GLOBALS[__FUNCTION__])) {
2520                 // Determine it
2521                 $GLOBALS[__FUNCTION__] = getConfig('title_middle');
2522         } // END - if
2523
2524         // Return cache
2525         return $GLOBALS[__FUNCTION__];
2526 }
2527
2528 // Getter for 'display_home_in_index'
2529 function getDisplayHomeInIndex () {
2530         // Is the cache entry set?
2531         if (!isset($GLOBALS[__FUNCTION__])) {
2532                 // No, so determine it
2533                 $GLOBALS[__FUNCTION__] = getConfig('display_home_in_index');
2534         } // END - if
2535
2536         // Return cached entry
2537         return $GLOBALS[__FUNCTION__];
2538 }
2539
2540 // Checks whether 'display_home_in_index' is 'Y'
2541 function isDisplayHomeInIndexEnabled () {
2542         // Is the cache entry set?
2543         if (!isset($GLOBALS[__FUNCTION__])) {
2544                 // No, so determine it
2545                 $GLOBALS[__FUNCTION__] = (getDisplayHomeInIndex() == 'Y');
2546         } // END - if
2547
2548         // Return cached entry
2549         return $GLOBALS[__FUNCTION__];
2550 }
2551
2552 // Getter for 'show_points_unconfirmed'
2553 function getShowPointsUnconfirmed () {
2554         // Is the cache entry set?
2555         if (!isset($GLOBALS[__FUNCTION__])) {
2556                 // No, so determine it
2557                 $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed');
2558         } // END - if
2559
2560         // Return cached entry
2561         return $GLOBALS[__FUNCTION__];
2562 }
2563
2564 // Checks whether 'show_points_unconfirmed' is 'Y'
2565 function isShowPointsUnconfirmedEnabled () {
2566         // Is the cache entry set?
2567         if (!isset($GLOBALS[__FUNCTION__])) {
2568                 // No, so determine it
2569                 $GLOBALS[__FUNCTION__] = (getShowPointsUnconfirmed() == 'Y');
2570         } // END - if
2571
2572         // Return cached entry
2573         return $GLOBALS[__FUNCTION__];
2574 }
2575
2576 // Getter for 'youre_here'
2577 function getYoureHere () {
2578         // Is the cache entry set?
2579         if (!isset($GLOBALS[__FUNCTION__])) {
2580                 // No, so determine it
2581                 $GLOBALS[__FUNCTION__] = getConfig('youre_here');
2582         } // END - if
2583
2584         // Return cached entry
2585         return $GLOBALS[__FUNCTION__];
2586 }
2587
2588 // Checks whether 'show_timings' is 'Y'
2589 function isYoureHereEnabled () {
2590         // Is the cache entry set?
2591         if (!isset($GLOBALS[__FUNCTION__])) {
2592                 // No, so determine it
2593                 $GLOBALS[__FUNCTION__] = (getYoureHere() == 'Y');
2594         } // END - if
2595
2596         // Return cached entry
2597         return $GLOBALS[__FUNCTION__];
2598 }
2599
2600 // Getter for 'show_timings'
2601 function getShowTimings () {
2602         // Is the cache entry set?
2603         if (!isset($GLOBALS[__FUNCTION__])) {
2604                 // No, so determine it
2605                 $GLOBALS[__FUNCTION__] = getConfig('show_timings');
2606         } // END - if
2607
2608         // Return cached entry
2609         return $GLOBALS[__FUNCTION__];
2610 }
2611
2612 // Checks whether 'show_timings' is 'Y'
2613 function isShowTimingsEnabled () {
2614         // Is the cache entry set?
2615         if (!isset($GLOBALS[__FUNCTION__])) {
2616                 // No, so determine it
2617                 $GLOBALS[__FUNCTION__] = (getShowTimings() == 'Y');
2618         } // END - if
2619
2620         // Return cached entry
2621         return $GLOBALS[__FUNCTION__];
2622 }
2623
2624 // Getter for 'ap_server_name_since'
2625 function getApServerNameSince () {
2626         // Is the cache entry set?
2627         if (!isset($GLOBALS[__FUNCTION__])) {
2628                 // No, so determine it
2629                 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since');
2630         } // END - if
2631
2632         // Return cached entry
2633         return $GLOBALS[__FUNCTION__];
2634 }
2635
2636 // Getter for 'ap_server_name'
2637 function getApServerName () {
2638         // Is the cache entry set?
2639         if (!isset($GLOBALS[__FUNCTION__])) {
2640                 // No, so determine it
2641                 $GLOBALS[__FUNCTION__] = getConfig('ap_server_name');
2642         } // END - if
2643
2644         // Return cached entry
2645         return $GLOBALS[__FUNCTION__];
2646 }
2647
2648 // Getter for 'index_delay'
2649 function getIndexDelay () {
2650         // Is the cache entry set?
2651         if (!isset($GLOBALS[__FUNCTION__])) {
2652                 // No, so determine it
2653                 $GLOBALS[__FUNCTION__] = getConfig('index_delay');
2654         } // END - if
2655
2656         // Return cached entry
2657         return $GLOBALS[__FUNCTION__];
2658 }
2659
2660 // Checks whether 'ap_server_name' is 'Y'
2661 function isApServerNameEnabled () {
2662         // Is the cache entry set?
2663         if (!isset($GLOBALS[__FUNCTION__])) {
2664                 // No, so determine it
2665                 $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y');
2666         } // END - if
2667
2668         // Return cached entry
2669         return $GLOBALS[__FUNCTION__];
2670 }
2671
2672 // Getter for 'admin_menu_javascript'
2673 function getAdminMenuJavascript () {
2674         // Is the cache entry set?
2675         if (!isset($GLOBALS[__FUNCTION__])) {
2676                 // No, so determine it
2677                 $GLOBALS[__FUNCTION__] = getConfig('admin_menu_javascript');
2678         } // END - if
2679
2680         // Return cached entry
2681         return $GLOBALS[__FUNCTION__];
2682 }
2683
2684 // Getter for 'points_remove_account'
2685 function getPointsRemoveAccount () {
2686         // Is the cache entry set?
2687         if (!isset($GLOBALS[__FUNCTION__])) {
2688                 // No, so determine it
2689                 $GLOBALS[__FUNCTION__] = getConfig('points_remove_account');
2690         } // END - if
2691
2692         // Return cached entry
2693         return $GLOBALS[__FUNCTION__];
2694 }
2695
2696 // Getter for 'css_php'
2697 function getCssPhp () {
2698         // Is the cache entry set?
2699         if (!isset($GLOBALS[__FUNCTION__])) {
2700                 // No, so determine it
2701                 $GLOBALS[__FUNCTION__] = getConfig('css_php');
2702         } // END - if
2703
2704         // Return cached entry
2705         return $GLOBALS[__FUNCTION__];
2706 }
2707
2708 // Getter for 'guest_menu'
2709 function getGuestMenu () {
2710         // Is the cache entry set?
2711         if (!isset($GLOBALS[__FUNCTION__])) {
2712                 // No, so determine it
2713                 $GLOBALS[__FUNCTION__] = getConfig('guest_menu');
2714         } // END - if
2715
2716         // Return cached entry
2717         return $GLOBALS[__FUNCTION__];
2718 }
2719
2720 // Checks if guest menu is enabled
2721 function isGuestMenuEnabled () {
2722         // Is the cache entry set?
2723         if (!isset($GLOBALS[__FUNCTION__])) {
2724                 // No, so determine it
2725                 $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y');
2726         } // END - if
2727
2728         // Return cached entry
2729         return $GLOBALS[__FUNCTION__];
2730 }
2731
2732 // Getter for 'member_menu'
2733 function getMemberMenu () {
2734         // Is the cache entry set?
2735         if (!isset($GLOBALS[__FUNCTION__])) {
2736                 // No, so determine it
2737                 $GLOBALS[__FUNCTION__] = getConfig('member_menu');
2738         } // END - if
2739
2740         // Return cached entry
2741         return $GLOBALS[__FUNCTION__];
2742 }
2743
2744 // Checks if member menu is enabled
2745 function isMemberMenuEnabled () {
2746         // Is the cache entry set?
2747         if (!isset($GLOBALS[__FUNCTION__])) {
2748                 // No, so determine it
2749                 $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y');
2750         } // END - if
2751
2752         // Return cached entry
2753         return $GLOBALS[__FUNCTION__];
2754 }
2755
2756 // Getter for 'word_wrap'
2757 function getWordWrap () {
2758         // Is the cache entry set?
2759         if (!isset($GLOBALS[__FUNCTION__])) {
2760                 // Construct config entry name
2761                 $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat();
2762
2763                 // Is a special config entry found or ext-sql_patches updated?
2764                 if (isConfigEntrySet($configEntry)) {
2765                         // A special config entry has been found, then use it
2766                         $GLOBALS[__FUNCTION__] = getConfig($configEntry);
2767                 } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) {
2768                         // No special config entry found, then use it as "fall-back"
2769                         $GLOBALS[__FUNCTION__] = getConfig('word_wrap');
2770                 } else {
2771                         // No, use default (15 characters)
2772                         $GLOBALS[__FUNCTION__] = 15;
2773                 }
2774         } // END - if
2775
2776         // Return cached entry
2777         return $GLOBALS[__FUNCTION__];
2778 }
2779
2780 // Checks whether proxy configuration is used
2781 function isProxyUsed () {
2782         // Is there cache?
2783         if (!isset($GLOBALS[__FUNCTION__])) {
2784                 // Determine it
2785                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.4.3')) && (getConfig('proxy_host') != '') && (getConfig('proxy_port') > 0));
2786         } // END - if
2787
2788         // Return cache
2789         return $GLOBALS[__FUNCTION__];
2790 }
2791
2792 // Checks whether POST data contains selections
2793 function ifPostContainsSelections ($element = 'sel') {
2794         // Is there cache?
2795         if (!isset($GLOBALS[__FUNCTION__][$element])) {
2796                 // Determine it
2797                 $GLOBALS[__FUNCTION__][$element] = ((isPostRequestElementSet($element)) && (is_array(postRequestElement($element))) && (countPostSelection($element) > 0));
2798         } // END - if
2799
2800         // Return cache
2801         return $GLOBALS[__FUNCTION__][$element];
2802 }
2803
2804 // Checks whether verbose_sql is Y and returns true/false if so
2805 function isVerboseSqlEnabled () {
2806         // Is there cache?
2807         if (!isset($GLOBALS[__FUNCTION__])) {
2808                 // Determine it
2809                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.0.7')) && (getConfig('verbose_sql') == 'Y'));
2810         } // END - if
2811
2812         // Return cache
2813         return $GLOBALS[__FUNCTION__];
2814 }
2815
2816 // "Getter" for total user points
2817 function getTotalPoints ($userid) {
2818         // Is there cache?
2819         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2820                 // Init array for filter chain
2821                 $data = array(
2822                         'userid' => $userid,
2823                         'points' => 0
2824                 );
2825
2826                 // Run filter chain for getting more point values
2827                 $data = runFilterChain('get_total_points', $data);
2828
2829                 // Determine it
2830                 $GLOBALS[__FUNCTION__][$userid] = $data['points']  - getUserUsedPoints($userid);
2831         } // END - if
2832
2833         // Return cache
2834         return $GLOBALS[__FUNCTION__][$userid];
2835 }
2836
2837 // Wrapper to get used points for given userid
2838 function getUserUsedPoints ($userid) {
2839         // Is there cache?
2840         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2841                 // Determine it
2842                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_data', 'used_points');
2843         } // END - if
2844
2845         // Return cache
2846         return $GLOBALS[__FUNCTION__][$userid];
2847 }
2848
2849 // Checks whether direct payment is allowed in configuration
2850 function isDirectPaymentEnabled () {
2851         // Is there cache?
2852         if (!isset($GLOBALS[__FUNCTION__])) {
2853                 // Determine it
2854                 $GLOBALS[__FUNCTION__] = (getConfig('allow_direct_pay') == 'Y');
2855         } // END - if
2856
2857         // Return cache
2858         return $GLOBALS[__FUNCTION__];
2859 }
2860
2861 // Checks whether JavaScript-based admin menu is enabled
2862 function isAdminMenuJavascriptEnabled () {
2863         // Is there cache?
2864         if (!isset($GLOBALS[__FUNCTION__])) {
2865                 // Determine it
2866                 $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('sql_patches', '0.8.7')) && (getAdminMenuJavaScript() == 'Y'));
2867         } // END - if
2868
2869         // Return cache
2870         return $GLOBALS[__FUNCTION__];
2871 }
2872
2873 // Wrapper to check if current task is for extension (not update)
2874 function isExtensionTask ($content) {
2875         // Is there cache?
2876         if (!isset($GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']])) {
2877                 // Determine it
2878                 $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']] = (($content['task_type'] == 'EXTENSION') && ((isExtensionNameValid($content['infos'])) || (isExtensionDeprecated($content['infos']))) && (!isExtensionInstalled($content['infos'])));
2879         } // END - if
2880
2881         // Return cache
2882         return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']];
2883 }
2884
2885 // Checks whether ALLOW_TESTER_ACCOUNTS is set
2886 function ifTesterAccountsAllowed () {
2887         // Is the cache entry set?
2888         if (!isset($GLOBALS[__FUNCTION__])) {
2889                 // No, so determine it
2890                 $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('ALLOW_TESTER_ACCOUNTS')) && (getConfig('ALLOW_TESTER_ACCOUNTS') == 'Y'));
2891         } // END - if
2892
2893         // Return cached entry
2894         return $GLOBALS[__FUNCTION__];
2895 }
2896
2897 // Wrapper to check if output mode is CSS
2898 function isCssOutputMode () {
2899         // Is cache set?
2900         if (!isset($GLOBALS[__FUNCTION__])) {
2901                 // Determine it
2902                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2903                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 1);
2904         } // END - if
2905
2906         // Return cache
2907         return $GLOBALS[__FUNCTION__];
2908 }
2909
2910 // Wrapper to check if output mode is HTML
2911 function isHtmlOutputMode () {
2912         // Is cache set?
2913         if (!isset($GLOBALS[__FUNCTION__])) {
2914                 // Determine it
2915                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2916                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == 0);
2917         } // END - if
2918
2919         // Return cache
2920         return $GLOBALS[__FUNCTION__];
2921 }
2922
2923 // Wrapper to check if output mode is RAW
2924 function isRawOutputMode () {
2925         // Is cache set?
2926         if (!isset($GLOBALS[__FUNCTION__])) {
2927                 // Determine it
2928                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2929                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -1);
2930         } // END - if
2931
2932         // Return cache
2933         return $GLOBALS[__FUNCTION__];
2934 }
2935
2936 // Wrapper to check if output mode is AJAX
2937 function isAjaxOutputMode () {
2938         // Is cache set?
2939         if (!isset($GLOBALS[__FUNCTION__])) {
2940                 // Determine it
2941                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2942                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -2);
2943         } // END - if
2944
2945         // Return cache
2946         return $GLOBALS[__FUNCTION__];
2947 }
2948
2949 // Wrapper to check if output mode is image
2950 function isImageOutputMode () {
2951         // Is cache set?
2952         if (!isset($GLOBALS[__FUNCTION__])) {
2953                 // Determine it
2954                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getScriptOutputMode()=' . getScriptOutputMode());
2955                 $GLOBALS[__FUNCTION__] = (getScriptOutputMode() == -3);
2956         } // END - if
2957
2958         // Return cache
2959         return $GLOBALS[__FUNCTION__];
2960 }
2961
2962 // Wrapper to generate a user email link
2963 function generateWrappedUserEmailLink ($email) {
2964         // Just call the inner function
2965         return generateEmailLink($email, 'user_data');
2966 }
2967
2968 // Wrapper to check if user points are locked
2969 function ifUserPointsLocked ($userid) {
2970         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - ENTERED!');
2971         // Is there cache?
2972         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
2973                 // Determine it
2974                 $GLOBALS[__FUNCTION__][$userid] = ((getFetchedUserData('userid', $userid, 'ref_payout') > 0) && (!isDirectPaymentEnabled()));
2975         } // END - if
2976
2977         // Return cache
2978         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',locked=' . intval($GLOBALS[__FUNCTION__][$userid]) . ' - EXIT!');
2979         return $GLOBALS[__FUNCTION__][$userid];
2980 }
2981
2982 // Appends a line to an existing file or creates it instantly with given content.
2983 // This function does always add a new-line character to every line.
2984 function appendLineToFile ($file, $line) {
2985         $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!');
2986         fwrite($fp, $line . PHP_EOL);
2987         fclose($fp);
2988 }
2989
2990 // Wrapper for changeDataInFile() but with full path added
2991 function changeDataInInclude ($FQFN, $comment, $prefix, $suffix, $inserted, $seek=0) {
2992         // Add full path
2993         $FQFN = getPath() . $FQFN;
2994
2995         // Call inner function
2996         return changeDataInFile($FQFN, $comment, $prefix, $suffix, $inserted, $seek);
2997 }
2998
2999 // Wrapper for changing entries in config-local.php
3000 function changeDataInLocalConfigurationFile ($comment, $prefix, $suffix, $inserted, $seek = 0) {
3001         // Call the inner function
3002         return changeDataInInclude(getCachePath() . 'config-local.php', $comment, $prefix, $suffix, $inserted, $seek);
3003 }
3004
3005 // Shortens ucfirst(strtolower()) calls
3006 function firstCharUpperCase ($str) {
3007         return ucfirst(strtolower($str));
3008 }
3009
3010 // Shortens calls with configuration entry as first argument (the second will become obsolete in the future)
3011 function createConfigurationTimeSelections ($configEntry, $stamps, $align = 'center') {
3012         // Get the configuration entry
3013         $configValue = getConfig($configEntry);
3014
3015         // Call inner method
3016         return createTimeSelections($configValue, $configEntry, $stamps, $align);
3017 }
3018
3019 // Shortens converting of German comma to Computer's version in POST data
3020 function convertCommaToDotInPostData ($postEntry) {
3021         // Read and convert given entry
3022         $postValue = convertCommaToDot(postRequestElement($postEntry));
3023
3024         // Log message
3025         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
3026
3027         // ... and set it again
3028         setPostRequestElement($postEntry, $postValue);
3029 }
3030
3031 // Converts German commas to Computer's version in all entries
3032 function convertCommaToDotInPostDataArray ($postEntries) {
3033         // Replace german decimal comma with computer decimal dot
3034         foreach ($postEntries as $entry) {
3035                 // Is the entry there?
3036                 if (isPostRequestElementSet($entry)) {
3037                         // Then convert it
3038                         convertCommaToDotInPostData($entry);
3039                 } // END - if
3040         } // END - foreach
3041 }
3042
3043 /**
3044  * Parses a string into a US formated float variable, taken from user comments
3045  * from PHP documentation website.
3046  *
3047  * @param       $floatString    A string holding a float expression
3048  * @return      $float                  Corresponding float variable
3049  * @author      chris<at>georgakopoulos<dot>com
3050  * @link        http://de.php.net/manual/en/function.floatval.php#92563
3051  */
3052 function parseFloat ($floatString){
3053         // Load locale info
3054         $LocaleInfo = localeconv();
3055
3056         // Remove thousand separators
3057         $floatString = str_replace($LocaleInfo['mon_thousands_sep'] , '' , $floatString);
3058
3059         // Convert decimal point
3060         $floatString = str_replace($LocaleInfo['mon_decimal_point'] , '.', $floatString);
3061
3062         // Return float value of converted string
3063         return floatval($floatString);
3064 }
3065
3066 /**
3067  * Searches a multi-dimensional array (as used in many places) for given
3068  * key/value pair as taken from user comments from PHP documentation website.
3069  *
3070  * @param       $array                  An array with one or more dimensions
3071  * @param       $key                    Key to look for
3072  * @param       $value                  Value to look for
3073  * @param       $parentIndex    Parent index (ONLY INTERNAL USE!)
3074  * @return      $results                Resulted array or empty array if $array is no array
3075  * @author      sunelbe<at>gmail<dot>com
3076  * @link        http://de.php.net/manual/en/function.array-search.php#110120
3077  */
3078 function search_array ($array, $key, $value, $parentIndex = NULL) {
3079         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
3080         // Init array result
3081         $results = array();
3082
3083         // Is $array really an array?
3084         if (is_array($array)) {
3085                 // Search for whole array
3086                 foreach ($array as $idx => $dummy) {
3087                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex);
3088                         //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=<pre>'.print_r($array, TRUE).'</pre>';
3089                         // Is dummy an array?
3090                         if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) {
3091                                 // Then search again
3092                                 $subResult = search_array($dummy, $key, $value, $idx);
3093                                 //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
3094
3095                                 // And merge both
3096                                 $results = merge_array($results, $subResult, TRUE);
3097                         } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) {
3098                                 // Is found, so add it
3099                                 $results[$parentIndex] = $array;
3100                                 //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=<pre>' . print_r($array, TRUE).'</pre>';
3101                         }
3102                 } // END - foreach
3103         } // END - if
3104
3105         // Return resulting array
3106         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
3107         return $results;
3108 }
3109
3110 // Generates a YES/NO option list from given default
3111 function generateYesNoOptions ($defaultValue = '') {
3112         // Generate it
3113         return generateOptions('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $defaultValue);
3114 }
3115
3116 // "Getter" for total available receivers
3117 function getTotalReceivers ($mode = 'normal') {
3118         // Get num rows
3119         $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
3120
3121         // Return value
3122         return $numRows;
3123 }
3124
3125 // Wrapper "getter" to get total unconfirmed mails for given userid
3126 function getTotalUnconfirmedMails ($userid) {
3127         // Is there cache?
3128         if (!isset($GLOBALS[__FUNCTION__][$userid])) {
3129                 // Determine it
3130                 $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
3131         } // END - if
3132
3133         // Return cache
3134         return $GLOBALS[__FUNCTION__][$userid];
3135 }
3136
3137 // Checks whether 'mailer_theme' was found in session
3138 function isMailerThemeSet () {
3139         // Is cache set?
3140         if (!isset($GLOBALS[__FUNCTION__])) {
3141                 // Determine it
3142                 $GLOBALS[__FUNCTION__] = isSessionVariableSet('mailer_theme');
3143         } // END - if
3144
3145         // Return cache
3146         return $GLOBALS[__FUNCTION__];
3147 }
3148
3149 /**
3150  * Setter for theme in session (This setter does return the success of
3151  * setSession() which is required e.g. for destroySponsorSession().
3152  */
3153 function setMailerTheme ($newTheme) {
3154         // Set it in session
3155         return setSession('mailer_theme', $newTheme);
3156 }
3157
3158 /**
3159  * Getter for theme from session (This getter does return 'mailer_theme' from
3160  * session data or throws an error if not possible
3161  */
3162 function getMailerTheme () {
3163         // Is cache set?
3164         if (!isset($GLOBALS[__FUNCTION__])) {
3165                 // Is 'mailer_theme' set?
3166                 if (!isMailerThemeSet()) {
3167                         // No, then abort here
3168                         reportBug(__FUNCTION__, __LINE__, 'mailer_theme not set in session. Please fix your code.');
3169                 } // END - if
3170
3171                 // Get it and store it in cache
3172                 $GLOBALS[__FUNCTION__] = getSession('mailer_theme');
3173         } // END - if
3174
3175         // Return cache
3176         return $GLOBALS[__FUNCTION__];
3177 }
3178
3179 // "Getter" for last_module/last_what depending on ext-user version
3180 function getUserLastWhatName () {
3181         // Default is old one: last_module
3182         $columnName = 'last_module';
3183
3184         // Is ext-user up-to-date?
3185         if (isExtensionInstalledAndNewer('user', '0.4.9')) {
3186                 // Yes, then use new one
3187                 $columnName = 'last_what';
3188         } // END - if
3189
3190         // Return it
3191         return $columnName;
3192 }
3193
3194 // "Getter" for all columns for given alias and separator
3195 function getAllPointColumns ($alias = NULL, $separator = ',') {
3196         // Prepare the filter array
3197         $filterData = array(
3198                 'columns'   => '',
3199                 'alias'     => $alias,
3200                 'separator' => $separator
3201         );
3202
3203         // Run the filter
3204         $filterData = runFilterChain('get_all_point_columns', $filterData);
3205
3206         // Return the columns
3207         return $filterData['columns'];
3208 }
3209
3210 // Checks whether the copyright footer (which breaks framesets) is enabled
3211 function ifCopyrightFooterEnabled () {
3212         // Is not unset and not 'N'?
3213         return ((!isset($GLOBALS['__copyright_enabled'])) || ($GLOBALS['__copyright_enabled'] == 'Y'));
3214 }
3215
3216 /**
3217  * Wrapper to check whether we have a "full page". This means that the actual
3218  * content is not delivered in any frame of a frameset.
3219  */
3220 function isFullPage () {
3221         /*
3222          * The parameter 'frame' is generic and always indicates that this content
3223          * will be output into a frame. Furthermore, if a frameset is reported or
3224          * the copyright line is explicitly deactivated, this cannot be a "full
3225          * page" again.
3226          */
3227         // @TODO Find a way to not use direct module comparison
3228         $isFullPage = ((!isGetRequestElementSet('frame')) && (getModule() != 'frametester') && (!isFramesetModeEnabled()) && (ifCopyrightFooterEnabled()));
3229
3230         // Return it
3231         return $isFullPage;
3232 }
3233
3234 // Checks whether frameset_mode is set to true
3235 function isFramesetModeEnabled () {
3236         // Check it
3237         return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
3238 }
3239
3240 // Function to determine correct 'what' value
3241 function determineWhat ($module = NULL) {
3242         // Init default 'what'
3243         $what = 'welcome';
3244
3245         // Is module NULL?
3246         if (is_null($module)) {
3247                 // Then use default
3248                 $module = getModule();
3249         } // END - if
3250
3251         // Is what set?
3252         if (isWhatSet()) {
3253                 // Then use it
3254                 $what = getWhat();
3255         } else {
3256                 // Else try to get it from current module
3257                 $what = getWhatFromModule($module);
3258         }
3259         //* DEBUG: */ debugOutput(__LINE__.'*'.$what.'/'.$module.'/'.getAction().'/'.getWhat().'*');
3260
3261         // Remove any spaces from variable
3262         $what = trim($what);
3263
3264         // Is it empty?
3265         if (empty($what)) {
3266                 // Default action for non-admin menus
3267                 $what = 'welcome';
3268         } else {
3269                 // Secure it
3270                 $what = secureString($what);
3271         }
3272
3273         // Return what
3274         return $what;
3275 }
3276
3277 // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad
3278 function prependZeros ($str, $length = 2) {
3279         // Return prepended string
3280         return sprintf('%0' . (int) $length . 's', $str);
3281 }
3282
3283 // Wraps convertSelectionsToEpocheTime()
3284 function convertSelectionsToEpocheTimeInPostData ($id) {
3285         // Init variables
3286         $content = array();
3287         $skip = FALSE;
3288
3289         // Get all POST data
3290         $postData = postRequestArray();
3291
3292         // Convert given selection id
3293         convertSelectionsToEpocheTime($postData, $content, $id, $skip);
3294
3295         // Set the POST array back
3296         setPostRequestArray($postData);
3297 }
3298
3299 // Wraps checking if given points account type matches with given in POST data
3300 function ifPointsAccountTypeMatchesPost ($type) {
3301         // Check condition
3302         exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
3303 }
3304
3305 // Gets given user's total referral
3306 function getUsersTotalReferrals ($userid, $level = NULL) {
3307         // Is there cache?
3308         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3309                 // Is the level NULL?
3310                 if (is_null($level)) {
3311                         // Get total amount (all levels)
3312                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
3313                 } else {
3314                         // Get it from user refs
3315                         $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
3316                 }
3317         } // END - if
3318
3319         // Return it
3320         return $GLOBALS[__FUNCTION__][$userid][$level];
3321 }
3322
3323 // Gets given user's total referral
3324 function getUsersTotalLockedReferrals ($userid, $level = NULL) {
3325         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ' - ENTERED!');
3326         // Is there cache?
3327         if (!isset($GLOBALS[__FUNCTION__][$userid][$level])) {
3328                 // Default is all refs
3329                 $add = '';
3330
3331                 // Is the not level NULL?
3332                 if (!is_null($level)) {
3333                         // Then add referral level
3334                         $add = ' AND `r`.`level`=' . bigintval($level);
3335                 } // END - if
3336
3337                 // Check for all referrals
3338                 $result = sqlQueryEscaped("SELECT
3339         COUNT(`d`.`userid`) AS `cnt`
3340 FROM
3341         `{?_MYSQL_PREFIX?}_user_data` AS `d`
3342 INNER JOIN
3343         `{?_MYSQL_PREFIX?}_user_refs` AS `r`
3344 ON
3345         `d`.`userid`=`r`.`refid`
3346 WHERE
3347         `d`.`status` != 'CONFIRMED' AND
3348         `r`.`userid`=%s
3349         " . $add . "
3350 ORDER BY
3351         `d`.`userid` ASC
3352 LIMIT 1",
3353                         array(
3354                                 $userid
3355                         ), __FUNCTION__, __LINE__);
3356
3357                 // Load count
3358                 list($GLOBALS[__FUNCTION__][$userid][$level]) = sqlFetchRow($result);
3359
3360                 // Free result
3361                 sqlFreeResult($result);
3362         } // END - if
3363
3364         // Return it
3365         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',level[' . gettype($level) . ']=' . $level . ':' . $GLOBALS[__FUNCTION__][$userid][$level] . ' - EXIT!');
3366         return $GLOBALS[__FUNCTION__][$userid][$level];
3367 }
3368
3369 // Converts, if found, dollar data to get element
3370 function convertDollarDataToGetElement ($data) {
3371         // Is first char a dollar?
3372         if (substr($data, 0, 1) == chr(36)) {
3373                 // Use last part for getRequestElement()
3374                 $data = getRequestElement(substr($data, 1));
3375         } // END - if
3376
3377         // Return it
3378         return $data;
3379 }
3380
3381 // Wrapper function for SQL layer to speed-up things
3382 function isSqlDebugEnabled () {
3383         // Is there cache?
3384         if (!isset($GLOBALS[__FUNCTION__])) {
3385                 // Determine it
3386                 $GLOBALS[__FUNCTION__] = ((!isCssOutputMode()) && (isDebugModeEnabled()) && (isSqlDebuggingEnabled()));
3387         } // END - if
3388
3389         // Return cache
3390         return $GLOBALS[__FUNCTION__];
3391 }
3392
3393 // Wrapper function to wrap call of wordwrap()
3394 function wrapWords ($text) {
3395         // Wrap words
3396         $wrapped = wordwrap($test, getWordWrap());
3397
3398         // Return it
3399         return $wrapped;
3400 }
3401
3402 // Encodes given data into a JSON object
3403 function encodeJson ($data) {
3404         // Encode it
3405         return json_encode($data, JSON_FORCE_OBJECT);
3406 }
3407
3408 // Get all extension files
3409 function loadAllExtensionsByTemplate () {
3410         // Get all
3411         $extensions = getArrayFromDirectory(
3412                 'templates/' . getLanguage() . '/html/ext/',
3413                 'ext_',
3414                 false,
3415                 false,
3416                 array(),
3417                 '.tpl',
3418                 '@(\.|\.\.)$@',
3419                 false
3420         );
3421
3422         // Return them
3423         return $extensions;
3424 }
3425
3426 // Wrapper function to allow full float values as supported by current database layout
3427 function translateFullComma ($dotted) {
3428         // Call inner function
3429         return translateComma($dotted, TRUE, 5);
3430 }
3431
3432 // Wrapper to check if the first element to be shifted is set to given value
3433 function shift_array (&$array, $value, $key = '0') {
3434         // Is the element set and value matches?
3435         assert(is_array($array));
3436         assert(isset($array[$key]));
3437         assert($array[$key] === $value);
3438
3439         // Shift it
3440         array_shift($array);
3441 }
3442
3443 // Wrapper for str_pad() with left padding zeros
3444 function padLeftZero ($str, $amount = 2) {
3445         // Is str_pad() there?
3446         if (function_exists('str_pad')) {
3447                 // Use prependZeros()
3448                 return prependZeros($str, $amount);
3449         } else {
3450                 // Pad it
3451                 return str_pad($str, $amount, '0', STR_PAD_LEFT);
3452         }
3453 }
3454
3455 // [EOF]
3456 ?>