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, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.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 'mxchange_user_links' !
44 function addTurboBonus ($mid, $userid, $type) {
45 // Shall we add bonus points?
46 if (!isBonusRallyeActive()) return false;
49 $sql = ''; $bonus = '0'; $mail = '0'; $column = '';
64 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid type %s detected.", $type));
68 // Is a column name set?
70 // No, then abort here
75 $rank = countSumTotalData($mid, 'bonus_turbo', 'id', $column, true) + 1;
80 $points = getConfig('turbo_bonus');
82 // Anything else so let's explode all entered rank points
83 $test = explode(';', getConfig('turbo_rates'));
84 if (!empty($test[$rank - 2])) {
86 $points = $test[$rank - 2];
93 // Add points to his account directly
94 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `turbo_bonus`=`turbo_bonus`+%s WHERE `userid`=%s LIMIT 1",
98 ), __FUNCTION__, __LINE__);
100 // Rember this whole data for displaying ranking list
101 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())",
108 ), __FUNCTION__, __LINE__);
110 if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD') && ($points > 0)) {
111 handleBonusPoints($points);
116 function addBonusRanks ($data, $type, $userid) {
118 $self = false; $OUT = ''; $GLOBALS['ranking_content'] = array();
120 // Clear rankings by default
121 $GLOBALS['ranking_content']['rankings'] = '';
123 // How many ranks do we have?
124 $ranks = count(explode(';', getConfig('turbo_rates'))) + 1;
126 // Load current user's data
127 $result = SQL_QUERY_ESC("SELECT `level`, `points`, `timemark` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s AND `userid`=%s LIMIT 1",
132 ), __FUNCTION__, __LINE__);
135 if (SQL_NUMROWS($result) == 1) {
137 $GLOBALS['ranking_content'] = merge_array($GLOBALS['ranking_content'], SQL_FETCHARRAY($result));
139 // Remember all values for later use
142 // Transfer data to template
143 $GLOBALS['ranking_content']['timemark'] = generateDateTime($GLOBALS['ranking_content']['timemark'], 1);
146 $GLOBALS['ranking_content']['own'] = loadTemplate('show_bonus_yr', true, $GLOBALS['ranking_content']);
150 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s ORDER BY `level` ASC LIMIT {?bonus_lines?}",
151 array($type, $data), __FUNCTION__, __LINE__);
152 if (!SQL_HASZERONUMS($result)) {
153 // Output all ranks (levels)
154 for ($rank = 1; $rank <= SQL_NUMROWS($result); $rank++) {
156 $result_users = SQL_QUERY_ESC("SELECT
159 `{?_MYSQL_PREFIX?}_bonus_turbo`
164 array($type, $data, $rank), __FUNCTION__, __LINE__);
166 // Nothing found by default
167 $rows['userid'] = '---';
168 $rows['points'] = '---';
170 // Are you one of them?
171 if (SQL_NUMROWS($result_users) == 1) {
173 $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
175 // Is ext-nickname active?
176 if (isExtensionActive('nickname')) {
177 // Then get the nickname
178 $nick = getNickname($rows['userid']);
180 // Is it not empty? Then use it
181 if (!empty($nick)) $rows['userid'] = $nick;
186 SQL_FREERESULT($result_users);
189 $rows['rank'] = $rank;
192 $OUT .= loadTemplate('member_bonus_turbo_row', true, $rows);
195 if ($self === false) {
196 // If current user was not found set constant
197 $GLOBALS['ranking_content']['rankings'] = '{--MEMBER_BONUS_RANK_YOU_ARE_404--}';
201 // @TODO Move this HTML to a template
203 <td colspan="3" align="center" height="30" class="bottom">
204 <div class="notice">' . getMaskedMessage('MEMBER_BONUS_NO_RANKS', $data) . '</div>
214 function handleBonusPoints ($mode) {
215 // Shall we add bonus points?
216 if (!isBonusRallyeActive()) return;
218 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
219 if ((getBonusMode() == 'UID') && (getBonusUserId() == '0') && (isExtensionActive('jackpot'))) {
220 // Update database & config
221 updateConfiguration('bonus_mode', 'JACKPOT');
224 if ($mode == 'login_bonus') {
225 // Login bonus detected
226 $points = getConfig('login_bonus');
228 // Direct points supplied
232 // Check his amount first
233 $total = getTotalPoints(getBonusUserId());
235 // Subtract points from...
236 switch (getBonusMode()) {
237 case 'ADD': // Only add them (no subtraction)
241 case 'JACKPOT': // ... jackpot
242 if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) == -1) && (isValidUserId(getBonusUserId()))) {
243 if ($total >= $points) {
244 // Subtract points from userid's account
245 subtractPointsFromJackpot('bonus_payout_jackpot', getBonusUserId(), $points);
250 case 'UID': // ... userid's account
251 if ($total >= $points) {
252 // Subtract points from userid's account
253 subtractPoints('bonus_payout_userid', getBonusUserId(), $points);
254 } elseif (isExtensionActive('jackpot')) {
255 // Try to subtract from jackpot
256 $dummy = subtractPointsFromJackpot($points);
260 default: // This should not happen
261 debug_report_bug(__FUNCTION__, __LINE__, 'Invalid bonus-mode ' . getBonusMode() . ' detected.');
266 // Purges expired fast-click bonus entries
267 function purgeExpiredTurboBonus() {
269 $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `timemark` < (UNIX_TIMESTAMP() - {?bonus_timeout?})', __FUNCTION__, __LINE__);
271 if (!SQL_HASZEROAFFECTED()) {
272 // Send out email to admin
273 sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
277 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
281 // Filter for adding login bonus to the user's account
282 function FILTER_ADD_LOGIN_BONUS () {
283 // Is the user data valid?
285 // Do only run for logged in members
286 debug_report_bug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
289 // Bonus is not given by default ;-)
291 if ((isExtensionInstalledAndNewer('sql_patches', '0.2.8')) && (isBonusRallyeActive()) && (getConfig('bonus_login_yn') == 'Y')) {
292 // Update last login if far enougth away
293 // @TODO This query isn't right, it will only update if the user was for a longer time away!
294 SQL_QUERY_ESC('UPDATE
295 `{?_MYSQL_PREFIX?}_user_data`
297 `last_login`=UNIX_TIMESTAMP()
300 `last_login` < (UNIX_TIMESTAMP() - {?login_timeout?})
304 ), __FUNCTION__, __LINE__
308 $bonus = (!SQL_HASZEROAFFECTED());
311 if (($bonus === true) && (getRequestParameter('mode') == 'bonus')) {
312 // Output message with added points
313 $GLOBALS['message'] .= '<div class="tiny">{--MEMBER_BONUS_LOGIN_BONUS_ADDED--}</div>';
314 } elseif (isExtensionActive('bonus')) {
315 // No login bonus added!
316 $GLOBALS['message'] .= '<div class="notice">{--MEMBER_BONUS_LOGIN_BONUS_NOT_ADDED--}</div>';
320 //-----------------------------------------------------------------------------
322 //-----------------------------------------------------------------------------
324 // Determines wether the "bonus rallye" is active
325 function isBonusRallyeActive () {
327 if (!isset($GLOBALS['bonus_rallye_active'])) {
329 $GLOBALS['bonus_rallye_active'] = (getConfig('bonus_active') == 'Y');
333 return $GLOBALS['bonus_rallye_active'];
336 // Determines wether the "bonus new_member_notify" is active
337 function isBonusNewMemberNotifyEnabled () {
339 if (!isset($GLOBALS['bonus_new_member_notify_active'])) {
341 $GLOBALS['bonus_new_member_notify_active'] = (getConfig('bonus_new_member_notify') == 'Y');
345 return $GLOBALS['bonus_new_member_notify_active'];
348 // Getter for bonus_timeout
349 function getBonusTimeout () {
351 if (!isset($GLOBALS[__FUNCTION__])) {
353 $GLOBALS[__FUNCTION__] = getConfig('bonus_timeout');
357 return $GLOBALS[__FUNCTION__];
360 // Getter for bonus_mode
361 function getBonusMode () {
363 if (!isset($GLOBALS[__FUNCTION__])) {
365 $GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
369 return $GLOBALS[__FUNCTION__];
372 // Getter for bonus_ranks
373 function getBonusRanks () {
375 if (!isset($GLOBALS[__FUNCTION__])) {
377 $GLOBALS[__FUNCTION__] = getConfig('bonus_ranks');
381 return $GLOBALS[__FUNCTION__];