2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // This function must be run *BEFORE* a link is removed from table 'mailer_user_links' !
44 function addTurboBonus ($mid, $userid, $type) {
45 // Shall we add bonus points?
46 if (!isBonusRallyeActive()) {
51 $sql = ''; $bonus = '0'; $mail = '0'; $column = '';
66 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid type %s detected.", $type));
70 // Is a column name set?
72 // No, then abort here
77 $rank = countSumTotalData($mid, 'bonus_turbo', 'id', $column, true) + 1;
82 $points = getConfig('turbo_bonus');
84 // Anything else so let's explode all entered rank points
85 $test = explode(';', getTurboRates());
86 if (!empty($test[$rank - 2])) {
88 $points = $test[$rank - 2];
95 // Add points to his account directly
96 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `turbo_bonus`=`turbo_bonus`+%s WHERE `userid`=%s LIMIT 1",
100 ), __FUNCTION__, __LINE__);
102 // Rember this whole data for displaying ranking list
103 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())",
110 ), __FUNCTION__, __LINE__);
112 if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD') && ($points > 0)) {
113 handleBonusPoints($points, $userid);
118 function addBonusRanks ($data, $type, $userid) {
120 $self = false; $OUT = ''; $GLOBALS['ranking_content'] = array();
122 // Clear rankings by default
123 $GLOBALS['ranking_content']['rankings'] = '';
125 // How many ranks do we have?
126 $ranks = count(explode(';', getTurboRates())) + 1;
128 // Load current user's data
129 $result = SQL_QUERY_ESC("SELECT `level`,`points`,`timemark` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s AND `userid`=%s LIMIT 1",
134 ), __FUNCTION__, __LINE__);
137 if (SQL_NUMROWS($result) == 1) {
139 $GLOBALS['ranking_content'] = merge_array($GLOBALS['ranking_content'], SQL_FETCHARRAY($result));
141 // Remember all values for later use
144 // Transfer data to template
145 $GLOBALS['ranking_content']['timemark'] = generateDateTime($GLOBALS['ranking_content']['timemark'], 1);
148 $GLOBALS['ranking_content']['own'] = loadTemplate('show_bonus_yr', true, $GLOBALS['ranking_content']);
152 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s ORDER BY `level` ASC LIMIT {?bonus_lines?}",
153 array($type, $data), __FUNCTION__, __LINE__);
154 if (!SQL_HASZERONUMS($result)) {
155 // Output all ranks (levels)
156 for ($rank = 1; $rank <= SQL_NUMROWS($result); $rank++) {
158 $result_users = SQL_QUERY_ESC("SELECT
161 `{?_MYSQL_PREFIX?}_bonus_turbo`
166 array($type, $data, $rank), __FUNCTION__, __LINE__);
168 // Nothing found by default
169 $rows['userid'] = '---';
170 $rows['points'] = '---';
172 // Are you one of them?
173 if (SQL_NUMROWS($result_users) == 1) {
175 $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
179 SQL_FREERESULT($result_users);
182 $rows['rank'] = $rank;
185 $OUT .= loadTemplate('member_bonus_turbo_row', true, $rows);
188 if ($self === false) {
189 // If current user was not found set constant
190 $GLOBALS['ranking_content']['rankings'] = '{--MEMBER_BONUS_RANK_YOU_ARE_404--}';
194 // @TODO Move this HTML to a template
196 <td colspan="3" align="center" height="30" class="bottom">
197 <div class="bad">{%message,MEMBER_BONUS_NO_RANKS=' . $data . '%}</div>
206 // Hanle any bonus points the given user shall become
207 function handleBonusPoints ($mode, $userid) {
208 // Shall we add bonus points?
209 if (!isBonusRallyeActive()) {
213 // Default is not working
216 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
217 if ((getBonusMode() == 'UID') && ($userid == '0') && (isExtensionActive('jackpot'))) {
218 // Update database & config
219 updateConfiguration('bonus_mode', 'JACKPOT');
222 if ($mode == 'login_bonus') {
223 // Login bonus detected
224 $points = getConfig('login_bonus');
226 // Direct points supplied
230 // Check his amount first
231 $total = getTotalPoints($userid);
233 // Subtract points from...
234 switch (getBonusMode()) {
235 case 'ADD': // Only add them (no subtraction)
239 case 'JACKPOT': // ... jackpot
240 if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) === false) && (isValidUserId($userid))) {
241 if ($total >= $points) {
242 // Subtract points from userid's account
243 $return = subtractPointsFromJackpot('bonus_payout_jackpot', $userid, $points);
248 case 'UID': // ... userid's account
249 if ($total >= $points) {
250 // Subtract points from userid's account
251 $return = subtractPoints('bonus_payout_userid', $userid, $points);
252 } elseif (isExtensionActive('jackpot')) {
253 // Try to subtract from jackpot
254 $return = subtractPointsFromJackpot($points);
258 default: // This should not happen
259 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid bonus-mode ' . getBonusMode() . ' detected.');
267 // Purges expired fast-click bonus entries
268 function purgeExpiredTurboBonus() {
270 $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__);
272 if (!SQL_HASZEROAFFECTED()) {
273 // Send out email to admin
274 sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 // Determines wether the "bonus rallye" is active
283 function isBonusRallyeActive () {
285 if (!isset($GLOBALS['bonus_rallye_active'])) {
287 $GLOBALS['bonus_rallye_active'] = (getConfig('bonus_active') == 'Y');
291 return $GLOBALS['bonus_rallye_active'];
294 // Determines wether the "bonus new_member_notify" is active
295 function isBonusNewMemberNotifyEnabled () {
297 if (!isset($GLOBALS['bonus_new_member_notify_active'])) {
299 $GLOBALS['bonus_new_member_notify_active'] = (getConfig('bonus_new_member_notify') == 'Y');
303 return $GLOBALS['bonus_new_member_notify_active'];
306 // Getter for bonus_timeout
307 function getBonusTimeout () {
309 if (!isset($GLOBALS[__FUNCTION__])) {
311 $GLOBALS[__FUNCTION__] = getConfig('bonus_timeout');
315 return $GLOBALS[__FUNCTION__];
318 // Getter for bonus_mode
319 function getBonusMode () {
321 if (!isset($GLOBALS[__FUNCTION__])) {
323 $GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
327 return $GLOBALS[__FUNCTION__];
330 // Getter for bonus_ranks
331 function getBonusRanks () {
333 if (!isset($GLOBALS[__FUNCTION__])) {
335 $GLOBALS[__FUNCTION__] = getConfig('bonus_ranks');
339 return $GLOBALS[__FUNCTION__];
342 // Getter for turbo_rates
343 function getTurboRates () {
345 if (!isset($GLOBALS[__FUNCTION__])) {
347 $GLOBALS[__FUNCTION__] = getConfig('turbo_rates');
351 return $GLOBALS[__FUNCTION__];