+
+// 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
+ exit;
+}
+
+// Setter for userid
+function setUserId ($userid) {
+ $GLOBALS['userid'] = bigintval($userid);
+}
+
+// Getter for userid or returns zero
+function getUserId () {
+ // Default userid
+ $userid = 0;
+
+ // Is the userid set?
+ if (isUserIdSet()) {
+ // Then use it
+ $userid = $GLOBALS['userid'];
+ } // END - if
+
+ // Return it
+ return $userid;
+}
+
+// Checks ether the userid is set
+function isUserIdSet () {
+ return (isset($GLOBALS['userid']));
+}
+
+// Handle message codes from URL
+function handleCodeMessage () {
+ if (REQUEST_ISSET_GET('msg')) {
+ // Default extension is 'unknown'
+ $ext = 'unknown';
+
+ // Is extension given?
+ if (REQUEST_ISSET_GET('ext')) $ext = REQUEST_GET('ext');
+
+ // Convert the 'msg' parameter from URL to a human-readable message
+ $message = convertCodeToMessage(REQUEST_GET('msg'));
+
+ // Load message template
+ LOAD_TEMPLATE('message', false, $message);
+ } // END - if
+}
+
+// Setter for extra title
+function setExtraTitle ($extraTitle) {
+ $GLOBALS['extra_title'] = $extraTitle;
+}
+
+// Getter for extra title
+function getExtraTitle () {
+ // Is the extra title set?
+ if (!isExtraTitleSet()) {
+ // No, then abort here
+ debug_report_bug('extra_title is not set!');
+ } // END - if
+
+ // Return it
+ return $GLOBALS['extra_title'];
+}
+
+// Checks if the extra title is set
+function isExtraTitleSet () {
+ return ((isset($GLOBALS['extra_title'])) && (!empty($GLOBALS['extra_title'])));
+}
+
+// Generates a 'extension foo inactive' message
+function generateExtensionInactiveMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ trigger_error(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), $ext_name);
+
+ // Is an admin logged in?
+ if (IS_ADMIN()) {
+ // Then output admin message
+ $message = sprintf(getMessage('ADMIN_EXTENSION_PROBLEM_EXT_INACTIVE'), $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a 'extension foo not installed' message
+function generateExtensionNotInstalledMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ trigger_error(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_EXT_NOT_INSTALLED'), $ext_name);
+
+ // Is an admin logged in?
+ if (IS_ADMIN()) {
+ // Then output admin message
+ $message = sprintf(getMessage('ADMIN_EXTENSION_PROBLEM_EXT_NOT_INSTALLED'), $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a message depending on if the extension is not installed or not
+// just activated
+function generateExtensionInactiveNotInstalledMessage ($ext_name) {
+ // Init message
+ $message = '';
+
+ // Is the extension not installed or just deactivated?
+ switch (isExtensionInstalled($ext_name)) {
+ case true; // Deactivated!
+ $message = generateExtensionInactiveMessage($ext_name);
+ break;
+
+ case false; // Not installed!
+ $message = generateExtensionNotInstalledMessage($ext_name);
+ break;
+
+ default: // Should not happen!
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name));
+ $message = sprintf("Invalid state of extension %s detected.", $ext_name);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+