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