unneccessary globals removed
[mailer.git] / inc / mysql-manager.php
index 593e21e0295076ec8c555f1c7b1a459850dfe5fe..da0aa7159611826a404838f107ab7fd70ba07e1f 100644 (file)
@@ -41,18 +41,18 @@ if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
 //
 function ADD_MODULE_TITLE($mod)
 {
-       global $MODULES, $CONFIG;
+       global $cacheArray, $_CONFIG;
        $name = ""; $result = false;
        // Load title
        if (!mxchange_installing)
        {
-               if ((GET_EXT_VERSION("cache") >= "0.1.2") && (is_array($MODULES['module'])) && (isset($MODULES['module'][$mod])))
+               if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module'])) && (isset($cacheArray['modules']['module'][$mod])))
                {
                        // Load from cache
-                       $name = $MODULES['title'][$mod];
+                       $name = $cacheArray['modules']['title'][$mod];
 
                        // Update cache hits
-                       $CONFIG['cache_hits']++;
+                       $_CONFIG['cache_hits']++;
                }
                 else
                {
@@ -79,27 +79,24 @@ function ADD_MODULE_TITLE($mod)
        }
        return $name;
 }
-//
-function CHECK_MODULE($mod)
-{
+// Check validity of a given module name (no file extension)
+function CHECK_MODULE($mod) {
        // We need them now here...
-       global $MODULES, $CONFIG, $CACHE;
+       global $cacheArray, $_CONFIG, $cacheInstance;
 
        // Filter module name (names with low chars and underlines are fine!)
        $mod = preg_replace("/[^a-z_]/", "", $mod);
 
        // Check for prefix is a extension...
-       $MOD_SPLIT = explode("_", $mod);
+       $modSplit = explode("_", $mod);
        $extension = ""; $mod_chk = $mod;
-       //* DEBUG: */ echo __LINE__."*".count($MOD_SPLIT)."*/".$mod."*<BR>";
-       if (count($MOD_SPLIT) == 2)
-       {
+       //* DEBUG: */ echo __LINE__."*".count($modSplit)."*/".$mod."*<br />";
+       if (count($modSplit) == 2) {
                // Okay, there is a seperator (_) in the name so is the first part a module?
-               //* DEBUG: */ echo __LINE__."*".$MOD_SPLIT[0]."*<BR>";
-               if (EXT_IS_ACTIVE($MOD_SPLIT[0]))
-               {
+               //* DEBUG: */ echo __LINE__."*".$modSplit[0]."*<br />";
+               if (EXT_IS_ACTIVE($modSplit[0])) {
                        // The prefix is an extension's name, so let's set it
-                       $extension = $MOD_SPLIT[0]; $mod = $MOD_SPLIT[1];
+                       $extension = $modSplit[0]; $mod = $modSplit[1];
                }
        }
 
@@ -111,30 +108,26 @@ function CHECK_MODULE($mod)
 
        // Check if cache is latest version
        $locked = 'Y'; $hidden = 'N'; $admin = 'N'; $mem = 'N'; $found = false;
-       if ((GET_EXT_VERSION("cache") >= "0.1.2") && (is_array($MODULES['module'])))
-       {
+       if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module']))) {
                // Is the module cached?
-               if (isset($MODULES['locked'][$mod_chk])) {
+               if (isset($cacheArray['modules']['locked'][$mod_chk])) {
                        // Check cache
-                       $locked = $MODULES['locked'][$mod_chk];
-                       $hidden = $MODULES['hidden'][$mod_chk];
-                       $admin  = $MODULES['admin_only'][$mod_chk];
-                       $mem    = $MODULES['mem_only'][$mod_chk];
+                       $locked = $cacheArray['modules']['locked'][$mod_chk];
+                       $hidden = $cacheArray['modules']['hidden'][$mod_chk];
+                       $admin  = $cacheArray['modules']['admin_only'][$mod_chk];
+                       $mem    = $cacheArray['modules']['mem_only'][$mod_chk];
 
                        // Update cache hits
-                       $CONFIG['cache_hits']++;
+                       $_CONFIG['cache_hits']++;
                        $found = true;
                } else {
                        // No, then we have to update it!
                        $ret = "cache_miss";
                }
-       }
-        else
-       {
+       } else {
                // Check for module in database
                $result = SQL_QUERY_ESC("SELECT locked, hidden, admin_only, mem_only FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1", array($mod_chk), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+               if (SQL_NUMROWS($result) == 1) {
                        // Read data
                        list($locked, $hidden, $admin, $mem) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
@@ -145,33 +138,24 @@ function CHECK_MODULE($mod)
        // Check returned values against current access permissions
        //
        //  Admin access            ----- Guest access -----           --- Guest   or   member? ---
-       if ((IS_ADMIN()) || (($locked == 'N') && ($admin == 'N') && (($mem == 'N') || (IS_LOGGED_IN()))))
-       {
+       if ((IS_ADMIN()) || (($locked == 'N') && ($admin == 'N') && (($mem == 'N') || (IS_LOGGED_IN())))) {
                // If you are admin you are welcome for everything!
                $ret = "done";
-       }
-        elseif ($locked == 'Y')
-       {
+       } elseif ($locked == 'Y') {
                // Module is locked
                $ret = "locked";
-       }
-        elseif (($mem == 'Y') && (!IS_LOGGED_IN()))
-       {
+       } elseif (($mem == 'Y') && (!IS_LOGGED_IN())) {
                // You have to login first!
                $ret = "mem_only";
-       }
-        elseif (($admin == 'Y') && (!IS_ADMIN()))
-       {
+       } elseif (($admin == 'Y') && (!IS_ADMIN())) {
                // Only the Admin is allowed to enter this module!
                $ret = "admin_only";
        }
 
        // Still no luck or not found?
-       if (($ret == "major") || ($ret == "cache_miss") || (!$found))
-       {
+       if (($ret == "major") || ($ret == "cache_miss") || (!$found)) {
                //         ----- Legacy module -----                      ---- Module in base folder  ----           --- Module with extension's name ---
-               if ((file_exists(PATH."inc/modules/".$mod.".php")) || (file_exists(PATH.$mod.".php")) || (file_exists(PATH.$extension."/".$mod.".php")))
-               {
+               if ((file_exists(PATH."inc/modules/".$mod.".php")) || (file_exists(PATH.$mod.".php")) || (file_exists(PATH.$extension."/".$mod.".php"))) {
                        // Data is missing so we add it
                        if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
                                // Since 0.3.6 we have a has_menu column, this took me a half hour
@@ -193,17 +177,14 @@ function CHECK_MODULE($mod)
                        }
 
                        // Destroy cache here
-                       if (GET_EXT_VERSION("cache") >= "0.1.2")
-                       {
-                               if ($CACHE->cache_file("mod_reg", true)) $CACHE->cache_destroy();
-                               unset($MODULES);
+                       if (GET_EXT_VERSION("cache") >= "0.1.2") {
+                               if ($cacheInstance->cache_file("mod_reg", true)) $cacheInstance->cache_destroy();
+                               unset($cacheArray['modules']);
                        }
 
                        // And reload data
                        $ret = CHECK_MODULE($mod_chk);
-               }
-                else
-               {
+               } else {
                        // Module not found we don't add it to the database
                        $ret = "404";
                }
@@ -212,14 +193,13 @@ function CHECK_MODULE($mod)
        // Return the value
        return $ret;
 }
-//
+// Add menu description pending on given file name (without path!)
 function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
 {
-       global $DEPTH, $CONFIG;
+       global $DEPTH, $_CONFIG;
        $LINK_ADD = ""; $OUT = ""; $AND = "";
        // First we have to do some analysis...
-       if (ereg("action-", $file))
-       {
+       if (ereg("action-", $file)) {
                // This is an action file!
                $type = "action";
                $search = substr($file, 7);
@@ -236,9 +216,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
                        break;
                }
                $AND = " AND what=''";
-       }
-        elseif (ereg("what-", $file))
-       {
+       } elseif (ereg("what-", $file)) {
                // This is an admin what file!
                $type = "what";
                $search = substr($file, 5);
@@ -252,85 +230,68 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
                case "guest":
                case "member":
                        $MOD_CHECK = $GLOBALS['module'];
-                       if (!IS_ADMIN())
-                       {
+                       if (!IS_ADMIN()) {
                                $AND = " AND visible='Y' AND locked='N'";
                        }
                        break;
                }
-               $DUMMY = substr($search, 0, -4);
-               $AND .= " AND action='".GET_ACTION($ACC_LVL, $DUMMY)."'";
-       }
-        elseif (($ACC_LVL == "sponsor") || ($ACC_LVL == "engine"))
-       {
+               $dummy = substr($search, 0, -4);
+               $AND .= " AND action='".GET_ACTION($ACC_LVL, $dummy)."'";
+       } elseif (($ACC_LVL == "sponsor") || ($ACC_LVL == "engine")) {
                // Sponsor / engine menu
                $type = "what";
                $search = $file;
                $MOD_CHECK = $GLOBALS['module'];
                $AND = "";
-       }
-        else
-       {
+       } else {
                // Other
                $type = "menu";
                $search = $file;
                $MOD_CHECK = $GLOBALS['module'];
                $AND = "";
        }
-       if ((!isset($DEPTH)) && (!$return))
-       {
+       if ((!isset($DEPTH)) && (!$return)) {
                $DEPTH = "0";
                $prefix = "<DIV class=\"you_are_here\">".YOU_ARE_HERE."&nbsp;<STRONG><A class=\"you_are_here\" href=\"".URL."/modules.php?module=".$GLOBALS['module'].$LINK_ADD."\">Home</A></STRONG>";
-       }
-        else
-       {
+       } else {
                if (!$return) $DEPTH++;
                $prefix = "";
        }
        $prefix .= "&nbsp;-&gt;&nbsp;";
-       if (ereg(".php", $search))
-       {
+       if (ereg(".php", $search)) {
                $search = substr($search, 0, strpos($search, ".php"));
        }
        $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_%s_menu WHERE %s='%s' ".$AND." LIMIT 1",
         array($ACC_LVL, $type, $search), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+       if (SQL_NUMROWS($result) == 1) {
                list($ret) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
-               if ($return)
-               {
+               if ($return) {
                        // Return title
                        return $ret;
-               }
-                elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($CONFIG['youre_here'] == 'Y')) || ((IS_ADMIN()) && ($MOD_CHECK == "admin")))
-               {
+               } elseif (((GET_EXT_VERSION("sql_patches") >= "0.2.3") && ($_CONFIG['youre_here'] == 'Y')) || ((IS_ADMIN()) && ($MOD_CHECK == "admin"))) {
                        // Output HTML code
                        $OUT = $prefix."<STRONG><A class=\"you_are_here\" href=\"".URL."/modules.php?module=".$MOD_CHECK."&amp;".$type."=".$search.$LINK_ADD."\">".$ret."</A></STRONG>\n";
                        //* DEBUG: */ echo __LINE__."*".$type."/".$GLOBALS['what']."*<br />\n";
                        if (($type == "what") || (($type == "action") && (!isset($_GET['what'])) && ($GLOBALS['what'] != "welcome"))) {
                                //* DEBUG: */ echo __LINE__."+".$type."+<br />\n";
-                               $OUT .= "</DIV><BR>\n";
+                               $OUT .= "</DIV><br />\n";
                        }
                }
        }
 
        // Return or output HTML code?
-       if ($output)
-       {
+       if ($output) {
                // Output HTML code here
                OUTPUT_HTML($OUT);
-       }
-        else
-       {
+       } else {
                // Return HTML code
                return $OUT;
        }
 }
 //
-function ADD_MENU($MODE, $act, $wht)
-{
-       global $CONFIG;
+function ADD_MENU($MODE, $act, $wht) {
+       global $_CONFIG;
        if (!VALIDATE_MENU_ACTION($MODE, $act, $wht, true)) return CODE_MENU_NOT_VALID;
        $main_cnt = 0; $AND = ""; $main_action = ""; $sub_what = "";
        if (!IS_ADMIN())
@@ -366,66 +327,41 @@ function ADD_MENU($MODE, $act, $wht)
                                        //* DEBUG: */ echo __LINE__.":!!!!".$sub_what."!!!<br />\n";
                                        $test_inc = sprintf("%sinc/modules/%s/what-%s.php", PATH, $MODE, $sub_what);
                                        $test = (file_exists($test_inc) && is_readable($test_inc));
-                                       if ($test)
-                                       {
-                                               if ((!empty($wht)) && (($wht == $sub_what)))
-                                               {
+                                       if ($test) {
+                                               if ((!empty($wht)) && (($wht == $sub_what))) {
                                                        $content = "<STRONG>";
                                                }
 
                                                // Navigation link
-                                               $content .= "<A name=\"menu\" class=\"menu_blur\" href=\"".URL."/modules.php?module=".$GLOBALS['module']."&amp;what=".$sub_what.ADD_URL_DATA("")."\"";
-
-                                               if (frameset_active)
-                                               {
-                                                       // We need to add a JavaScript here to reload both frames!
-                                               }
-                                                else
-                                               {
-                                                       // Add the default target _self
-                                                       $content .= " target=\"_self\"";
-                                               }
-                                               $content .= ">";
-                                       }
-                                        else
-                                       {
+                                               $content .= "<A name=\"menu\" class=\"menu_blur\" href=\"".URL."/modules.php?module=".$GLOBALS['module']."&amp;what=".$sub_what.ADD_URL_DATA("")."\" target=\"_self\">";
+                                       } else {
                                                $content .= "<I>";
                                        }
 
                                        // Menu title
-                                       $content .= $CONFIG['middot'].$sub_title;
+                                       $content .= $_CONFIG['middot'].$sub_title;
 
-                                       if ($test)
-                                       {
+                                       if ($test) {
                                                $content .= "</A>";
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                $content .= "</I>";
                                        }
 
-                                       if ((!empty($wht)) && (($wht == $sub_what)))
-                                       {
+                                       if ((!empty($wht)) && (($wht == $sub_what))) {
                                                $content .= "</STRONG>";
                                        }
                                        $wht = $sub_what; $cnt++;
-                                       if ($cnt < $ctl)
-                                       {
+                                       if ($cnt < $ctl) {
                                                LOAD_TEMPLATE($MODE."_menu_row", false, $content);
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                LOAD_TEMPLATE($MODE."_menu_bottom", false, $content);
                                        }
                                }
-                       }
-                        else
-                       {
+                       } else {
                                // This is a menu block... ;-)
                                $BLOCK_MODE = true;
                                $INC_BLOCK = sprintf(PATH."inc/modules/%s/action-%s.php", $MODE, $main_action);
-                               if ((file_exists($INC_BLOCK)) && (is_readable($INC_BLOCK)))
-                               {
+                               if ((file_exists($INC_BLOCK)) && (is_readable($INC_BLOCK))) {
                                        // Load include file
                                        if ((!EXT_IS_ACTIVE($main_action)) || ($main_action == "online")) OUTPUT_HTML("<TR>
   <TD class=\"".$MODE."_menu_whats\">");
@@ -453,25 +389,25 @@ function ADD_MENU($MODE, $act, $wht)
 // This patched function will reduce many SELECT queries for the specified or current admin login
 function IS_ADMIN($admin="")
 {
-       global $_COOKIE, $ADMINS, $CONFIG;
+       global $cacheArray, $_CONFIG;
        $ret = false; $passCookie = ""; $valPass = "";
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."<BR>";
+       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."<br />";
 
        // If admin login is not given take current from cookies...
-       if ((empty($admin)) && (!empty($_COOKIE['admin_login'])) && (!empty($_COOKIE['admin_md5'])))
+       if ((empty($admin)) && (!empty($_SESSION['admin_login'])) && (!empty($_SESSION['admin_md5'])))
        {
-               $admin = SQL_ESCAPE($_COOKIE['admin_login']); $passCookie = $_COOKIE['admin_md5'];
+               $admin = SQL_ESCAPE($_SESSION['admin_login']); $passCookie = $_SESSION['admin_md5'];
        }
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."<BR>";
+       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."<br />";
 
        // Search in array for entry
-       if ((!empty($passCookie)) && (isset($ADMINS['password'][$admin])) && (!empty($admin)))
+       if ((!empty($passCookie)) && (isset($cacheArray['admins']['password'][$admin])) && (!empty($admin)))
        {
                // Count cache hits
-               $CONFIG['cache_hits']++;
+               $_CONFIG['cache_hits']++;
 
                // Login data is valid or not?
-               $valPass = generatePassString($ADMINS['password'][$admin]);
+               $valPass = generatePassString($cacheArray['admins']['password'][$admin]);
        }
         elseif (!empty($admin))
        {
@@ -602,7 +538,7 @@ function WHAT_IS_VALID($act, $wht, $type="guest")
 //
 function IS_LOGGED_IN()
 {
-       global $_COOKIE, $status, $LAST;
+       global $status, $LAST;
        if (!is_array($LAST)) $LAST = array();
        $ret = false;
 
@@ -610,7 +546,7 @@ function IS_LOGGED_IN()
        FIX_DELETED_COOKIES(array('userid', 'u_hash', 'lifetime'));
 
        // Are cookies set?
-       if ((!empty($GLOBALS['userid'])) && (!empty($_COOKIE['u_hash'])) && (!empty($_COOKIE['lifetime'])) && (defined('COOKIE_PATH')))
+       if ((!empty($GLOBALS['userid'])) && (!empty($_SESSION['u_hash'])) && (!empty($_SESSION['lifetime'])) && (defined('COOKIE_PATH')))
        {
                // Cookies are set with values, but are they valid?
                $result = SQL_QUERY_ESC("SELECT password, status, last_module, last_online FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
@@ -627,8 +563,8 @@ function IS_LOGGED_IN()
                        if ((!empty($mod)) && (empty($LAST['module']))) { $LAST['module'] = $mod; $LAST['online'] = $onl; }
 
                        // So did we now have valid data and an unlocked user?
-                       //* DEBUG: */ echo $valPass."<br>".$_COOKIE['u_hash']."<br>";
-                       if (($status == "CONFIRMED") && ($valPass == $_COOKIE['u_hash']))
+                       //* DEBUG: */ echo $valPass."<br>".$_SESSION['u_hash']."<br>";
+                       if (($status == "CONFIRMED") && ($valPass == $_SESSION['u_hash']))
                        {
                                // Account is confirmed and all cookie data is valid so he is definely logged in! :-)
                                $ret = true;
@@ -637,28 +573,24 @@ function IS_LOGGED_IN()
                        {
                                // Maybe got locked etc.
                                //* DEBUG: */ echo __LINE__."!!!<br>";
-                               @setcookie("userid", "", time() - 3600, COOKIE_PATH);
-                               @setcookie("u_hash", "", time() - 3600, COOKIE_PATH);
-                               @setcookie("lifetime", "0", time() - 3600, COOKIE_PATH);
+                               set_session("userid", "", time() - 3600, COOKIE_PATH);
+                               set_session("u_hash", "", time() - 3600, COOKIE_PATH);
+                               set_session("lifetime", "", time() - 3600, COOKIE_PATH);
 
                                // Remove array elements to prevent errors
                                unset($GLOBALS['userid']);
-                               unset($_COOKIE['u_hash']);
-                               unset($_COOKIE['lifetime']);
                        }
                }
                 else
                {
                        // Cookie data is invalid!
                        //* DEBUG: */ echo __LINE__."***<br>";
-                       @setcookie("userid", "", time() - 3600, COOKIE_PATH);
-                       @setcookie("u_hash", "", time() - 3600, COOKIE_PATH);
-                       @setcookie("lifetime", "0", time() - 3600, COOKIE_PATH);
+                       set_session("userid", "", time() - 3600, COOKIE_PATH);
+                       set_session("u_hash", "", time() - 3600, COOKIE_PATH);
+                       set_session("lifetime", "", time() - 3600, COOKIE_PATH);
 
                        // Remove array elements to prevent errors
                        unset($GLOBALS['userid']);
-                       unset($_COOKIE['u_hash']);
-                       unset($_COOKIE['lifetime']);
                }
 
                // Free memory
@@ -668,14 +600,12 @@ function IS_LOGGED_IN()
        {
                // Cookie data is invalid!
                //* DEBUG: */ echo __LINE__."///<br>";
-               @setcookie("userid", "", time() - 3600, COOKIE_PATH);
-               @setcookie("u_hash", "", time() - 3600, COOKIE_PATH);
-               @setcookie("lifetime", "0", time() - 3600, COOKIE_PATH);
+               set_session("userid", "", time() - 3600, COOKIE_PATH);
+               set_session("u_hash", "", time() - 3600, COOKIE_PATH);
+               set_session("lifetime", "", time() - 3600, COOKIE_PATH);
 
                // Remove array elements to prevent errors
                unset($GLOBALS['userid']);
-               unset($_COOKIE['u_hash']);
-               unset($_COOKIE['lifetime']);
        }
        return $ret;
 }
@@ -685,16 +615,16 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
        if (!is_array($LAST)) $LAST = array();
 
        // Are the required cookies set?
-       if ((!isset($GLOBALS['userid'])) || (!isset($_COOKIE['u_hash'])) || (!isset($_COOKIE['lifetime']))) {
+       if ((!isset($GLOBALS['userid'])) || (!isset($_SESSION['u_hash'])) || (!isset($_SESSION['lifetime']))) {
                // Nope, then return here to caller function
                return false;
        } else {
                // Secure user ID
-               $GLOBALS['userid'] = bigintval($_COOKIE['userid']);
+               $GLOBALS['userid'] = bigintval($_SESSION['userid']);
        }
 
        // Extract last online time (life) and how long is auto-login valid (time)
-       $newl = time() + bigintval($_COOKIE['lifetime']);
+       $newl = time() + bigintval($_SESSION['lifetime']);
 
        // Recheck if logged in
        if (!IS_LOGGED_IN()) return false;
@@ -709,7 +639,7 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
                // Maybe first login time?
                if (empty($mod)) $mod = "login";
 
-               if (@setcookie("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && @setcookie("u_hash", SQL_ESCAPE($_COOKIE['u_hash']), $newl, COOKIE_PATH) && @setcookie("lifetime", bigintval($_COOKIE['lifetime']), $newl, COOKIE_PATH)) {
+               if (set_session("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && set_session("u_hash", SQL_ESCAPE($_SESSION['u_hash']), $newl, COOKIE_PATH) && set_session("lifetime", bigintval($_SESSION['lifetime']), $newl, COOKIE_PATH)) {
                        // This will be displayed on welcome page! :-)
                        if (empty($LAST['module'])) {
                                $LAST['module'] = $mod; $LAST['online'] = $onl;
@@ -726,9 +656,9 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
         else
        {
                // Destroy session, we cannot update!
-               @setcookie("userid", "", time() - 3600, COOKIE_PATH);
-               @setcookie("u_hash", "", time() - 3600, COOKIE_PATH);
-               @setcookie("lifetime", "0", time() - 3600, COOKIE_PATH);
+               set_session("userid", "", time() - 3600, COOKIE_PATH);
+               set_session("u_hash", "", time() - 3600, COOKIE_PATH);
+               set_session("lifetime", "", time() - 3600, COOKIE_PATH);
        }
 }
 //
@@ -796,33 +726,42 @@ function GET_MOD_DESCR($MODE, $wht)
 //
 function SEND_MODE_MAILS($mod, $modes)
 {
-       global $_COOKIE, $_POST, $CONFIG, $DATA;
+       global $_CONFIG, $DATA;
+
        // Load hash
-       $result_main = SQL_QUERY("SELECT password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
+       $result_main = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
         array($GLOBALS['userid']), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result_main) == 1)
-       {
-               // Load hash and extract salt
-               list($hash) = SQL_FETCHROW($result_main);
-               $salt = substr($hash, 0, -40);
+       if (SQL_NUMROWS($result_main) == 1) {
+               // Load hash from database
+               list($hashDB) = SQL_FETCHROW($result_main);
+
+               // Extract salt from cookie
+               $salt = substr($_SESSION['u_hash'], 0, -40);
 
                // Now let's compare passwords
-               $hash = generateHash($_POST['pass1'], $salt);
-               if (($hash == $_COOKIE['u_hash']) || ($_POST['pass1'] == $_POST['pass2']))
-               {
+               $hash = generatePassString($hashDB);
+               if (($hash == $_SESSION['u_hash']) || ($_POST['pass1'] == $_POST['pass2'])) {
                        // Load user's data
                        $result = SQL_QUERY_ESC("SELECT sex, surname, family, street_nr, country, zip, city, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND password='%s' LIMIT 1",
-                        array($GLOBALS['userid'], $hash), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1)
-                       {
+                        array($GLOBALS['userid'], $hashDB), __FILE__, __LINE__);
+                       if (SQL_NUMROWS($result) == 1) {
+                               // Load the data
                                $DATA = SQL_FETCHROW($result);
+
+                               // Free result
                                SQL_FREERESULT($result);
+
+                               // Translate salutation
                                $DATA[0] = TRANSLATE_SEX($DATA[0]);
+
+                               // Clear/init the content variable
+                               $content = "";
+                               $DATA['info'] = "";
+
                                switch ($mod)
                                {
                                case "mydata":
-                                       foreach ($modes as $mode)
-                                       {
+                                       foreach ($modes as $mode) {
                                                switch ($mode)
                                                {
                                                case "normal": break; // Do not add any special lines
@@ -839,10 +778,9 @@ function SEND_MODE_MAILS($mod, $modes)
                                                        $content = MEMBER_UNKNOWN_MODE.": ".$mode."\n\n";
                                                        break;
                                                }
-                                       }
+                                       } // END - if
 
-                                       if (EXT_IS_ACTIVE("country"))
-                                       {
+                                       if (EXT_IS_ACTIVE("country")) {
                                                // Replace code with description
                                                $DATA[4] = COUNTRY_GENERATE_INFO($_POST['country_code']);
                                        }
@@ -850,14 +788,11 @@ function SEND_MODE_MAILS($mod, $modes)
                                        // Load template
                                        $msg = LOAD_EMAIL_TEMPLATE("member_mydata_notify", $content, $GLOBALS['userid']);
 
-                                       if ($CONFIG['admin_notify'] == 'Y')
-                                       {
+                                       if ($_CONFIG['admin_notify'] == 'Y') {
                                                // The admin needs to be notified about a profile change
                                                $msg_admin = "admin_mydata_notify";
                                                $sub_adm = ADMIN_CHANGED_DATA;
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                // No mail to admin
                                                $msg_admin = "";
                                                $sub_adm = "";
@@ -874,51 +809,42 @@ function SEND_MODE_MAILS($mod, $modes)
                                        $content = "<STRONG><SPAN class=\"member_failed\">".UNKNOWN_MODULE."</SPAN></STRONG>";
                                        break;
                                }
-                       }
-                        else
-                       {
+                       } else {
                                // Could not load profile data
                                $content = "<STRONG><SPAN class=\"member_failed\">".MEMBER_CANNOT_LOAD_PROFILE."</SPAN></STRONG>";
                        }
-               }
-                else
-               {
+               } else {
                        // Passwords mismatch
                        $content = "<STRONG><SPAN class=\"member_failed\">".MEMBER_PASSWORD_ERROR."</SPAN></STRONG>";
                }
-       }
-        else
-       {
+       } else {
                // Could not load profile
                $content = "<STRONG><SPAN class=\"member_failed\">".MEMBER_CANNOT_LOAD_PROFILE."</SPAN></STRONG>";
        }
-       if ((!empty($sub_mem)) && (!empty($msg)))
-       {
+
+       // Send email to user if required
+       if ((!empty($sub_mem)) && (!empty($msg))) {
                // Send member mail
                SEND_EMAIL($DATA[7], $sub_mem, $msg);
        }
-       if ((!empty($sub_adm)) && (!empty($msg_admin)))
-       {
-               // Send admin mail
-               if (GET_EXT_VERSION("admins") >= "0.4.1")
-               {
-                       SEND_ADMIN_EMAILS_PRO($sub_adm, $msg_admin, $content, $GLOBALS['userid']);
-               }
-                else
-               {
-                       SEND_ADMIN_EMAILS($sub_adm, LOAD_EMAIL_TEMPLATE($msg_admin, $content, $GLOBALS['userid']));
+
+       // Send only if no other error has occured
+       if (empty($content)) {
+               if ((!empty($sub_adm)) && (!empty($msg_admin))) {
+                       // Send admin mail
+                       if (GET_EXT_VERSION("admins") >= "0.4.1") {
+                               SEND_ADMIN_EMAILS_PRO($sub_adm, $msg_admin, $content, $GLOBALS['userid']);
+                       } else {
+                               SEND_ADMIN_EMAILS($sub_adm, LOAD_EMAIL_TEMPLATE($msg_admin, $content, $GLOBALS['userid']));
+                       }
+               } elseif ($_CONFIG['admin_notify'] == 'Y') {
+                       // Cannot send mails to admin!
+                       $content = CANNOT_SEND_ADMIN_MAILS;
+               } else {
+                       // No mail to admin
+                       $content = "<STRONG><SPAN class=\"member_done\">".MYDATA_MAIL_SENT."</SPAN></STRONG>";
                }
        }
-        elseif ($CONFIG['admin_notify'] == 'Y')
-       {
-               // Cannot send mails to admin!
-               $content = CANNOT_SEND_ADMIN_MAILS;
-       }
-        else
-       {
-               // No mail to admin
-               $content = "<STRONG><SPAN class=\"member_done\">".MYDATA_MAIL_SENT."</SPAN></STRONG>";
-       }
 
        // Load template
        LOAD_TEMPLATE("admin_settings_saved", false, $content);
@@ -1034,10 +960,11 @@ function GET_PAYMENT ($pid, $full=false)
        return $ret;
 }
 //
-function GET_PAY_POINTS($pid, $DATA="price")
+function GET_PAY_POINTS($pid, $lookFor="price")
 {
        $ret = "-1";
-       $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_payments WHERE id=%d LIMIT 1", array($DATA, $pid), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_payments WHERE id=%d LIMIT 1",
+               array($lookFor, $pid), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1)
        {
                // Payment type found... :-)
@@ -1059,15 +986,15 @@ function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=fal
                if ($stats_id > 0)
                {
                        // Only when we got a real stats ID continue searching for the entry
-                       $type = "NORMAL"; $ROW = "stats_id";
-                       if ($bonus) { $type = "BONUS"; $ROW = "bonus_id"; }
+                       $type = "NORMAL"; $rowName = "stats_id";
+                       if ($bonus) { $type = "BONUS"; $rowName = "bonus_id"; }
                        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE %s='%s' AND userid=%d AND link_type='%s' LIMIT 1",
-                        array($ROW, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
+                        array($rowName, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
                        if (SQL_NUMROWS($result) == 0)
                        {
                                // No, so we add one!
                                $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_links (%s, userid, link_type) VALUES ('%s', '%s', '%s')",
-                                array($ROW, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
+                                array($rowName, $stats_id, bigintval($uid), $type), __FILE__, __LINE__);
                                $ret = "done";
                        }
                         else
@@ -1084,27 +1011,25 @@ function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=fal
        return $ret;
 }
 //
-function GET_TOTAL_DATA($search, $TABLE, $DATA, $WHERE="userid", $ONLY_ROWS=false)
+function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid", $onlyRows=false)
 {
        $ret = "0";
-       if ($ONLY_ROWS)
-       {
+       if ($onlyRows) {
                // Count rows
                $result = SQL_QUERY_ESC("SELECT COUNT(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'",
-                array($DATA, $TABLE, $WHERE, $search), __FILE__, __LINE__);
-       }
-        else
-       {
+                array($lookFor, $tableName, $whereStatement, $search), __FILE__, __LINE__);
+       } else {
                // Add all rows
                $result = SQL_QUERY_ESC("SELECT SUM(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'",
-                array($DATA, $TABLE, $WHERE, $search), __FILE__, __LINE__);
+                array($lookFor, $tableName, $whereStatement, $search), __FILE__, __LINE__);
        }
+
        // Load row
        list($ret) = SQL_FETCHROW($result);
-       //* DEBUG: */ echo __LINE__."*".$DATA."/".$search."/".$TABLE."/".$ret."*<br />\n";
+       //* DEBUG: */ echo __LINE__."*".$DATA."/".$search."/".$tableName."/".$ret."*<br />\n";
        SQL_FREERESULT($result);
        if (empty($ret)) {
-               if (($DATA == "counter") || ($DATA == "id")) {
+               if (($lookFor == "counter") || ($lookFor == "id")) {
                        $ret = "0";
                } else {
                        $ret = "0.00000";
@@ -1126,7 +1051,7 @@ function GET_TOTAL_DATA($search, $TABLE, $DATA, $WHERE="userid", $ONLY_ROWS=fals
  */
 function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $locked=false, $add_mode="ref")
 {
-       global $DEPTH, $_GET, $CONFIG, $DATA, $link;
+       global $DEPTH, $_CONFIG, $DATA, $link;
 
        // When $uid = 0 add points to jackpot
        if ($uid == "0")
@@ -1167,12 +1092,12 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
                        $P = $points * $per / 100;
 
                        // Update points...
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%d AND ref_depth='%s' LIMIT 1",
+                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%d AND ref_depth=%d LIMIT 1",
                         array($data, $data, $P, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
                        if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 0)
                        {
                                // First ref in this level! :-)
-                               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, %s) VALUES ('%s', '%s', '%s')",
+                               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, %s) VALUES (%d, %d, %s)",
                                 array($data, bigintval($uid), bigintval($DEPTH), $P), __FILE__, __LINE__);
                        }
 
@@ -1205,7 +1130,7 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
 //
 function UPDATE_REF_COUNTER($uid)
 {
-       global $REF_LVL, $link, $CACHE;
+       global $REF_LVL, $link, $cacheInstance;
        // Make it sure referral level zero (member him-/herself) is at least selected
        if (empty($REF_LVL)) $REF_LVL = "0";
 
@@ -1238,13 +1163,13 @@ function UPDATE_REF_COUNTER($uid)
         elseif ((($ref == $uid) || ($ref == 0)) && (GET_EXT_VERSION("cache") >= "0.1.2"))
        {
                // Remove cache here
-               if ($CACHE->cache_file("refsystem", true)) $CACHE->cache_destroy();
+               if ($cacheInstance->cache_file("refsystem", true)) $cacheInstance->cache_destroy();
        }
 }
 //
 function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht)
 {
-       global $_COOKIE, $_SERVER, $link, $_GET, $CONFIG;
+       global $link, $_CONFIG;
        // Do not update online list when extension is deactivated
        if (!EXT_IS_ACTIVE("online", true)) return;
 
@@ -1265,10 +1190,10 @@ function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht)
                // Is administrator
                $ADMIN = 'Y';
        }
-       if (!empty($_COOKIE['refid']))
+       if (!empty($_SESSION['refid']))
        {
                // Check cookie
-               if ($_COOKIE['refid'] > 0) $rid = $GLOBALS['refid'];
+               if ($_SESSION['refid'] > 0) $rid = $GLOBALS['refid'];
        }
 
        // Now Read data
@@ -1308,9 +1233,8 @@ WHERE sid='%s' LIMIT 1",
        }
 
        // Purge old entries
-       $TIMEOUT = time() - $CONFIG['online_timeout'];
-       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_online WHERE timestamp <= %d",
-        array($TIMEOUT), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_online WHERE timestamp <= (UNIX_TIMESTAMP() - %d)",
+        array($_CONFIG['online_timeout']), __FILE__, __LINE__);
 }
 // OBSULETE: Sends out mail to all administrators
 function SEND_ADMIN_EMAILS($subj, $msg)
@@ -1326,12 +1250,12 @@ function SEND_ADMIN_EMAILS($subj, $msg)
 // Get ID number from administrator's login name
 function GET_ADMIN_ID($login)
 {
-       global $ADMINS;
+       global $cacheArray;
        $ret = "-1";
-       if (!empty($ADMINS['aid'][$login]))
+       if (!empty($cacheArray['admins']['aid'][$login]))
        {
                // Check cache
-               $ret = $ADMINS['aid'][$login];
+               $ret = $cacheArray['admins']['aid'][$login];
                if (empty($ret)) $ret = "-1";
        }
         else
@@ -1351,12 +1275,12 @@ function GET_ADMIN_ID($login)
 // Get password hash from administrator's login name
 function GET_ADMIN_HASH($login)
 {
-       global $ADMINS;
+       global $cacheArray;
        $ret = "-1";
-       if (!empty($ADMINS['password'][$login]))
+       if (!empty($cacheArray['admins']['password'][$login]))
        {
                // Check cache
-               $ret = $ADMINS['password'][$login];
+               $ret = $cacheArray['admins']['password'][$login];
                if (empty($ret)) $ret = "-1";
        }
         else
@@ -1375,12 +1299,12 @@ function GET_ADMIN_HASH($login)
 //
 function GET_ADMIN_LOGIN($aid)
 {
-       global $ADMINS;
+       global $cacheArray;
        $ret = "***";
-       if (!empty($ADMINS['login']['aid']))
+       if (!empty($cacheArray['admins']['login']['aid']))
        {
                // Check cache
-               if (!empty($ADMINS['login'][$aid]))     $ret = $ADMINS['login'][$aid];
+               if (!empty($cacheArray['admins']['login'][$aid]))       $ret = $cacheArray['admins']['login'][$aid];
                if (empty($ret)) $ret = "***";
        }
         else
@@ -1452,9 +1376,9 @@ function ADD_OPTION_LINES($table, $id, $name, $default="",$special="",$where="")
 }
 // Aiut
 function activateExchange() {
-       global $CONFIG;
+       global $_CONFIG;
        $result = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' AND max_mails > 0", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) >= $CONFIG['activate_xchange'])
+       if (SQL_NUMROWS($result) >= $_CONFIG['activate_xchange'])
        {
                // Free memory
                SQL_FREERESULT($result);
@@ -1463,7 +1387,7 @@ function activateExchange() {
                $SQLs = array(
                        "UPDATE "._MYSQL_PREFIX."_mod_reg SET locked='N', hidden='N', mem_only='Y' WHERE module='order' LIMIT 1",
                        "UPDATE "._MYSQL_PREFIX."_member_menu SET visible='Y', locked='N' WHERE what='order' OR what='unconfirmed' LIMIT 2",
-                       "UPDATE "._MYSQL_PREFIX."_config SET activate_xchange='0' WHERE config='0' LIMIT 1"
+                       "UPDATE "._MYSQL_PREFIX."_config SET activate_xchange='0' WHERE config=0 LIMIT 1"
                );
 
                // Run SQLs
@@ -1478,7 +1402,7 @@ function activateExchange() {
 //
 function DELETE_USER_ACCOUNT($uid, $reason)
 {
-       $POINTS = 0;
+       $points = 0;
        $result = SQL_QUERY_ESC("SELECT (SUM(p.points) - d.used_points) AS points
 FROM "._MYSQL_PREFIX."_user_points AS p
 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
@@ -1487,7 +1411,7 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) == 1)
        {
                // Save his points to add them to the jackpot
-               list($POINTS) = SQL_FETCHROW($result);
+               list($points) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
 
                // Delete points entries as well
@@ -1497,11 +1421,11 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
                if (GET_EXT_VERSION("mediadata") >= "0.0.4")
                {
                        // Update database
-                       MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $POINTS);
+                       MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
                }
 
                // Now, when we have all his points adds them do the jackpot!
-               ADD_JACKPOT($POINTS);
+               ADD_JACKPOT($points);
        }
 
        // Delete category selections as well...
@@ -1516,7 +1440,7 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
        }
 
        // Now a mail to the user and that's all...
-       $msg = LOAD_EMAIL_TEMPLATE("del-user", stripslashes($reason), $uid);
+       $msg = LOAD_EMAIL_TEMPLATE("del-user", $reason, $uid);
        SEND_EMAIL($uid, ADMIN_DEL_ACCOUNT, $msg);
 
        // Ok, delete the account!
@@ -1525,13 +1449,13 @@ WHERE p.userid=%d", array(bigintval($uid)), __FILE__, __LINE__);
 //
 function META_DESCRIPTION($mod, $wht)
 {
-       global $CONFIG, $DEPTH;
+       global $_CONFIG, $DEPTH;
        if (($mod != "admin") && ($mod != "login"))
        {
                // Exclude admin and member's area
-               $DESCR = MAIN_TITLE." ".trim($CONFIG['title_middle'])." ".ADD_DESCR("guest", "what-".$wht, true);
+               $DESCR = MAIN_TITLE." ".trim($_CONFIG['title_middle'])." ".ADD_DESCR("guest", "what-".$wht, true);
                unset($DEPTH);
-               OUTPUT_HTML("<META name=\"description\" content=\"".$DESCR."\">\n");
+               OUTPUT_HTML("<META name=\"description\" content=\"".$DESCR."\">");
        }
 }
 //
@@ -1564,7 +1488,7 @@ function SUB_JACKPOT($points)
        if (SQL_NUMROWS($result) == 0)
        {
                // Create line
-               $result = SQL_QUERY("INSERT INTO "._MYSQL_PREFIX."_jackpot (ok, points) VALUES ('ok', '0.00000')", __FILE__, __LINE__);
+               $result = SQL_QUERY("INSERT INTO "._MYSQL_PREFIX."_jackpot (ok, points) VALUES ('ok', 0.00000)", __FILE__, __LINE__);
        }
         else
        {
@@ -1576,42 +1500,45 @@ function SUB_JACKPOT($points)
                if ($jackpot >= $points)
                {
                        // Update points when there are enougth points in jackpot
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_jackpot SET points=points-%s WHERE ok='ok' LIMIT 1", array($points), __FILE__, __LINE__);
+                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_jackpot SET points=points-%s WHERE ok='ok' LIMIT 1",
+                               array($points), __FILE__, __LINE__);
                        $ret = $jackpot - $points;
                }
        }
 }
 //
-function IS_DEMO()
-{
-       global $_COOKIE;
-       return ((EXT_IS_ACTIVE("demo")) && ($_COOKIE['admin_login'] == "demo"));
+function IS_DEMO() {
+       return ((EXT_IS_ACTIVE("demo")) && ($_SESSION['admin_login'] == "demo"));
 }
 //
 function LOAD_CONFIG($no="0")
 {
-       global $CFG_CACHE, $CONFIG;
-       $CFG_DUMMY = false;
+       global $cacheArray;
+       $CFG_DUMMY = array();
+
        // Check for cache extension, cache-array and if the requested configuration is in cache
-       if ((is_array($CFG_CACHE)) && (isset($CFG_CACHE['config'][$no])))
-       {
+       if ((is_array($cacheArray)) && (isset($cacheArray['config'][$no])) && (is_array($cacheArray['config'][$no]))) {
                // Load config from cache
-               $CFG_DUMMY = array();
-               foreach ($CFG_CACHE as $element=>$cfgs)
-               {
-                       $CFG_DUMMY[$element] = $cfgs[$no];
+               //* DEBUG: */ echo gettype($cacheArray['config'][$no])."<br />\n";
+               foreach ($cacheArray['config'][$no] as $key=>$value) {
+                       $CFG_DUMMY[$key] = $value;
                }
 
                // Count cache hits
-               $CONFIG['cache_hits']++;
-       }
-        else
-       {
+               $CFG_DUMMY['cache_hits']++;
+       } else {
                // Load config from DB
-               $result_config = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_config WHERE config='%d' LIMIT 1",
-                array(bigintval($no)), __FILE__, __LINE__);
+               $result_config = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_config WHERE config=%d LIMIT 1",
+                       array(bigintval($no)), __FILE__, __LINE__);
+
+               // Get config from database
                $CFG_DUMMY = SQL_FETCHARRAY($result_config);
+
+               // Free result
                SQL_FREERESULT($result_config);
+
+               // Remember this config in the array
+               $cacheArray['config'][$no] = $CFG_DUMMY;
        }
 
        // Return config array
@@ -1644,23 +1571,23 @@ function GET_WHAT($MOD_CHECK)
 //
 function MODULE_HAS_MENU($mod)
 {
-       global $EXTENSIONS, $MODULES, $CONFIG;
+       global $cacheArray, $_CONFIG;
 
        // All is false by default
        $ret = false;
        if (GET_EXT_VERSION("cache") >= "0.1.2")
        {
-               if (isset($MODULES['has_menu'][$mod]))
+               if (isset($cacheArray['modules']['has_menu'][$mod]))
                {
                        // Check module cache and count hit
-                       if ($MODULES['has_menu'][$mod] == 'Y') $ret = true;
-                       $CONFIG['cache_hits']++;
+                       if ($cacheArray['modules']['has_menu'][$mod] == 'Y') $ret = true;
+                       $_CONFIG['cache_hits']++;
                }
-                elseif (isset($EXTENSIONS['ext_menu'][$mod]))
+                elseif (isset($cacheArray['extensions']['ext_menu'][$mod]))
                {
                        // Check cache and count hit
-                       if ($EXTENSIONS['ext_menu'][$mod] == 'Y') $ret = true;
-                       $CONFIG['cache_hits']++;
+                       if ($cacheArray['extensions']['ext_menu'][$mod] == 'Y') $ret = true;
+                       $_CONFIG['cache_hits']++;
                }
        }
        if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false))
@@ -1684,5 +1611,6 @@ function MODULE_HAS_MENU($mod)
        // Return status
        return $ret;
 }
+
 //
 ?>