]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/bonus_functions.php
Fixes for login bonus, some minor rewrites
[mailer.git] / inc / libs / bonus_functions.php
index 366606a243d6649687743275e4596cd338c202ee..bbb2a32388383cdfd06a3fee591600179c76596b 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
+
 // This function must be run *BEFORE* a link is removed from table 'mxchange_user_links' !
 function BONUS_ADD_TURBO_POINTS($mid, $uid, $type)
 {
@@ -74,7 +74,7 @@ function BONUS_ADD_TURBO_POINTS($mid, $uid, $type)
         else
        {
                // Anything else so let's explode all entered rank points
-               $test = explode(";", $_CONFIG['bonus_rates']);
+               $test = explode(";", $_CONFIG['turbo_rates']);
                if (!empty($test[$rank - 2]))
                {
                        // Level found
@@ -104,7 +104,7 @@ function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
        $self = false; $OUT = "";
 
        // How many ranks do we have?
-       $ranks = sizeof(explode(";", $_CONFIG['bonus_rates'])) + 1;
+       $ranks = sizeof(explode(";", $_CONFIG['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",
@@ -181,23 +181,25 @@ function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
        return $OUT;
 }
 //
-function BONUS_POINTS_HANDLER($MODE)
-{
+function BONUS_POINTS_HANDLER($MODE) {
        global $_CONFIG;
 
        // Shall we add bonus points?
        if ($_CONFIG['bonus_active'] == "N") return;
 
        // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
-       if (($_CONFIG['bonus_mode'] == "UID") && ($_CONFIG['bonus_uid'] == "0")) $_CONFIG['bonus_mode'] = "JACKPOT";
+       if (($_CONFIG['bonus_mode'] == "UID") && ($_CONFIG['bonus_uid'] == "0")) {
+               // Update database
+               UPDATE_CONFIG(array('bonus_mode'), array("JACKPOT"));
 
-       if ($MODE == "login_bonus")
-       {
+               // Update configuration
+               $_CONFIG['bonus_mode'] = "JACKPOT";
+       } // END - if
+
+       if ($MODE == "login_bonus") {
                // Login bonus detected
                $points = $_CONFIG['login_bonus'];
-       }
-        else
-       {
+       } else {
                // Direct points supplied
                $points = $MODE;
        }
@@ -206,28 +208,23 @@ function BONUS_POINTS_HANDLER($MODE)
        switch ($_CONFIG['bonus_mode'])
        {
        case "JACKPOT": // ... jackpot
-               if ((SUB_JACKPOT($points) == -1) && ($_CONFIG['bonus_uid'] > 0))
-               {
+               if ((SUB_JACKPOT($points) == -1) && ($_CONFIG['bonus_uid'] > 0)) {
                        // Check points amount first...
                        $TOTAL = GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_points", "points") - GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_data", "used_points");
-                       if ($TOTAL >= $points)
-                       {
+                       if ($TOTAL >= $points) {
                                // Subtract points from userid's account
-                               SUB_POINTS($_CONFIG['bonus_uid'], $points);
-                       }
-               }
+                               SUB_POINTS("bonus_payout_jackpot", $_CONFIG['bonus_uid'], $points);
+                       } // END - if
+               } // END - if
                break;
 
        case "UID": // ... userid's account
                // Check his amount first
                $TOTAL = GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_points", "points") - GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_data", "used_points");
-               if ($TOTAL >= $points)
-               {
+               if ($TOTAL >= $points) {
                        // Subtract points from userid's account
-                       SUB_POINTS($_CONFIG['bonus_uid'], $points);
-               }
-                else
-               {
+                       SUB_POINTS("bonus_payout_uid", $_CONFIG['bonus_uid'], $points);
+               } else {
                        // Try to subtract from jackpot
                        $dummy = SUB_JACKPOT($points);
                }
@@ -239,7 +236,7 @@ function BONUS_PURGE_EXPIRED_TURBO_BONUS()
 {
        global $_CONFIG;
        // Remove entries
-       $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus_turbo WHERE timemark < ".(time() - $_CONFIG['bonus_timeout']), __FILE__, __LINE__);
+       $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus_turbo WHERE timemark < (UNIX_TIMESTAMP() - ".$_CONFIG['bonus_timeout'].")", __FILE__, __LINE__);
        if (SQL_AFFECTEDROWS() > 0) {
                // Send out email to admin
                SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_TURBO_SUBJECT, "admin_autopurge_turbo", $DELETED, "");