More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / libs / bonus_functions.php
index a13aec9642ac2bec0e371ffb9c92c3284c2e7c2f..55aba4995f949096c806a830686e695ac2d2e772 100644 (file)
@@ -75,17 +75,7 @@ function BONUS_ADD_TURBO_POINTS ($mid, $uid, $type) {
        } // END - if
 
        // Check for entry
-       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt FROM  `{!_MYSQL_PREFIX!}_bonus_turbo` WHERE userid=%s AND %s=%s LIMIT 1",
-       array($uid, $column, $mid), __FUNCTION__, __LINE__);
-
-       // Load clicks from table as current rank
-       list($rank) = SQL_FETCHROW($result);
-
-       // Add one line
-       $rank++;
-
-       // Free result
-       SQL_FREERESULT($result);
+       $rank = GET_TOTAL_DATA($uid, 'bonus_turbo', 'id', 'userid', true, sprintf(" AND `%s`=%s", $column, $mid)) + 1;
 
        // Which rank?
        if ($rank == 1) {
@@ -99,17 +89,23 @@ function BONUS_ADD_TURBO_POINTS ($mid, $uid, $type) {
                        $points = $test[$rank - 2];
                } else {
                        // Level not found!
-                       $points = "0.00000";
+                       $points = '0.00000';
                }
        }
 
        // Add points to his account directly
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET turbo_bonus=turbo_bonus+".$points." WHERE userid=%s LIMIT 1",
-       array(bigintval($uid)), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `turbo_bonus`=`turbo_bonus`+%s WHERE `userid`=%s LIMIT 1",
+               array(bigintval($uid), $points), __FUNCTION__, __LINE__);
 
        // Rember this whole data for displaying ranking list
-       SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus_turbo` (userid, mail_id, bonus_id, level, points, timemark) VALUES ('%s', '%s', '%s', '%s', '%s', UNIX_TIMESTAMP())",
-       array(bigintval($uid), bigintval($mail), bigintval($bonus), $rank, $points), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus_turbo` (`userid`, `mail_id`, `bonus_id`, `level`, `points`, `timemark`) VALUES (%s, %s, %s, %s, %s, UNIX_TIMESTAMP())",
+               array(
+                       bigintval($uid),
+                       bigintval($mail),
+                       bigintval($bonus),
+                       $rank,
+                       $points
+               ), __FUNCTION__, __LINE__);
 
        if ((GET_EXT_VERSION('bonus') >= '0.3.5') && (getConfig('bonus_mode') != "ADD") && ($points > 0)) BONUS_POINTS_HANDLER($points);
 }
@@ -121,8 +117,8 @@ function BONUS_MAKE_RANK_ROWS ($data, $type, $uid) {
        $ranks = count(explode(';', getConfig('turbo_rates'))) + 1;
 
        // Load current user's data
-       $result = SQL_QUERY_ESC("SELECT level, points, timemark FROM `{!_MYSQL_PREFIX!}_bonus_turbo` WHERE %s=%s AND `userid`=%s LIMIT 1",
-       array($type, $data, $uid), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `level`, `points`, `timemark` FROM `{!_MYSQL_PREFIX!}_bonus_turbo` WHERE `%s`=%s AND `userid`=%s LIMIT 1",
+               array($type, $data, $uid), __FUNCTION__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Load data
                list($rank, $points, $mark) = SQL_FETCHROW($result);