2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/10/2004 *
4 * =============== Last change: 03/18/2005 *
6 * -------------------------------------------------------------------- *
7 * File : bonus_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for bonus extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktion fuer bonus-Erweiterung *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // This function must be run *BEFORE* a link is removed from table 'mxchange_user_links' !
41 function BONUS_ADD_TURBO_POINTS($mid, $uid, $type)
45 // Shall we add bonus points?
46 if ($_CONFIG['bonus_active'] == "N") return;
53 $result = SQL_QUERY_ESC("SELECT clicks FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
54 array($mid), __FILE__, __LINE__);
55 $bonus = $mid; $mail = 0;
59 $result = SQL_QUERY_ESC("SELECT clicks FROM "._MYSQL_PREFIX."_user_stats WHERE id=%s LIMIT 1",
60 array($mid), __FILE__, __LINE__);
61 $bonus = 0; $mail = $mid;
65 // Load clicks from table as current rank
66 list($rank) = SQL_FETCHROW($result);
72 $points = $_CONFIG['turbo_bonus'];
76 // Anything else so let's explode all entered rank points
77 $test = explode(";", $_CONFIG['turbo_rates']);
78 if (!empty($test[$rank - 2]))
81 $points = $test[$rank - 2];
90 // Add points to his account directly
91 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET turbo_bonus=turbo_bonus+".$points." WHERE userid=%s LIMIT 1",
92 array(bigintval($uid)), __FILE__, __LINE__);
94 // Rember this whole data for displaying ranking list
95 $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())",
96 array(bigintval($uid), bigintval($mail), bigintval($bonus)), __FILE__, __LINE__);
98 if ((GET_EXT_VERSION("bonus") >= "0.3.5") && ($_CONFIG['bonus_mode'] != "ADD") && ($points > 0)) BONUS_POINTS_HANDLER($points);
101 function BONUS_MAKE_RANK_ROWS($data, $type, $uid)
104 $self = false; $OUT = "";
106 // How many ranks do we have?
107 $ranks = sizeof(explode(";", $_CONFIG['turbo_rates'])) + 1;
109 // Load current user's data
110 $result = SQL_QUERY_ESC("SELECT level, points, timemark FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s AND userid=%s LIMIT 1",
111 array($type, $data, $uid), __FILE__, __LINE__);
112 if (SQL_NUMROWS($result) == 1)
115 list($rank, $points, $mark) = SQL_FETCHROW($result);
117 // Remember all values for later use
118 $self = true; $points = TRANSLATE_COMMA($points);
120 // Transfer data to template
121 define('__YR_LEVEL' , $rank);
122 define('__YR_POINTS', $points);
123 define('__YR_TMARK' , MAKE_DATETIME($mark, "1"));
126 define('__YOUR_RANKING_LINE', LOAD_TEMPLATE("show_bonus_yr", true));
130 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s ORDER BY level LIMIT %s",
131 array($type, $data, $_CONFIG['bonus_lines']), __FILE__, __LINE__);
132 if (SQL_NUMROWS($result) > 0)
134 // Start generating the ranking list
135 $max = SQL_NUMROWS($result);
138 for ($rank = 1; $rank <= $max; $rank++)
141 $result_users = SQL_QUERY_ESC("SELECT userid, points, timemark FROM "._MYSQL_PREFIX."_bonus_turbo WHERE %s=%s AND level='%s' LIMIT 1",
142 array($type, $data, $rank), __FILE__, __LINE__);
143 list($userid, $points, $mark) = SQL_FETCHROW($result_users);
145 // Are you one of them?
149 $userid = "---"; $points = "---";
154 $points = TRANSLATE_COMMA($points);
159 <TD class=\"bonus_rank_".$rank." bottom2 switch_sw".$SW."\"> ".$rank.".</TD>
160 <TD class=\"bonus_rank_".$rank." bottom2 switch_sw".$SW."\" align=\"center\">".$userid."</TD>
161 <TD class=\"bonus_rank_".$rank." bottom2 switch_sw".$SW."\" align=\"center\">".$points."</TD>
167 // If current user was not found set constant
168 define('__YOUR_RANKING_LINE', BONUS_RANK_YOU_ARE_NOT_FOUND);
175 <TD colspan=\"3\" align=\"center\" height=\"30\" class=\"bottom2\">
176 <STRONG class=\"guest_failed\">".BONUS_NO_RANKS_1.$data.BONUS_NO_RANKS_2."</STRONG>
179 define('__YOUR_RANKING_LINE', "");
184 function BONUS_POINTS_HANDLER($MODE) {
187 // Shall we add bonus points?
188 if ($_CONFIG['bonus_active'] == "N") return;
190 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
191 if (($_CONFIG['bonus_mode'] == "UID") && ($_CONFIG['bonus_uid'] == "0")) {
193 UPDATE_CONFIG(array('bonus_mode'), array("JACKPOT"));
195 // Update configuration
196 $_CONFIG['bonus_mode'] = "JACKPOT";
199 if ($MODE == "login_bonus") {
200 // Login bonus detected
201 $points = $_CONFIG['login_bonus'];
203 // Direct points supplied
207 // Subtract points from...
208 switch ($_CONFIG['bonus_mode'])
210 case "JACKPOT": // ... jackpot
211 if ((SUB_JACKPOT($points) == -1) && ($_CONFIG['bonus_uid'] > 0)) {
212 // Check points amount first...
213 $TOTAL = GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_points", "points") - GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_data", "used_points");
214 if ($TOTAL >= $points) {
215 // Subtract points from userid's account
216 SUB_POINTS("bonus_payout_jackpot", $_CONFIG['bonus_uid'], $points);
221 case "UID": // ... userid's account
222 // Check his amount first
223 $TOTAL = GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_points", "points") - GET_TOTAL_DATA($_CONFIG['bonus_uid'], "user_data", "used_points");
224 if ($TOTAL >= $points) {
225 // Subtract points from userid's account
226 SUB_POINTS("bonus_payout_uid", $_CONFIG['bonus_uid'], $points);
228 // Try to subtract from jackpot
229 $dummy = SUB_JACKPOT($points);
235 function BONUS_PURGE_EXPIRED_TURBO_BONUS()
239 $result = SQL_QUERY("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus_turbo WHERE timemark < (UNIX_TIMESTAMP() - ".$_CONFIG['bonus_timeout'].")", __FILE__, __LINE__);
240 if (SQL_AFFECTEDROWS() > 0) {
241 // Send out email to admin
242 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_TURBO_SUBJECT, "admin_autopurge_turbo", $DELETED, "");