More fixes for what/action deprecation in modules.php
[mailer.git] / inc / functions.php
index 6d414a53865611bdec27ee2af04646c29c66fff6..e779bae69271a9e53f4a732f5eb7e9f254b7adbb 100644 (file)
@@ -48,7 +48,7 @@ function IS_INC_WRITEABLE($inc) {
        } // END - if
 
        // Test if we can append data
-       $fp = @fopen($fqfn, 'a');
+       $fp = fopen($fqfn, 'a');
        if ($inc == "dummy") {
                // Remove dummy file
                fclose($fp);
@@ -114,8 +114,10 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                // Output cached HTML code
                $OUTPUT = ob_get_contents();
 
-               // Clear output buffer for later output
-               clearOutputBuffer();
+               // Clear output buffer for later output if output is found
+               if (!empty($OUTPUT)) {
+                       clearOutputBuffer();
+               } // END - if
 
                // Send HTTP header
                header("HTTP/1.1 200");
@@ -139,8 +141,8 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                while (strpos($OUTPUT, '{!') > 0) {
                        // Prepare the content and eval() it...
                        $newContent = "";
-                       $eval = "\$newContent = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
-                       @eval($eval);
+                       $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
+                       eval($eval);
 
                        // Was that eval okay?
                        if (empty($newContent)) {
@@ -160,7 +162,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
 
                // Compile and run finished rendered HTML code
                while (strpos($OUTPUT, '{!') > 0) {
-                       $eval = "\$OUTPUT = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
+                       $eval = "\$OUTPUT = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
                        eval($eval);
                } // END - while
 
@@ -186,8 +188,13 @@ function initFatalMessages () {
        $GLOBALS['fatal_messages'] = array();
 }
 
+// Getter for whole fatal error messages
+function getFatalArray () {
+       return $GLOBALS['fatal_messages'];
+}
+
 // Add a fatal error message to the queue array
-function addFatalMessage ($message, $extra="") {
+function addFatalMessage ($F, $L, $message, $extra="") {
        if (is_array($extra)) {
                // Multiple extras for a message with masks
                $message = call_user_func_array('sprintf', $extra);
@@ -200,7 +207,7 @@ function addFatalMessage ($message, $extra="") {
        $GLOBALS['fatal_messages'][] = $message;
 
        // Log fatal messages away
-       DEBUG_LOG(__FUNCTION__, __LINE__, " message={$message}");
+       DEBUG_LOG($F, $L, " message={$message}");
 }
 
 // Getter for total fatal message count
@@ -242,7 +249,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
        if ($template == "member_support_form") {
                // Support request of a member
                $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                       array($GLOBALS['userid']), __FILE__, __LINE__);
+                       array($GLOBALS['userid']), __FUNCTION__, __LINE__);
 
                // Is content an array?
                if (is_array($content)) {
@@ -340,7 +347,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
                $ret = "";
                if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
                        // Okay, compile it!
-                       $tmpl_file = "\$ret=\"".COMPILE_CODE(SQL_ESCAPE($tmpl_file))."\";";
+                       $tmpl_file = "\$ret=\"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";";
                        eval($tmpl_file);
                } else {
                        // Simply return loaded code
@@ -349,7 +356,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
 
                // Add surrounding HTML comments to help finding bugs faster
                $ret = "<!-- Template ".$template." - Start -->\n".$ret."<!-- Template ".$template." - End -->\n";
-       } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!isBooleanConstantAndTrue('mxchange_installed')))) {
+       } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
                // Only admins shall see this warning or when installation mode is active
                $ret = "<br /><span class=\"guest_failed\">".TEMPLATE_404."</span><br />
 (".basename($FQFN).")<br />
@@ -386,7 +393,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):TO={$TO},SUBJECT={$SUBJECT}<br />\n";
 
        // Compile subject line (for POINTS constant etc.)
-       $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(SQL_ESCAPE($SUBJECT))."\");";
+       $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(smartAddSlashes($SUBJECT))."\");";
        eval($eval);
 
        // Set from header
@@ -397,7 +404,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
                        return;
                } else {
                        // Load email address
-                       $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($TO)), __FILE__, __LINE__);
+                       $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($TO)), __FUNCTION__, __LINE__);
                        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result_email)."<br />\n";
 
                        // Does the user exist?
@@ -439,11 +446,11 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
        }
 
        // Compile "TO"
-       $eval = "\$TO = \"".COMPILE_CODE(SQL_ESCAPE($TO))."\";";
+       $eval = "\$TO = \"".COMPILE_CODE(smartAddSlashes($TO))."\";";
        eval($eval);
 
        // Compile "MSG"
-       $eval = "\$MSG = \"".COMPILE_CODE(SQL_ESCAPE($MSG))."\";";
+       $eval = "\$MSG = \"".COMPILE_CODE(smartAddSlashes($MSG))."\";";
        eval($eval);
 
        // Fix HTML parameter (default is no!)
@@ -797,12 +804,12 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
                        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NICKNAME!<br />\n";
                        // Load nickname
                        $result = SQL_QUERY_ESC("SELECT surname, family, gender, email, nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                               array(bigintval($UID)), __FILE__, __LINE__);
+                               array(bigintval($UID)), __FUNCTION__, __LINE__);
                } else {
                        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NO-NICK!<br />\n";
                        /// Load normal data
                        $result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                               array(bigintval($UID)), __FILE__, __LINE__);
+                               array(bigintval($UID)), __FUNCTION__, __LINE__);
                }
 
                // Fetch and merge data
@@ -863,7 +870,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
 
                // Run code
                $tmpl_file = "\$newContent = decodeEntities(\"".COMPILE_CODE($tmpl_file)."\");";
-               @eval($tmpl_file);
+               eval($tmpl_file);
        } elseif (!empty($template)) {
                // Template file not found!
                $newContent = "{--TEMPLATE_404--}: ".$template."<br />
@@ -896,7 +903,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        return COMPILE_CODE($newContent);
 }
 //
-function MAKE_TIME($H, $M, $S, $stamp) {
+function MAKE_TIME ($H, $M, $S, $stamp) {
        // Extract day, month and year from given timestamp
        $DAY   = date("d", $stamp);
        $MONTH = date("m", $stamp);
@@ -906,7 +913,7 @@ function MAKE_TIME($H, $M, $S, $stamp) {
        return mktime($H, $M, $S, $MONTH, $DAY, $YEAR);
 }
 //
-function LOAD_URL($URL, $addUrlData=true) {
+function LOAD_URL ($URL, $addUrlData=true) {
        // Compile out URI codes
        $URL = compileUriCode($URL);
 
@@ -917,7 +924,8 @@ function LOAD_URL($URL, $addUrlData=true) {
        }
 
        // Get output buffer
-       //* DEBUG: */ debug_report_bug();
+       //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, $URL);
        $OUTPUT = ob_get_contents();
 
        // Clear it only if there is content
@@ -926,7 +934,7 @@ function LOAD_URL($URL, $addUrlData=true) {
        } // END - if
 
        // Add some data to URL if cookies are not accepted
-       if (((!defined('__COOKIES')) || (!__COOKIES)) && ($addUrlData)) $URL = ADD_URL_DATA($URL);
+       if (((!defined('__COOKIES')) || (!constant('__COOKIES'))) && ($addUrlData)) $URL = ADD_URL_DATA($URL);
 
        // Probe for bot from search engine
        if ((eregi("spider", GET_USER_AGENT())) || (eregi("bot", GET_USER_AGENT()))) {
@@ -964,7 +972,7 @@ function LOAD_CONFIGURED_URL ($configEntry) {
 }
 
 //
-function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
+function COMPILE_CODE ($code, $simple = false, $constants = true, $full = true) {
        // Is the code a string?
        if (!is_string($code)) {
                // Silently return it
@@ -1062,8 +1070,7 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
  * Sie, dass es doch nicht so schwer ist! :-)                           *
  *                                                                      *
  ************************************************************************/
-function array_pk_sort(&$array, $a_sort, $primary_key = 0, $order = -1, $nums = false)
-{
+function array_pk_sort (&$array, $a_sort, $primary_key = 0, $order = -1, $nums = false) {
        $dummy = $array;
        while ($primary_key < count($a_sort)) {
                foreach ($dummy[$a_sort[$primary_key]] as $key => $value) {
@@ -1097,8 +1104,9 @@ function array_pk_sort(&$array, $a_sort, $primary_key = 0, $order = -1, $nums =
        // Write back sorted array
        $array = $dummy;
 }
+
 //
-function ADD_SELECTION($type, $DEFAULT, $prefix="", $id="0") {
+function ADD_SELECTION ($type, $DEFAULT, $prefix="", $id="0") {
        global $MONTH_DESCR;
        $OUT = "";
 
@@ -1211,14 +1219,14 @@ function ADD_SELECTION($type, $DEFAULT, $prefix="", $id="0") {
        $OUT .= "    </select>\n";
        return $OUT;
 }
+
 //
-function TRANSLATE_YESNO($yn)
-{
+function TRANSLATE_YESNO ($yn) {
        // Default
-       $yn = "??? (".$yn.")";
+       $translated = "??? (".$yn.")";
        switch ($yn) {
-               case "Y": $yn = getMessage('YES'); break;
-               case "N": $yn = getMessage('NO'); break;
+               case "Y": $translated = getMessage('YES'); break;
+               case "N": $translated = getMessage('NO'); break;
                default:
                        // Log unknown value
                        DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn));
@@ -1226,8 +1234,9 @@ function TRANSLATE_YESNO($yn)
        }
 
        // Return it
-       return $yn;
+       return $translated;
 }
+
 //
 // Deprecated : $length
 // Optional   : $DATA
@@ -1286,7 +1295,7 @@ function GEN_RANDOM_CODE ($length, $code, $uid, $DATA="") {
 }
 
 // Does only allow numbers
-function bigintval($num, $castValue = true) {
+function bigintval ($num, $castValue = true) {
        // Filter all numbers out
        $ret = preg_replace("/[^0123456789]/", "", $num);
 
@@ -1546,6 +1555,7 @@ function CREATE_TIME_SELECTIONS ($timestamp, $prefix="", $display="", $align="ce
        }
        return $OUT;
 }
+
 //
 function CREATE_TIMESTAMP_FROM_SELECTIONS ($prefix, $POST) {
        // Initial return value
@@ -1591,11 +1601,11 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
 
        // Check which admin shall receive this mail
        $result = SQL_QUERY_ESC("SELECT DISTINCT admin_id FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' ORDER BY admin_id",
-               array($template), __FILE__, __LINE__);
+               array($template), __FUNCTION__, __LINE__);
        if (SQL_NUMROWS($result) == 0) {
                // Create new entry (to all admins)
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES (0, '%s')",
-                       array($template), __FILE__, __LINE__);
+                       array($template), __FUNCTION__, __LINE__);
        } else {
                // Load admin IDs...
                $aids = array();
@@ -1625,10 +1635,10 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
                        }
                } elseif ($aid == "0") {
                        // Select all email adresses
-                       $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FILE__, __LINE__);
+                       $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FUNCTION__, __LINE__);
                } else {
                        // If Admin-ID is not "to-all" select
-                       $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FILE__, __LINE__);
+                       $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FUNCTION__, __LINE__);
                }
        }
 
@@ -1640,6 +1650,7 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
        // Free memory
        SQL_FREERESULT($result);
 }
+
 //
 function CREATE_FANCY_TIME ($stamp) {
        // Get data array with years/months/weeks/days/...
@@ -1666,8 +1677,9 @@ function CREATE_FANCY_TIME ($stamp) {
        // Return fancy time string
        return $ret;
 }
+
 //
-function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) {
+function ADD_EMAIL_NAV ($PAGES, $offset, $show_form, $colspan, $return=false) {
        $SEP = ""; $TOP = "";
        if (!$show_form) {
                $TOP = " top2";
@@ -1926,6 +1938,7 @@ function SEND_RAW_REQUEST ($host, $request) {
        // Return response
        return $response;
 }
+
 // Taken from www.php.net eregi() user comments
 function VALIDATE_EMAIL($email) {
        // Compile email
@@ -2284,7 +2297,7 @@ function DISPLAY_PARSING_TIME_FOOTER() {
 
 // Check wether a boolean constant is set
 // Taken from user comments in PHP documentation for function constant()
-function isBooleanConstantAndTrue($constName) { // : Boolean
+function isBooleanConstantAndTrue ($constName) { // : Boolean
        // Failed by default
        $res = false;
 
@@ -2292,11 +2305,15 @@ function isBooleanConstantAndTrue($constName) { // : Boolean
        if (isset($GLOBALS['cache_array']['const'][$constName])) {
                // Use cache
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-CACHE!<br />\n";
-               $res = $GLOBALS['cache_array']['const'][$constName];
+               $res = ($GLOBALS['cache_array']['const'][$constName] === true);
        } else {
                // Check constant
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-RESOLVE!<br />\n";
-               if (defined($constName)) $res = (constant($constName) === true);
+               if (defined($constName)) {
+                       // Found!
+                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-FOUND!<br />\n";
+                       $res = (constant($constName) === true);
+               } // END - if
 
                // Set cache
                $GLOBALS['cache_array']['const'][$constName] = $res;
@@ -2361,14 +2378,14 @@ function GET_CURR_THEME() {
                        // Fix it to default
                        $ret = "default";
                } // END - if
-       } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
+       } elseif ((!isInstalled()) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
                // Prepare FQFN for checking
-               $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_GET('theme')));
+               $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET(('theme')));
 
                // Installation mode active
                if ((REQUEST_ISSET_GET(('theme'))) && (FILE_READABLE($theme))) {
                        // Set cookie from URL data
-                       set_session('mxchange_theme', SQL_ESCAPE(REQUEST_GET('theme')));
+                       set_session('mxchange_theme', REQUEST_GET(('theme')));
                } elseif (FILE_READABLE(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) {
                        // Set cookie from posted data
                        set_session('mxchange_theme', SQL_ESCAPE(REQUEST_POST('theme')));
@@ -2412,7 +2429,7 @@ function THEME_GET_ID ($name) {
        } elseif (GET_EXT_VERSION("cache") != "0.1.8") {
                // Check if current theme is already imported or not
                $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
-                       array($name), __FILE__, __LINE__);
+                       array($name), __FUNCTION__, __LINE__);
 
                // Entry found?
                if (SQL_NUMROWS($result) == 1) {
@@ -2586,12 +2603,12 @@ function LOAD_INC ($INC) {
 // Loads an include file once
 function LOAD_INC_ONCE ($INC) {
        // Is it not loaded?
-       if (!isset($GLOBALS['cache_array']['load_once'][$INC])) {
+       if (!isset($GLOBALS['load_once'][$INC])) {
                // Then try to load it
                LOAD_INC($INC);
 
                // And mark it as loaded
-               $GLOBALS['cache_array']['load_once'][$INC] = true;
+               $GLOBALS['load_once'][$INC] = "loaded";
        } // END - if
 }
 
@@ -2603,7 +2620,7 @@ function debug_get_printable_backtrace () {
        // Get and prepare backtrace for output
        $backtraceArray = debug_backtrace();
        foreach ($backtraceArray as $key => $trace) {
-               if (!isset($trace['file'])) $trace['file'] = __FILE__;
+               if (!isset($trace['file'])) $trace['file'] = __FUNCTION__;
                if (!isset($trace['line'])) $trace['line'] = __LINE__;
                if (!isset($trace['args'])) $trace['args'] = array();
                $backtrace .= "<li class=\"debug_list\"><span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span></li>\n";
@@ -2669,7 +2686,7 @@ function convertCodeToMessage ($code) {
 
                case constant('CODE_EXTENSION_PROBLEM'):
                        if (REQUEST_ISSET_GET(('ext'))) {
-                               $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), SQL_ESCAPE(REQUEST_GET('ext')));
+                               $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), REQUEST_GET(('ext')));
                        } else {
                                $msg = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
                        }
@@ -2698,7 +2715,7 @@ function REDIRCT_ON_UNINSTALLED_EXTENSION ($ext_name) {
 // Generate a "link" for the given admin id (aid)
 function GENERATE_AID_LINK ($aid) {
        // No assigned admin is default
-       $admin = "<div class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</div>";
+       $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
 
        // Zero? = Not assigned
        if ($aid == "0") {
@@ -2865,12 +2882,12 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
                $tmp = $FQFN.".tmp";
 
                // Open the source file
-               $fp = @fopen($FQFN, 'r') or OUTPUT_HTML("<strong>READ:</strong> ".$FQFN."<br />");
+               $fp = fopen($FQFN, 'r') or OUTPUT_HTML("<strong>READ:</strong> ".$FQFN."<br />");
 
                // Is the resource valid?
                if (is_resource($fp)) {
                        // Open temporary file
-                       $fp_tmp = @fopen($tmp, 'w') or OUTPUT_HTML("<strong>WRITE:</strong> ".$tmp."<br />");
+                       $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML("<strong>WRITE:</strong> ".$tmp."<br />");
 
                        // Is the resource again valid?
                        if (is_resource($fp_tmp)) {
@@ -2905,21 +2922,488 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
 
                        if (($done) && ($found)) {
                                // Copy back tmp file and delete tmp :-)
-                               @copy($tmp, $FQFN);
-                               @unlink($tmp);
-                               define('_FATAL', false);
+                               copy($tmp, $FQFN);
+                               return unlink($tmp);
                        } elseif (!$found) {
                                OUTPUT_HTML("<strong>CHANGE:</strong> 404!");
-                               define('_FATAL', true);
                        } else {
                                OUTPUT_HTML("<strong>TMP:</strong> UNDONE!");
-                               define('_FATAL', true);
                        }
                }
        } 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 SEND_ADMIN_NOTIFICATION($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 outdated way
+               $msg = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
+               SEND_ADMIN_EMAILS($subject, $msg);
+       }
+}
+
+// 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
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
+               return $array1;
+       } elseif (is_array($array2)) {
+               // Return right array
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("array1 is not an array. array != %s", gettype($array1)));
+               return $array2;
+       }
+
+       // Both are not arrays
+       debug_report_bug(__FUNCTION__.": No arrays provided!");
+}
+
+// Debug message logger
+function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
+       // Is debug mode enabled?
+       if ((isBooleanConstantAndTrue('DEBUG_MODE')) || ($force === true)) {
+               // Log this message away
+               $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
+               fwrite($fp, date("d.m.Y|H:i:s", time())."|".basename($funcFile)."|".$line."|".strip_tags($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(constant('PATH') . $baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
+
+       // Read all entries
+       while ($baseFile = readdir($dirPointer)) {
+               // Load file only if extension is active
+               $INC = $baseDir.$baseFile;
+               $FQFN = constant('PATH') . $INC;
+
+               // Is this a valid reset file?
+               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
+               if ((FILE_READABLE($FQFN)) && (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[] = $INC;
+                       } elseif ($extId == 0) {
+                               // Add non-extension files as well
+                               $INCs[] = $INC;
+                       }
+               } // END - if
+       } // END - while
+
+       // Close directory
+       closedir($dirPointer);
+
+       // Sort array
+       asort($INCs);
+
+       // Return array with include files
+       return $INCs;
+}
+
+// Load more reset scripts
+function RESET_ADD_INCLUDES () {
+       // Is the reset set or old sql_patches?
+       if ((!defined('__DAILY_RESET')) || (EXT_VERSION_IS_OLDER("sql_patches", "0.4.5"))) {
+               // Then abort here
+               return array();
+       } // END - if
+
+       // Get more daily reset scripts
+       $INC_POOL = GET_DIR_AS_ARRAY("inc/reset/", "reset_");
+
+       // Update database
+       if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
+
+       // Create current week mark
+       $currWeek = date("W", time());
+
+       // Has it changed?
+       if (getConfig('last_week') != $currWeek) {
+               // Include weekly reset scripts
+               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_"));
+
+               // Update config
+               if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("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
+               $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_"));
+
+               // Update config
+               if (!defined('DEBUG_MONTHLY')) 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 = 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;
+}
+
+// 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[] = 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 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.'_failures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) {
+               // Ignore zero values
+               if (get_session('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' => get_session('mxchange_'.$accessLevel.'_failures'),
+                               'last_failure'   => MAKE_DATETIME(get_session('mxchange_'.$accessLevel.'_last_fail'), "2")
+                       );
+
+                       // Load template
+                       $OUT = LOAD_TEMPLATE("login_failures", true, $content);
+               } // END - if
+
+               // Reset session data
+               set_session('mxchange_'.$accessLevel.'_failures', "");
+               set_session('mxchange_'.$accessLevel.'_last_fail', "");
+       } // END - if
+
+       // Return rendered content
+       return $OUT;
+}
+
+// Rebuild cache
+function REBUILD_CACHE ($cache, $inc="") {
+       // Shall I remove the cache file?
+       if ((EXT_IS_ACTIVE("cache")) && (is_object($GLOBALS['cache_instance']))) {
+               // 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 (INCLUDE_READABLE($INC)) {
+                               // And rebuild it from scratch
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): inc={$inc} - LOADED!<br />\n";
+                               LOAD_INC($INC);
+                       } else {
+                               // Include not found!
+                               DEBUG_LOG(__FUNCTION__, __LINE__, "Include {$inc} not found. cache={$cache}");
+                       }
+               } // END - if
+       } // END - if
+}
+
+// Purge admin menu cache
+function CACHE_PURGE_ADMIN_MENU ($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 (!is_object($GLOBALS['cache_instance'])) {
+               // 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.");
+}
+
+// Translates the "pool type" into human-readable
+function TRANSLATE_POOL_TYPE ($type) {
+       // Default type is unknown
+       $translated = sprintf(getMessage('POOL_TYPE_UNKNOWN'), $type);
+
+       // Generate constant
+       $constName = sprintf("POOL_TYPE_%s", $type);
+
+       // Does it exist?
+       if (defined($constName)) {
+               // Then use it
+               $translated = getMessage($constName);
+       } // END - if
+
+       // Return "translation"
+       return $translated;
+}
+
+// "Getter" for remote IP number
+function GET_REMOTE_ADDR () {
+       // Get remote ip from environment
+       $remoteAddr = getenv('REMOTE_ADDR');
+
+       // Is removeip installed?
+       if (EXT_IS_ACTIVE("removeip")) {
+               // Then anonymize it
+               $remoteAddr = GET_ANONYMOUS_REMOTE_ADDR($remoteAddr);
+       } // END - if
+
+       // Return it
+       return $remoteAddr;
+}
+
+// "Getter" for remote hostname
+function GET_REMOTE_HOST () {
+       // Get remote ip from environment
+       $remoteHost = getenv('REMOTE_HOST');
+
+       // Is removeip installed?
+       if (EXT_IS_ACTIVE("removeip")) {
+               // Then anonymize it
+               $remoteHost = GET_ANONYMOUS_REMOTE_HOST($remoteHost);
+       } // END - if
+
+       // Return it
+       return $remoteHost;
+}
+
+// "Getter" for user agent
+function GET_USER_AGENT () {
+       // Get remote ip from environment
+       $userAgent = getenv('HTTP_USER_AGENT');
+
+       // Is removeip installed?
+       if (EXT_IS_ACTIVE("removeip")) {
+               // Then anonymize it
+               $userAgent = GET_ANONYMOUS_USER_AGENT($userAgent);
+       } // END - if
+
+       // Return it
+       return $userAgent;
+}
+
+// "Getter" for referer
+function GET_REFERER () {
+       // Get remote ip from environment
+       $referer = getenv('HTTP_REFERER');
+
+       // Is removeip installed?
+       if (EXT_IS_ACTIVE("removeip")) {
+               // Then anonymize it
+               $referer = GET_ANONYMOUS_REFERER($referer);
+       } // END - if
+
+       // Return it
+       return $referer;
+}
+
+// Adds a bonus mail to the queue
+// This is a high-level function!
+function ADD_NEW_BONUS_MAIL ($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 = GENERATE_RECEIVER_LIST($data['cat'], $data['receiver'], $mode);
+
+       // Receivers added?
+       if (!empty($RECEIVER)) {
+               // Add bonus mail to queue
+               ADD_BONUS_MAIL_TO_QUEUE(
+                       $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 () {
+       global $CLICK, $_SERVER;
+
+       // Check if refid is set
+       if ((!empty($_GET['user'])) && ($CLICK == 1) && (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($_GET['user']);
+       } elseif (!empty($_POST['refid'])) {
+               // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+               $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_POST['refid']));
+       } elseif (!empty($_GET['refid'])) {
+               // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
+               $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['refid']));
+       } elseif (!empty($_GET['ref'])) {
+               // Set refid=ref (the referal link uses such variable)
+               $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['ref']));
+       } elseif ((isSessionVariableSet('refid')) && (get_session('refid') != 0)) {
+               // Set session refid als global
+               $GLOBALS['refid'] = bigintval(get_session('refid'));
+       } elseif ((GET_EXT_VERSION("sql_patches") != "") && (getConfig('def_refid') > 0)) {
+               // Set default refid as refid in URL
+               $GLOBALS['refid'] = bigintval(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'] = SELECT_RANDOM_REFID();
+       } 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'])) || ((get_session('refid') == "0") && (getConfig('def_refid') > 0))) {
+               // Set cookie
+               set_session('refid', $GLOBALS['refid']);
+       } // END - if
+
+       // Return determined refid
+       return $GLOBALS['refid'];
+}
+
+// Check wether we are installing
+function isInstalling () {
+       return (isset($GLOBALS['mxchange_installing']));
+}
+
+// Check wether this script is installed
+function isInstalled () {
+       return isBooleanConstantAndTrue('mxchange_installed');
+}
+
+// Check wether an admin is registered
+function isAdminRegistered () {
+       return isBooleanConstantAndTrue('admin_registered');
 }
 
 //////////////////////////////////////////////////