]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/bonus_functions.php
More fixes for bonus ranking
[mailer.git] / inc / libs / bonus_functions.php
index 445857c6ae8c92ab7b7a8f78ff2df560af52232f..5b7358917ef5bec4e9a2ba12e4b24bdc0c207ee6 100644 (file)
@@ -47,11 +47,10 @@ function addTurboBonus ($mid, $userid, $type) {
        if (getConfig('bonus_active') != 'Y') return false;
 
        // Init variables
-       $sql = ''; $bonys = 0; $mail = 0; $column = '';
+       $sql = ''; $bonus = 0; $mail = 0; $column = '';
 
        // Select SQL command
-       switch ($type)
-       {
+       switch ($type) {
                case 'bonusid':
                        $column = 'bonus_id';
                        $bonus = $mid;
@@ -74,7 +73,7 @@ function addTurboBonus ($mid, $userid, $type) {
        } // END - if
 
        // Check for entry
-       $rank = countSumTotalData($userid, 'bonus_turbo', 'id', 'userid', true, sprintf(" AND `%s`=%s", $column, $mid)) + 1;
+       $rank = countSumTotalData($mid, 'bonus_turbo', 'id', $column, true) + 1;
 
        // Which rank?
        if ($rank == 1) {
@@ -112,10 +111,10 @@ function addTurboBonus ($mid, $userid, $type) {
 //
 function addBonusRanks ($data, $type, $userid) {
        // Init variables
-       $self = false; $OUT = ''; $content = array();
+       $self = false; $OUT = ''; $GLOBALS['ranking_content'] = array();
 
        // Clear rankings by default
-       setConfigEntry('__rankings', '');
+       $GLOBALS['ranking_content']['rankings'] = '';
 
        // How many ranks do we have?
        $ranks = count(explode(';', getConfig('turbo_rates'))) + 1;
@@ -125,18 +124,18 @@ function addBonusRanks ($data, $type, $userid) {
                array($type, $data, $userid), __FUNCTION__, __LINE__);
        if (SQL_NUMROWS($result) == 1) {
                // Load data
-               $content = merge_array($content, SQL_FETCHARRAY($result));
+               $GLOBALS['ranking_content'] = merge_array($GLOBALS['ranking_content'], SQL_FETCHARRAY($result));
 
                // Remember all values for later use
                $self  = true;
 
                // Transfer data to template
-               $content['yr_level']  = $content['level'];
-               $content['yr_points'] = translateComma($content['points']);
-               $content['yr_tmark']  = generateDateTime($content['timemark'], '1');
+               $GLOBALS['ranking_content']['yr_level']  = $GLOBALS['ranking_content']['level'];
+               $GLOBALS['ranking_content']['yr_points'] = translateComma($GLOBALS['ranking_content']['points']);
+               $GLOBALS['ranking_content']['yr_tmark']  = generateDateTime($GLOBALS['ranking_content']['timemark'], '1');
 
                // Load template
-               setConfigEntry('__rankings', loadTemplate('show_bonus_yr', true, $content));
+               $GLOBALS['ranking_content']['own'] = loadTemplate('show_bonus_yr', true, $GLOBALS['ranking_content']);
        } // END - if
 
        // Load rankings
@@ -147,35 +146,46 @@ function addBonusRanks ($data, $type, $userid) {
                $max = SQL_NUMROWS($result);
 
                // Init variables
-               $SW = 2; $content = array();
+               $SW = 2;
 
                // Output all ranks (levels)
                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",
+                       $result_users = SQL_QUERY_ESC("SELECT
+       `userid`, `points`
+FROM
+       `{?_MYSQL_PREFIX?}_bonus_turbo`
+WHERE
+       `%s`=%s AND
+       `level`=%s
+LIMIT 1",
                                array($type, $data, $rank), __FUNCTION__, __LINE__);
 
                        // Nothing found by default
-                       $content['userid'] = '---'; $content['points'] = '---';
+                       $rows['userid'] = '---';
+                       $rows['points'] = '---';
 
                        // Are you one of them?
                        if (SQL_NUMROWS($result_users) == 1) {
                                // Load data
-                               $content = merge_array($content, SQL_FETCHARRAY($result_users));
+                               $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
 
                                // Translate comma
-                               $content['points'] = translateComma($content['points']);
+                               $rows['points'] = translateComma($rows['points']);
                        } // END - if
 
+                       // Free result
+                       SQL_FREERESULT($result_users);
+
                        // Add more
-                       $content['rank'] = $rank;
-                       $content['sw']   = $SW;
+                       $rows['rank'] = $rank;
+                       $rows['sw']   = $SW;
 
                        // Output row
                        $OUT .= "<tr>
-  <td class=\"bonus_rank_".$content['level']." bottom2 switch_sw".$content['sw']."\">&nbsp;".$content['level'].".</td>
-  <td class=\"bonus_rank_".$content['level']." bottom2 switch_sw".$content['sw']."\" align=\"center\">".$content['userid']."</td>
-  <td class=\"bonus_rank_".$content['level']." bottom2 switch_sw".$content['sw']."\" align=\"center\">".$content['points']."</td>
+  <td class=\"bonus_rank_".$rows['rank']." bottom2 switch_sw".$rows['sw']."\">&nbsp;".$rows['rank'].".</td>
+  <td class=\"bonus_rank_".$rows['rank']." bottom2 switch_sw".$rows['sw']."\" align=\"center\">".$rows['userid']."</td>
+  <td class=\"bonus_rank_".$rows['rank']." bottom2 switch_sw".$rows['sw']."\" align=\"center\">".$rows['points']."</td>
 </tr>\n";
 
                        // Switch color
@@ -185,7 +195,7 @@ function addBonusRanks ($data, $type, $userid) {
                if ($self === false) {
                        // If current user was not found set constant
                        // @TODO Try to find a way for rewriting this constant
-                       setConfigEntry('__rankings', getMessage('BONUS_RANK_YOU_ARE_404'));
+                       $GLOBALS['ranking_content']['rankings'] = getMessage('BONUS_RANK_YOU_ARE_404');
                } // END - if
        } else {
                // No entries found!