+ // @TODO Add a little more infos here
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
+ } // END - if
+
+ // Add output
+ $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>inc/cache/debug.log</strong> in your report (you can now attach files):<pre>";
+ $debug .= debug_get_printable_backtrace();
+ $debug .= "</pre>\nRequest-URI: " . $_SERVER['REQUEST_URI']."<br />\n";
+ $debug .= "Thank you for finding bugs.";
+
+ // And abort here
+ // @TODO This cannot be rewritten to app_die(), try to find a solution for this.
+ die($debug);
+}
+
+// Generates a ***weak*** seed (taken from de.php.net/mt_srand)
+function generateSeed () {
+ list($usec, $sec) = explode(' ', microtime());
+ $microTime = (((float)$sec + (float)$usec)) * 100000;
+ return $microTime;
+}
+
+// Converts a message code to a human-readable message
+function convertCodeToMessage ($code) {
+ $message = '';
+ switch ($code) {
+ case getCode('LOGOUT_DONE') : $message = getMessage('LOGOUT_DONE'); break;
+ case getCode('LOGOUT_FAILED') : $message = "<span class=\"guest_failed\">{--LOGOUT_FAILED--}</span>"; break;
+ case getCode('DATA_INVALID') : $message = getMessage('MAIL_DATA_INVALID'); break;
+ case getCode('POSSIBLE_INVALID') : $message = getMessage('MAIL_POSSIBLE_INVALID'); break;
+ case getCode('ACCOUNT_LOCKED') : $message = getMessage('MEMBER_ACCOUNT_LOCKED_UNC'); break;
+ case getCode('USER_404') : $message = getMessage('USER_NOT_FOUND'); break;
+ case getCode('STATS_404') : $message = getMessage('MAIL_STATS_404'); break;
+ case getCode('ALREADY_CONFIRMED'): $message = getMessage('MAIL_ALREADY_CONFIRMED'); break;
+
+ case getCode('ERROR_MAILID'):
+ if (EXT_IS_ACTIVE($ext, true)) {
+ $message = getMessage('ERROR_CONFIRMING_MAIL');
+ } else {
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'mailid');
+ }
+ break;
+
+ case getCode('EXTENSION_PROBLEM'):
+ if (REQUEST_ISSET_GET('ext')) {
+ $message = generateExtensionInactiveNotInstalledMessage(REQUEST_GET('ext'));
+ } else {
+ $message = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
+ }
+ break;
+
+ case getCode('COOKIES_DISABLED') : $message = getMessage('LOGIN_NO_COOKIES'); break;
+ case getCode('BEG_SAME_AS_OWN') : $message = getMessage('BEG_SAME_UID_AS_OWN'); break;
+ case getCode('LOGIN_FAILED') : $message = getMessage('LOGIN_FAILED_GENERAL'); break;
+ case getCode('MODULE_MEM_ONLY') : $message = sprintf(getMessage('MODULE_MEM_ONLY'), REQUEST_GET('mod')); break;
+
+ default:
+ // Missing/invalid code
+ $message = sprintf(getMessage('UNKNOWN_MAILID_CODE'), $code);
+
+ // Log it
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+
+// Generate a "link" for the given admin id (aid)
+function generateAdminLink ($aid) {
+ // No assigned admin is default
+ $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
+
+ // Zero? = Not assigned
+ if (bigintval($aid) > 0) {
+ // Load admin's login
+ $login = getAdminLogin($aid);
+
+ // Is the login valid?
+ if ($login != '***') {
+ // Is the extension there?
+ if (EXT_IS_ACTIVE('admins')) {
+ // Admin found
+ $admin = "<a href=\"".adminsCreateEmailLink(getAdminEmail($aid))."\">" . $login."</a>";
+ } else {
+ // Extension not found
+ $admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
+ }
+ } else {
+ // Maybe deleted?
+ $admin = "<div class=\"admin_note\">".sprintf(getMessage('ADMIN_ID_404'), $aid)."</div>";
+ }
+ } // END - if
+
+ // Return result
+ return $admin;
+}
+
+// Compile characters which are allowed in URLs
+function compileUriCode ($code, $simple=true) {
+ // Compile constants
+ if (!$simple) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
+
+ // Compile QUOT and other non-HTML codes
+ $code = str_replace('{DOT}', '.',
+ str_replace('{SLASH}', '/',
+ str_replace('{QUOT}', "'",
+ str_replace('{DOLLAR}', '$',
+ str_replace('{OPEN_ANCHOR}', '(',
+ str_replace('{CLOSE_ANCHOR}', ')',
+ str_replace('{OPEN_SQR}', '[',
+ str_replace('{CLOSE_SQR}', ']',
+ str_replace('{PER}', '%',
+ $code
+ )))))))));
+
+ // Return compiled code
+ return $code;
+}
+
+// Function taken from user comments on www.php.net / function eregi()
+function isUrlValidSimple ($url) {
+ // Prepare URL
+ $url = strip_tags(str_replace("\\", '', COMPILE_CODE(urldecode($url))));
+
+ // Allows http and https
+ $http = "(http|https)+(:\/\/)";
+ // Test domain
+ $domain1 = "([[:alnum:]]([-[:alnum:]])*\.)?([[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})?";
+ // Test double-domains (e.g. .de.vu)
+ $domain2 = "([-[:alnum:]])?(\.[[:alnum:]][-[:alnum:]\.]*[[:alnum:]])(\.[[:alpha:]]{2,5})(\.[[:alpha:]]{2,5})?";
+ // Test IP number
+ $ip = "([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})\.([[:digit:]]{1,3})";
+ // ... directory
+ $dir = "((/)+([-_\.[:alnum:]])+)*";
+ // ... page
+ $page = "/([-_[:alnum:]][-\._[:alnum:]]*\.[[:alnum:]]{2,5})?";
+ // ... and the string after and including question character
+ $getstring1 = "([\?/]([[:alnum:]][-\._%[:alnum:]]*(=)?([-\@\._:%[:alnum:]])+)(&([[:alnum:]]([-_%[:alnum:]])*(=)?([-\@\[\._:%[:alnum:]])+(\])*))*)?";
+ // Pattern for URLs like http://url/dir/doc.html?var=value
+ $pattern['d1dpg1'] = $http . $domain1 . $dir . $page . $getstring1;
+ $pattern['d2dpg1'] = $http . $domain2 . $dir . $page . $getstring1;
+ $pattern['ipdpg1'] = $http . $ip . $dir . $page . $getstring1;
+ // Pattern for URLs like http://url/dir/?var=value
+ $pattern['d1dg1'] = $http . $domain1 . $dir.'/' . $getstring1;
+ $pattern['d2dg1'] = $http . $domain2 . $dir.'/' . $getstring1;
+ $pattern['ipdg1'] = $http . $ip . $dir.'/' . $getstring1;
+ // Pattern for URLs like http://url/dir/page.ext
+ $pattern['d1dp'] = $http . $domain1 . $dir . $page;
+ $pattern['d1dp'] = $http . $domain2 . $dir . $page;
+ $pattern['ipdp'] = $http . $ip . $dir . $page;
+ // Pattern for URLs like http://url/dir
+ $pattern['d1d'] = $http . $domain1 . $dir;
+ $pattern['d2d'] = $http . $domain2 . $dir;
+ $pattern['ipd'] = $http . $ip . $dir;
+ // Pattern for URLs like http://url/?var=value
+ $pattern['d1g1'] = $http . $domain1 . '/' . $getstring1;
+ $pattern['d2g1'] = $http . $domain2 . '/' . $getstring1;
+ $pattern['ipg1'] = $http . $ip . '/' . $getstring1;
+ // Pattern for URLs like http://url?var=value
+ $pattern['d1g12'] = $http . $domain1 . $getstring1;
+ $pattern['d2g12'] = $http . $domain2 . $getstring1;
+ $pattern['ipg12'] = $http . $ip . $getstring1;
+ // Test all patterns
+ $reg = false;
+ foreach ($pattern as $key => $pat) {
+ // Debug regex?
+ if (isDebugRegExpressionEnabled()) {
+ // @TODO Are these convertions still required?
+ $pat = str_replace('.', "\.", $pat);
+ $pat = str_replace('@', "\@", $pat);
+ echo $key."= " . $pat . "<br />";
+ } // END - if
+
+ // Check if expression matches
+ $reg = ($reg || preg_match(('^' . $pat.'^'), $url));
+
+ // Does it match?
+ if ($reg === true) break;
+ }
+
+ // Return true/false
+ return $reg;
+}
+
+// Wtites data to a config.php-style file
+// @TODO Rewrite this function to use readFromFile() and writeToFile()
+function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
+ // Initialize some variables
+ $done = false;
+ $seek++;
+ $next = -1;
+ $found = false;
+
+ // Is the file there and read-/write-able?
+ if ((isFileReadable($FQFN)) && (is_writeable($FQFN))) {
+ $search = 'CFG: ' . $comment;
+ $tmp = $FQFN . '.tmp';
+
+ // Open the source file
+ $fp = fopen($FQFN, 'r') or OUTPUT_HTML('<strong>READ:</strong> ' . $FQFN . "<br />\n");
+
+ // Is the resource valid?
+ if (is_resource($fp)) {
+ // Open temporary file
+ $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('<strong>WRITE:</strong> ' . $tmp . "<br />\n");
+
+ // Is the resource again valid?
+ if (is_resource($fp_tmp)) {
+ while (!feof($fp)) {
+ // Read from source file
+ $line = fgets ($fp, 1024);
+
+ if (strpos($line, $search) > -1) { $next = 0; $found = true; }
+
+ if ($next > -1) {
+ if ($next === $seek) {
+ $next = -1;
+ $line = $prefix . $DATA . $suffix . "\n";
+ } else {
+ $next++;
+ }
+ }
+
+ // Write to temp file
+ fputs($fp_tmp, $line);
+ } // END - while
+
+ // Close temp file
+ fclose($fp_tmp);
+
+ // Finished writing tmp file
+ $done = true;
+ } // END - if
+
+ // Close source file
+ fclose($fp);
+
+ if (($done === true) && ($found === true)) {
+ // Copy back tmp file and delete tmp :-)
+ copyFileVerified($tmp, $FQFN, 0644);
+ return removeFile($tmp);
+ } elseif ($found === false) {
+ OUTPUT_HTML('<strong>CHANGE:</strong> 404!');
+ } else {
+ OUTPUT_HTML('<strong>TMP:</strong> UNDONE!');
+ }
+ }
+ } else {
+ // File not found, not readable or writeable
+ OUTPUT_HTML('<strong>404:</strong> ' . $FQFN . '<br />');
+ }
+
+ // An error was detected!
+ return false;
+}
+// Send notification to admin
+function sendAdminNotification ($subject, $templateName, $content=array(), $uid = '0') {
+ if (GET_EXT_VERSION('admins') >= '0.4.1') {
+ // Send new way
+ SEND_ADMIN_EMAILS_PRO($subject, $templateName, $content, $uid);
+ } else {
+ // Send out out-dated way
+ $message = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
+ SEND_ADMIN_EMAILS($subject, $message);
+ }
+}
+
+// Debug message logger
+function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
+ // Is debug mode enabled?
+ if ((isDebugModeEnabled()) || ($force === true)) {
+ // Remove CRLF
+ $message = str_replace("\r", '', str_replace("\n", '', $message));
+
+ // Log this message away
+ $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or app_die(__FUNCTION__, __LINE__, "Cannot write logfile debug.log!");
+ fwrite($fp, date("d.m.Y|H:i:s", time())."|" . getModule()."|".basename($funcFile)."|" . $line."|".strip_tags($message)."\n");
+ fclose($fp);
+ } // END - if
+}
+
+// Load more reset scripts
+function runResetIncludes () {
+ // Is the reset set or old sql_patches?
+ if ((!isResetModeEnabled()) || (EXT_VERSION_IS_OLDER('sql_patches', '0.4.5'))) {
+ // Then abort here
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot run reset! Please report this bug. Thanks");
+ } // END - if
+
+ // Get more daily reset scripts
+ SET_INC_POOL(getArrayFromDirectory('inc/reset/', 'reset_'));
+
+ // Update database
+ if (getConfig('DEBUG_RESET') != 'Y') updateConfiguration('last_update', time());
+
+ // Is the config entry set?
+ if (GET_EXT_VERSION('sql_patches') >= '0.4.2') {
+ // Create current week mark
+ $currWeek = date('W', time());
+
+ // Has it changed?
+ if (getConfig('last_week') != $currWeek) {
+ // Include weekly reset scripts
+ MERGE_INC_POOL(getArrayFromDirectory('inc/weekly/', 'weekly_'));
+
+ // Update config
+ if (getConfig('DEBUG_WEEKLY') != 'Y') updateConfiguration('last_week', $currWeek);
+ } // END - if
+
+ // Create current month mark
+ $currMonth = date('m', time());
+
+ // Has it changed?
+ if (getConfig('last_month') != $currMonth) {
+ // Include monthly reset scripts
+ MERGE_INC_POOL(getArrayFromDirectory('inc/monthly/', 'monthly_'));
+
+ // Update config
+ if (getConfig('DEBUG_MONTHLY') != 'Y') updateConfiguration('last_month', $currMonth);
+ } // END - if
+ } // END - if
+
+ // Run the filter
+ runFilterChain('load_includes');
+}
+
+// Handle extra values
+function handleExtraValues ($filterFunction, $value, $extraValue) {
+ // Default is the value itself
+ $ret = $value;
+
+ // Do we have a special filter function?
+ if (!empty($filterFunction)) {
+ // Does the filter function exist?
+ if (function_exists($filterFunction)) {
+ // Do we have extra parameters here?
+ if (!empty($extraValue)) {
+ // Put both parameters in one new array by default
+ $args = array($value, $extraValue);
+
+ // If we have an array simply use it and pre-extend it with our value
+ if (is_array($extraValue)) {
+ // Make the new args array
+ $args = merge_array(array($value), $extraValue);
+ } // END - if
+
+ // Call the multi-parameter call-back
+ $ret = call_user_func_array($filterFunction, $args);
+ } else {
+ // One parameter call
+ $ret = call_user_func($filterFunction, $value);
+ }
+ } // END - if
+ } // END - if
+
+ // Return the value
+ return $ret;
+}
+
+// Converts timestamp selections into a timestamp
+function convertSelectionsToTimestamp (&$POST, &$DATA, &$id, &$skip) {
+ // Init test variable
+ $test2 = '';
+
+ // Get last three chars
+ $test = substr($id, -3);
+
+ // Improved way of checking! :-)
+ if (in_array($test, array('_ye', '_mo', '_we', '_da', '_ho', '_mi', '_se'))) {
+ // Found a multi-selection for timings?
+ $test = substr($id, 0, -3);
+ if ((isset($POST[$test.'_ye'])) && (isset($POST[$test.'_mo'])) && (isset($POST[$test.'_we'])) && (isset($POST[$test.'_da'])) && (isset($POST[$test.'_ho'])) && (isset($POST[$test.'_mi'])) && (isset($POST[$test.'_se'])) && ($test != $test2)) {
+ // Generate timestamp
+ $POST[$test] = createTimestampFromSelections($test, $POST);
+ $DATA[] = sprintf("%s='%s'", $test, $POST[$test]);
+
+ // Remove data from array
+ foreach (array('ye', 'mo', 'we', 'da', 'ho', 'mi', 'se') as $rem) {
+ unset($POST[$test.'_' . $rem]);
+ } // END - foreach
+
+ // Skip adding
+ unset($id); $skip = true; $test2 = $test;
+ } // END - if
+ } else {
+ // Process this entry
+ $skip = false;
+ $test2 = '';
+ }
+}
+
+// Reverts the german decimal comma into Computer decimal dot
+function convertCommaToDot ($str) {
+ // Default float is not a float... ;-)
+ $float = false;
+
+ // Which language is selected?
+ switch (getLanguage()) {
+ case 'de': // German language
+ // Remove german thousand dots first
+ $str = str_replace('.', '', $str);
+
+ // Replace german commata with decimal dot and cast it
+ $float = (float)str_replace(',', '.', $str);
+ break;
+
+ default: // US and so on
+ // Remove thousand dots first and cast
+ $float = (float)str_replace(',', '', $str);
+ break;
+ }
+
+ // Return float
+ return $float;
+}
+
+// Handle menu-depending failed logins and return the rendered content
+function HANDLE_LOGIN_FAILTURES ($accessLevel) {
+ // Default output is empty ;-)
+ $OUT = '';
+
+ // Is the session data set?
+ if ((isSessionVariableSet('mxchange_' . $accessLevel.'_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel.'_last_fail'))) {
+ // Ignore zero values
+ if (getSession('mxchange_' . $accessLevel.'_failures') > 0) {
+ // Non-guest has login failures found, get both data and prepare it for template
+ //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):accessLevel={$accessLevel}<br />\n";
+ $content = array(
+ 'login_failures' => getSession('mxchange_' . $accessLevel.'_failures'),
+ 'last_failure' => generateDateTime(getSession('mxchange_' . $accessLevel.'_last_fail'), '2')
+ );
+
+ // Load template
+ $OUT = LOAD_TEMPLATE('login_failures', true, $content);
+ } // END - if
+
+ // Reset session data
+ setSession('mxchange_' . $accessLevel.'_failures', '');
+ setSession('mxchange_' . $accessLevel.'_last_fail', '');
+ } // END - if
+
+ // Return rendered content
+ return $OUT;
+}
+
+// Rebuild cache
+function rebuildCacheFiles ($cache, $inc = '') {
+ // Shall I remove the cache file?
+ if ((EXT_IS_ACTIVE('cache')) && (isCacheInstanceValid())) {
+ // Rebuild cache
+ if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
+ // Destroy it
+ $GLOBALS['cache_instance']->destroyCacheFile();
+ } // END - if
+
+ // Include file given?
+ if (!empty($inc)) {
+ // Construct FQFN
+ $INC = sprintf("inc/loader/load_cache-%s.php", $inc);
+
+ // Is the include there?
+ if (isIncludeReadable($INC)) {
+ // And rebuild it from scratch
+ //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): inc={$inc} - LOADED!<br />\n";
+ loadInclude($INC);
+ } else {
+ // Include not found!
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Include {$inc} not found. cache={$cache}");
+ }
+ } // END - if
+ } // END - if
+}
+
+// Purge admin menu cache
+function cachePurgeAdminMenu ($id=0, $action = '', $what = '', $str = '') {
+ // Is the cache extension enabled or no cache instance or admin menu cache disabled?
+ if (!EXT_IS_ACTIVE('cache')) {
+ // Cache extension not active
+ return false;
+ } elseif (!isCacheInstanceValid()) {
+ // No cache instance!
+ DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
+ return false;
+ } elseif ((!isConfigEntrySet('cache_admin_menu')) || (getConfig('cache_admin_menu') != 'Y')) {
+ // Caching disabled (currently experiemental!)
+ return false;
+ }
+
+ // Experiemental feature!
+ debug_report_bug("<strong>Experimental feature:</strong> You have to delete the admin_*.cache files by yourself at this point.");
+}
+
+// Determines the real remote address
+function determineRealRemoteAddress () {
+ // Is a proxy in use?
+ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
+ // Proxy was used
+ $address = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
+ // Yet, another proxy
+ $address = $_SERVER['HTTP_CLIENT_IP'];
+ } else {
+ // The regular address when no proxy was used
+ $address = $_SERVER['REMOTE_ADDR'];
+ }
+
+ // This strips out the real address from proxy output
+ if (strstr($address, ',')){
+ $addressArray = explode(',', $address);
+ $address = $addressArray[0];
+ } // END - if
+
+ // Return the result
+ return $address;
+}
+
+// Adds a bonus mail to the queue
+// This is a high-level function!
+function addNewBonusMail ($data, $mode = '', $output=true) {
+ // Use mode from data if not set and availble ;-)
+ if ((empty($mode)) && (isset($data['mode']))) $mode = $data['mode'];
+
+ // Generate receiver list
+ $RECEIVER = generateReceiverList($data['cat'], $data['receiver'], $mode);
+
+ // Receivers added?
+ if (!empty($RECEIVER)) {
+ // Add bonus mail to queue
+ addBonusMailToQueue(
+ $data['subject'],
+ $data['text'],
+ $RECEIVER,
+ $data['points'],
+ $data['seconds'],
+ $data['url'],
+ $data['cat'],
+ $mode,
+ $data['receiver']
+ );
+
+ // Mail inserted into bonus pool
+ if ($output) LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_BONUS_SEND'));
+ } elseif ($output) {
+ // More entered than can be reached!
+ LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_MORE_SELECTED'));
+ } else {
+ // Debug log
+ DEBUG_LOG(__FUNCTION__, __LINE__, " cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
+ }
+}
+
+// Determines referal id and sets it
+function DETERMINE_REFID () {
+ // Check if refid is set
+ if ((REQUEST_ISSET_GET('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) {
+ // The variable user comes from the click-counter script click.php and we only accept this here
+ $GLOBALS['refid'] = bigintval(REQUEST_GET('user'));
+ } elseif (REQUEST_ISSET_POST('refid')) {
+ // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+ $GLOBALS['refid'] = strip_tags(REQUEST_POST('refid'));
+ } elseif (REQUEST_ISSET_GET('refid')) {
+ // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+ $GLOBALS['refid'] = strip_tags(REQUEST_GET('refid'));
+ } elseif (REQUEST_ISSET_GET('ref')) {
+ // Set refid=ref (the referal link uses such variable)
+ $GLOBALS['refid'] = strip_tags(REQUEST_GET('ref'));
+ } elseif ((isSessionVariableSet('refid')) && (getSession('refid') != 0)) {
+ // Set session refid als global
+ $GLOBALS['refid'] = bigintval(getSession('refid'));
+ } elseif ((GET_EXT_VERSION('sql_patches') != '') && (getConfig('def_refid') > 0)) {
+ // Set default refid as refid in URL
+ $GLOBALS['refid'] = getConfig(('def_refid'));
+ } elseif ((GET_EXT_VERSION('user') >= '0.3.4') && (getConfig('select_user_zero_refid')) == 'Y') {
+ // Select a random user which has confirmed enougth mails
+ $GLOBALS['refid'] = determineRandomReferalId();
+ } else {
+ // No default ID when sql_patches is not installed or none set
+ $GLOBALS['refid'] = 0;
+ }
+
+ // Set cookie when default refid > 0
+ if (!isSessionVariableSet('refid') || (!empty($GLOBALS['refid'])) || ((getSession('refid') == '0') && (getConfig('def_refid') > 0))) {
+ // Set cookie
+ setSession('refid', $GLOBALS['refid']);
+ } // END - if
+
+ // Return determined refid
+ return $GLOBALS['refid'];
+}
+
+// Enables the reset mode. Only call this function if you really want the
+// reset to be run!
+function enableResetMode () {
+ // Enable the reset mode
+ $GLOBALS['reset_enabled'] = true;
+
+ // Run filters
+ runFilterChain('reset_enabled');
+}
+
+// Our shutdown-function
+function shutdown () {
+ // Call the filter chain 'shutdown'
+ runFilterChain('shutdown', null, false);
+
+ if (SQL_IS_LINK_UP()) {
+ // Close link
+ SQL_CLOSE(__FILE__, __LINE__);
+ } elseif ((!isInstalling()) && (isInstalled())) {
+ // No database link
+ addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK_SHUTDOWN'));
+ }
+
+ // Stop executing here