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 - 2012 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
162 `{?_MYSQL_PREFIX?}_bonus_turbo`
167 array($type, $data, $rank), __FUNCTION__, __LINE__);
169 // Nothing found by default
170 $rows['userid'] = '---';
171 $rows['points'] = '---';
173 // Are you one of them?
174 if (SQL_NUMROWS($result_users) == 1) {
176 $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
180 SQL_FREERESULT($result_users);
183 $rows['rank'] = $rank;
186 $OUT .= loadTemplate('member_bonus_turbo_row', true, $rows);
189 if ($self === false) {
190 // If current user was not found set constant
191 $GLOBALS['ranking_content']['rankings'] = '{--MEMBER_BONUS_RANK_YOU_ARE_404--}';
195 // @TODO Move this HTML to a template
197 <td colspan="3" align="center" height="30" class="bottom">
198 <div class="bad">{%message,MEMBER_BONUS_NO_RANKS=' . $data . '%}</div>
207 // Hanle any bonus points the given user shall become
208 function handleBonusPoints ($mode, $userid) {
209 // Shall we add bonus points?
210 if (!isBonusRallyeActive()) {
214 // Default is not working
217 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
218 if ((getBonusMode() == 'UID') && ($userid == '0') && (isExtensionActive('jackpot'))) {
219 // Update database & config
220 updateConfiguration('bonus_mode', 'JACKPOT');
223 if ($mode == 'login_bonus') {
224 // Login bonus detected
225 $points = getConfig('login_bonus');
227 // Direct points supplied
231 // Check his amount first
232 $total = getTotalPoints($userid);
234 // Subtract points from...
235 switch (getBonusMode()) {
236 case 'ADD': // Only add them (no subtraction)
240 case 'JACKPOT': // ... jackpot
241 if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) === false) && (isValidUserId($userid))) {
242 if ($total >= $points) {
243 // Subtract points from userid's account
244 $return = subtractPointsFromJackpot('bonus_payout_jackpot', $userid, $points);
249 case 'UID': // ... userid's account
250 if ($total >= $points) {
251 // Subtract points from userid's account
252 $return = subtractPoints('bonus_payout_userid', $userid, $points);
253 } elseif (isExtensionActive('jackpot')) {
254 // Try to subtract from jackpot
255 $return = subtractPointsFromJackpot($points);
259 default: // This should not happen
260 reportBug(__FUNCTION__, __LINE__, 'Invalid bonus-mode ' . getBonusMode() . ' detected.');
268 // Purges expired fast-click bonus entries
269 function purgeExpiredTurboBonus() {
271 $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__);
273 if (!SQL_HASZEROAFFECTED()) {
274 // Send out email to admin
275 sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
279 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
283 // Determines whether the "bonus rallye" is active
284 function isBonusRallyeActive () {
286 if (!isset($GLOBALS['bonus_rallye_active'])) {
288 $GLOBALS['bonus_rallye_active'] = (getConfig('bonus_active') == 'Y');
292 return $GLOBALS['bonus_rallye_active'];
295 // Determines whether the "bonus new_member_notify" is active
296 function isBonusNewMemberNotifyEnabled () {
298 if (!isset($GLOBALS['bonus_new_member_notify_active'])) {
300 $GLOBALS['bonus_new_member_notify_active'] = (getConfig('bonus_new_member_notify') == 'Y');
304 return $GLOBALS['bonus_new_member_notify_active'];
307 // Getter for bonus_timeout
308 function getBonusTimeout () {
310 if (!isset($GLOBALS[__FUNCTION__])) {
312 $GLOBALS[__FUNCTION__] = getConfig('bonus_timeout');
316 return $GLOBALS[__FUNCTION__];
319 // Getter for bonus_mode
320 function getBonusMode () {
322 if (!isset($GLOBALS[__FUNCTION__])) {
324 $GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
328 return $GLOBALS[__FUNCTION__];
331 // Getter for bonus_ranks
332 function getBonusRanks () {
334 if (!isset($GLOBALS[__FUNCTION__])) {
336 $GLOBALS[__FUNCTION__] = getConfig('bonus_ranks');
340 return $GLOBALS[__FUNCTION__];
343 // Getter for turbo_rates
344 function getTurboRates () {
346 if (!isset($GLOBALS[__FUNCTION__])) {
348 $GLOBALS[__FUNCTION__] = getConfig('turbo_rates');
352 return $GLOBALS[__FUNCTION__];
355 // Getter for login_timeout
356 function getLoginTimeout () {
358 if (!isset($GLOBALS[__FUNCTION__])) {
360 $GLOBALS[__FUNCTION__] = getConfig('login_timeout');
364 return $GLOBALS[__FUNCTION__];
367 // Getter for bonus_ref
368 function getBonusRef () {
370 if (!isset($GLOBALS[__FUNCTION__])) {
372 $GLOBALS[__FUNCTION__] = getConfig('bonus_ref');
376 return $GLOBALS[__FUNCTION__];