]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/bonus_functions.php
More fixes, menus are no longer set visible if extension is deactivated, thanks to...
[mailer.git] / inc / libs / bonus_functions.php
index bbb2a32388383cdfd06a3fee591600179c76596b..86d7f83f9ac434ab007f6599f7ebf948ffb34660 100644 (file)
@@ -38,50 +38,63 @@ if (!defined('__SECURITY')) {
 }
 
 // This function must be run *BEFORE* a link is removed from table 'mxchange_user_links' !
-function BONUS_ADD_TURBO_POINTS($mid, $uid, $type)
-{
+function BONUS_ADD_TURBO_POINTS($mid, $uid, $type) {
        global $_CONFIG;
 
        // Shall we add bonus points?
-       if ($_CONFIG['bonus_active'] == "N") return;
+       if ($_CONFIG['bonus_active'] == "N") return false;
+
+       // Init variables
+       $SQL = ""; $bonys = 0; $mail = 0; $column = "";
 
        // Select SQL command
-       $SQL = "";
        switch ($type)
        {
        case "bonusid":
-               $result = SQL_QUERY_ESC("SELECT clicks FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
-                array($mid), __FILE__, __LINE__);
-               $bonus = $mid; $mail = 0;
+               $column = "bonus_id";
+               $bonus = $mid;
                break;
 
        case "mailid" :
-               $result = SQL_QUERY_ESC("SELECT clicks FROM "._MYSQL_PREFIX."_user_stats WHERE id=%s LIMIT 1",
-                array($mid), __FILE__, __LINE__);
-               $bonus = 0; $mail = $mid;
+               $column = "mail_id";
+               $mail = $mid;
+               break;
+
+       default:
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid type %s detected.", $type));
                break;
        }
 
+       // Is a column name set?
+       if (empty($column)) {
+               // No, then abort here
+               return false;
+       } // 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), __FILE__, __LINE__);
+
        // Load clicks from table as current rank
        list($rank) = SQL_FETCHROW($result);
 
-       if ($rank == 1)
-       {
+       // Add one line
+       $rank++;
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Which rank?
+       if ($rank == 1) {
                // First rank!
-               $rank = 1;
                $points = $_CONFIG['turbo_bonus'];
-       }
-        else
-       {
+       } else {
                // Anything else so let's explode all entered rank points
                $test = explode(";", $_CONFIG['turbo_rates']);
-               if (!empty($test[$rank - 2]))
-               {
+               if (!empty($test[$rank - 2])) {
                        // Level found
                        $points = $test[$rank - 2];
-               }
-                else
-               {
+               } else {
                        // Level not found!
                        $points = "0.00000";
                }
@@ -89,17 +102,16 @@ function BONUS_ADD_TURBO_POINTS($mid, $uid, $type)
 
        // Add points to his account directly
        $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET turbo_bonus=turbo_bonus+".$points." WHERE userid=%s LIMIT 1",
-        array(bigintval($uid)), __FILE__, __LINE__);
+               array(bigintval($uid)), __FILE__, __LINE__);
 
        // Rember this whole data for displaying ranking list
-       $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus_turbo (userid, mail_id, bonus_id, level, points, timemark) VALUES ('%s', '%s', '%s', '".$rank."', '".$points."', UNIX_TIMESTAMP())",
-        array(bigintval($uid), bigintval($mail), bigintval($bonus)), __FILE__, __LINE__);
+       $result = 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), __FILE__, __LINE__);
 
        if ((GET_EXT_VERSION("bonus") >= "0.3.5") && ($_CONFIG['bonus_mode'] != "ADD") && ($points > 0)) BONUS_POINTS_HANDLER($points);
 }
 //
-function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
-{
+function BONUS_MAKE_RANK_ROWS ($data, $type, $uid) {
        global $_CONFIG;
        $self = false; $OUT = "";
 
@@ -108,9 +120,8 @@ function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
 
        // 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), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
+               array($type, $data, $uid), __FILE__, __LINE__);
+       if (SQL_NUMROWS($result) == 1) {
                // Load data
                list($rank, $points, $mark) = SQL_FETCHROW($result);
 
@@ -124,35 +135,32 @@ function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
 
                // Load template
                define('__YOUR_RANKING_LINE', LOAD_TEMPLATE("show_bonus_yr", true));
-       }
+       } // END - if
 
        // Load rankings
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s ORDER BY level LIMIT %s",
-        array($type, $data, $_CONFIG['bonus_lines']), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+               array($type, $data, $_CONFIG['bonus_lines']), __FILE__, __LINE__);
+       if (SQL_NUMROWS($result) > 0) {
                // Start generating the ranking list
                $max = SQL_NUMROWS($result);
 
                $SW = 2;
-               for ($rank = 1; $rank <= $max; $rank++)
-               {
+               for ($rank = 1; $rank <= $max; $rank++) {
                        // Load data
-                       $result_users = SQL_QUERY_ESC("SELECT userid, points, timemark FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s AND level='%s' LIMIT 1",
-                        array($type, $data, $rank), __FILE__, __LINE__);
-                       list($userid, $points, $mark) = SQL_FETCHROW($result_users);
+                       $result_users = SQL_QUERY_ESC("SELECT userid, points, timemark FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s AND level=%s LIMIT 1",
+                               array($type, $data, $rank), __FILE__, __LINE__);
+
+                       // Nothing found by default
+                       $userid = "---"; $points = "---";
 
                        // Are you one of them?
-                       if (empty($userid))
-                       {
-                               // Nothing found
-                               $userid = "---"; $points = "---";
-                       }
-                        else
-                       {
+                       if (SQL_NUMROWS($result_users) == 1) {
+                               // Load data
+                               list($userid, $points, $mark) = SQL_FETCHROW($result_users);
+
                                // Translate comma
                                $points = TRANSLATE_COMMA($points);
-                       }
+                       } // END - if
 
                        // Output row
                        $OUT .= "<TR>
@@ -161,15 +169,13 @@ function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
   <TD class=\"bonus_rank_".$rank." bottom2 switch_sw".$SW."\" align=\"center\">".$points."</TD>
 </TR>\n";
                        $SW = 3 - $SW;
-               }
-               if (!$self)
-               {
+               } // END - for
+
+               if (!$self) {
                        // If current user was not found set constant
                        define('__YOUR_RANKING_LINE', BONUS_RANK_YOU_ARE_NOT_FOUND);
-               }
-       }
-        else
-       {
+               } // END - if
+       } else {
                // No entries found!
                $OUT = "<TR>
   <TD colspan=\"3\" align=\"center\" height=\"30\" class=\"bottom2\">