- Daily/weekly/monthly reset completely rewritten
[mailer.git] / inc / mysql-manager.php
index f87c4c4c0df7957d258fb59ebd10e657605dc89c..a519c798b1ead0b181699020132891d3508c3d29 100644 (file)
@@ -400,8 +400,8 @@ function IS_ADMIN($admin="")
        // If admin login is not given take current from cookies...
        if ((empty($admin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
                // Get admin login and password from session/cookies
-               $admin = SQL_ESCAPE(get_session('admin_login'));
-               $passCookie = SQL_ESCAPE(get_session('admin_md5'));
+               $admin = get_session('admin_login');
+               $passCookie = get_session('admin_md5');
        }
        //* DEBUG: */ echo __LINE__."ADMIN:".$admin."/".$passCookie."<br />";
 
@@ -629,7 +629,7 @@ function UPDATE_LOGIN_DATA ($UPDATE=true) {
                // Maybe first login time?
                if (empty($mod)) $mod = "login";
 
-               if (set_session("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && set_session("u_hash", SQL_ESCAPE(get_session('u_hash')), $newl, COOKIE_PATH) && set_session("lifetime", bigintval(get_session('lifetime')), $newl, COOKIE_PATH)) {
+               if (set_session("userid", $GLOBALS['userid'], $newl, COOKIE_PATH) && set_session("u_hash", get_session('u_hash'), $newl, COOKIE_PATH) && set_session("lifetime", bigintval(get_session('lifetime')), $newl, COOKIE_PATH)) {
                        // This will be displayed on welcome page! :-)
                        if (empty($LAST['module'])) {
                                $LAST['module'] = $mod; $LAST['online'] = $onl;
@@ -1375,12 +1375,11 @@ function activateExchange() {
                );
 
                // Run SQLs
-               foreach ($SQLs as $sql)
-               {
+               foreach ($SQLs as $sql) {
                        $result = SQL_QUERY($sql, __FILE__, __LINE__);
                }
 
-               // Destroy cache
+               // @TODO Destroy cache
        }
 }
 //
@@ -1392,8 +1391,7 @@ FROM "._MYSQL_PREFIX."_user_points AS p
 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
 ON p.userid=d.userid
 WHERE p.userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+       if (SQL_NUMROWS($result) == 1) {
                // Save his points to add them to the jackpot
                list($points) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -1402,8 +1400,7 @@ WHERE p.userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
                $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_points WHERE userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
 
                // Update mediadata as well
-               if (GET_EXT_VERSION("mediadata") >= "0.0.4")
-               {
+               if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
                        // Update database
                        MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
                }
@@ -1417,8 +1414,7 @@ WHERE p.userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
         array(bigintval($uid)), __FILE__, __LINE__);
 
        // Remove from rallye if found
-       if (EXT_IS_ACTIVE("rallye"))
-       {
+       if (EXT_IS_ACTIVE("rallye")) {
                $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_users WHERE userid=%s",
                 array(bigintval($uid)), __FILE__, __LINE__);
        }
@@ -1559,8 +1555,7 @@ function MODULE_HAS_MENU($mod)
 
        // All is false by default
        $ret = false;
-       if (GET_EXT_VERSION("cache") >= "0.1.2")
-       {
+       if (GET_EXT_VERSION("cache") >= "0.1.2") {
                if (isset($cacheArray['modules']['has_menu'][$mod]))
                {
                        // Check module cache and count hit
@@ -1574,22 +1569,21 @@ function MODULE_HAS_MENU($mod)
                        $_CONFIG['cache_hits']++;
                }
        }
-       if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false))
-       {
+
+       if ((GET_EXT_VERSION("sql_patches") >= "0.3.6") && ($ret === false)) {
                // Check database for entry
                $result = SQL_QUERY_ESC("SELECT has_menu FROM "._MYSQL_PREFIX."_mod_reg WHERE module='%s' LIMIT 1",
                 array($mod), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+               if (SQL_NUMROWS($result) == 1) {
                        list($has_menu) = SQL_FETCHROW($result);
-                       if ($has_menu == "Y") $ret = true;
+                       $ret = ($has_menu == "Y");
                }
 
                // Free memory
                SQL_FREERESULT($result);
        } elseif (GET_EXT_VERSION("sql_patches") == "") {
                // No sql_patches installed, so maybe in admin area?
-               if ((IS_ADMIN()) && ($mod == "admin")) return true; // Then there is a menu!
+               $ret = ((IS_ADMIN()) && ($mod == "admin")); // Then there is a menu!
        }
 
        // Return status
@@ -1607,6 +1601,48 @@ function SUB_POINTS ($uid, $points) {
                MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
        } // END - if
 }
+// Update config entries
+function UPDATE_CONFIG ($entries, $values, $updateMode="") {
+       // Do we have multiple entries?
+       if (is_array($entries)) {
+               // Walk through all
+               $all = "";
+               foreach ($entries as $idx => $entry) {
+                       // Update mode set?
+                       if (!empty($updateMode)) {
+                               // Update entry
+                               $all .= sprintf("%s=%s%s%s,", $entry, $entry, $updateMode, (float)$values[$idx]);
+                       } else {
+                               // Check if string or number
+                               if (($values[$idx] + 0) === $values[$idx]) {
+                                       // Number detected
+                                       $all .= sprintf("%s=%s,", $entry, (float)$values[$idx]);
+                               } else {
+                                       // String detected
+                                       $all .= sprintf("%s='%s',", $entry, SQL_ESCAPE($values[$idx]));
+                               }
+                       }
+               } // END - foreach
 
+               // Remove last comma
+               $entries = substr($all, 0, -1);
+       } elseif (!empty($updateMode)) {
+               // Update mode set
+               $entries .= sprintf("=%s%s%s", $entries, $updateMode, (float)$value);
+       } else {
+               // Regular entry to update
+               $entries .= sprintf("='%s'", SQL_ESCAPE($values));
+       }
+
+       // Run database update
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__.":entries={$entries}");
+       SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET ".$entries." WHERE config=0 LIMIT 1", __FILE__, __LINE__);
+
+       // Destroy cache
+       if ((GET_EXT_VERSION("cache") >= "0.1.2") && (SQL_AFFECTEDROWS() == 1)) {
+               global $cacheInstance;
+               if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();
+       } // END - if
+}
 //
 ?>