+// Check wether a boolean constant is set
+// Taken from user comments in PHP documentation for function constant()
+function isBooleanConstantAndTrue($constName) { // : Boolean
+ global $constCache;
+
+ // Failed by default
+ $res = false;
+
+ // In cache?
+ if (isset($constCache[$constName])) {
+ // Use cache
+ $res = $constCache[$constName];
+ } else {
+ // Check constant
+ if (defined($constName)) $res = (constant($constName) === true);
+
+ // Set cache
+ $constCache[$constName] = $res;
+ }
+
+ // Return value
+ return $res;
+}
+
+// Check wether a session variable is set
+function isSessionVariableSet($var) {
+ //* DEBUG: */ echo __FUNCTION__.":var={$var}<br />\n";
+ return (isset($_SESSION[$var]));
+}
+// Returns wether the value of the session variable or NULL if not set
+function get_session($var) {
+ // Default is not found! ;-)
+ $value = null;
+
+ // Is the variable there?
+ if (isSessionVariableSet($var)) {
+ // Then get it secured!
+ $value = SQL_ESCAPE($_SESSION[$var]);
+ } // END - if
+
+ // Return the value
+ return $value;
+}
+// Send notification to admin
+function SEND_ADMIN_NOTIFICATION($subject, $templateName, $content="", $uid="0") {
+ if (GET_EXT_VERSION("admins") >= "0.4.1") {
+ // Send new way
+ SEND_ADMIN_EMAILS_PRO($subject, $templateName, $content, $uid);
+ } else {
+ // Send outdated way
+ $msg = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
+ SEND_ADMIN_EMAILS($subject, $msg);
+ }
+}
+// Destroy user session
+function destroy_user_session () {
+ // Remove all user data from session
+ return ((set_session("userid", "")) && (set_session("u_hash", "")) && (set_session("lifetime", "")));
+}
+// Merges an array together but only if both are arrays
+function merge_array ($array1, $array2) {
+ // Are both an array?
+ if ((is_array($array1)) && (is_array($array2))) {
+ // Merge all together
+ return array_merge($array1, $array2);
+ } elseif (is_array($array1)) {
+ // Return left array
+ return $array1;
+ }
+
+ // Something wired happened here...
+ print(__FUNCTION__.":<pre>");
+ debug_print_backtrace();
+ die("</pre>");
+}
+// Debug message logger
+function DEBUG_LOG ($message) {
+ // Is debug mode enabled?
+ if (isBooleanConstantAndTrue('DEBUG_MODE')) {
+ // Log this message away
+ $fp = fopen(PATH."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
+ fwrite($fp, date("d.m.Y|H:i:s", time())."|{$message}\n");
+ fclose($fp);
+ } // END - if
+}
+// Reads a directory with PHP files in and gets only files back
+function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
+ $INCs = array();
+
+ // Open directory
+ $dirPointer = opendir($baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
+
+ // Read all entries
+ while ($baseFile = readdir($dirPointer)) {
+ // Load file only if extension is active
+ // Make full path
+ $file = $baseDir.$baseFile;
+
+ // Is this a valid reset file?
+ //* DEBUG: */ echo __FUNCTION__.":baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
+ if ((is_file($file)) && (is_readable($file)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) {
+ // Remove both for extension name
+ $extName = substr($baseFile, strlen($prefix), -4);
+
+ // Try to find it
+ $extId = GET_EXT_ID($extName);
+
+ // Is the extension valid and active?
+ if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
+ // Then add this file
+ $INCs[] = $file;
+ } elseif ($extId == 0) {
+ // Add non-extension files as well
+ $INCs[] = $file;
+ }
+ } // END - if
+ } // END - while
+
+ // Close directory
+ closedir($dirPointer);
+
+ // Return array with include files
+ return $INCs;
+}
+// Load more reset scripts
+function RESET_ADD_INCLUDES () {
+ global $_CONFIG;
+
+ // Is the reset set or old sql_patches?
+ if ((!isBooleanConstantAndTrue('__DAILY_RESET')) || (GET_EXT_VERSION("sql_patches") < "0.4.5")) {
+ // Then abort here
+ return;
+ } // END - if
+
+ // Get more daily reset scripts
+ $INC_POOL = GET_DIR_AS_ARRAY(PATH."inc/reset/", "reset_");
+
+ // Create current week mark
+ $currWeek = date("W", time());
+
+ // Has it changed?
+ if ($_CONFIG['last_week'] != $currWeek) {
+ // Include weekly reset scripts
+ $INC_POOL = array_merge($INC_POOL, GET_DIR_AS_ARRAY(PATH."inc/weekly/", "weekly_"));
+
+ // Update config
+ UPDATE_CONFIG("last_week", $currWeek);
+ } // END - if
+
+ // Create current month mark
+ $currMonth = date("m", time());
+
+ // Has it changed?
+ if ($_CONFIG['last_month'] != $currMonth) {
+ // Include monthly reset scripts
+ $INC_POOL = array_merge($INC_POOL, GET_DIR_AS_ARRAY(PATH."inc/monthly/", "monthly_"));
+
+ // Update config
+ UPDATE_CONFIG("last_month", $currMonth);
+ } // END - if
+
+ // Return array
+ return $INC_POOL;
+}
+// Handle extra values
+function HANDLE_EXTRA_VALUES ($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 = array_merge(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;
+}
+// Check if given FQFN is a readable file
+function FILE_READABLE($fqfn) {
+ // Check all...
+ return ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn)));
+}
+// Converts timestamp selections into a timestamp
+function CONVERT_SELECTIONS_TO_TIMESTAMP(&$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] = CREATE_TIMESTAMP_FROM_SELECTIONS($TEST, $POST);
+ $DATA[] = "$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 REVERT_COMMA ($str) {
+ // Default float is not a float... ;-)
+ $float = false;
+
+ // Which language is selected?
+ switch (GET_LANGUAGE()) {
+ 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.'_failtures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) {
+ // Ignore zero values
+ if (get_session('mxchange_'.$accessLevel.'_failtures') > 0) {
+ // Non-guest has login failtures found, get both data and prepare it for template
+ //* DEBUG: */ echo __FUNCTION__.":accessLevel={$accessLevel}<br />\n";
+ $content = array(
+ 'login_failtures' => get_session('mxchange_'.$accessLevel.'_failtures'),
+ 'last_failture' => MAKE_DATETIME(get_session('mxchange_'.$accessLevel.'_last_fail'), "2")
+ );
+
+ // Load template
+ $OUT = LOAD_TEMPLATE("login_failtures", true, $content);
+ } // END - if
+
+ // Reset session data
+ set_session('mxchange_'.$accessLevel.'_failtures', "");
+ set_session('mxchange_'.$accessLevel.'_last_fail', "");
+ } // END - if
+
+ // Return rendered content
+ return $OUT;
+}
+// Rebuild cache
+function REBUILD_CACHE ($cache, $inc="") {
+ global $cacheInstance;
+
+ // Shall I remove the cache file?
+ if ((EXT_IS_ACTIVE("cache")) && (is_object($cacheInstance))) {
+ // Rebuild cache
+ if ($cacheInstance->cache_file("admins", true)) {
+ // Destroy it
+ $cacheInstance->cache_destroy();
+
+ // Include file given?
+ if (!empty($inc)) {
+ // And rebuild it from scratch
+ require_once(PATH."inc/loader/load_cache-".$inc.".php");
+ } // END - if
+ } // END - if
+ } // END - if
+}