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 - 2013 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 ($id, $userid, $type) {
45 // Shall we add bonus points?
46 if (!isBonusRallyeActive()) {
69 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid type %s detected.", $type));
73 // Is a column name set?
75 // No, then abort here
80 $rank = countSumTotalData($id, 'bonus_turbo', 'id', $column, TRUE) + 1;
85 $points = getTurboBonus();
87 // Anything else so let's explode all entered rank points
88 $test = explode(';', getTurboRates());
89 if (!empty($test[$rank - 2])) {
91 $points = $test[$rank - 2];
98 // Add points to his account directly
99 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `turbo_bonus`=`turbo_bonus`+%s WHERE `userid`=%s LIMIT 1",
103 ), __FUNCTION__, __LINE__);
105 // Rember this whole data for displaying ranking list
106 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())",
113 ), __FUNCTION__, __LINE__);
115 // @TODO Rewrite this to a filter
116 if ((isExtensionInstalledAndNewer('bonus', '0.3.5')) && (getBonusMode() != 'ADD') && ($points > 0)) {
117 handleBonusPoints($points, $userid);
122 function addBonusRanks ($data, $type, $userid) {
126 $GLOBALS['ranking_content'] = array();
128 // Clear rankings by default
129 $GLOBALS['ranking_content']['rankings'] = '';
131 // How many ranks do we have?
132 $ranks = count(explode(';', getTurboRates())) + 1;
134 // Load current user's data
135 $result = SQL_QUERY_ESC("SELECT `level`, `points`, `timemark` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s AND `userid`=%s LIMIT 1",
140 ), __FUNCTION__, __LINE__);
143 if (SQL_NUMROWS($result) == 1) {
145 $GLOBALS['ranking_content'] = merge_array($GLOBALS['ranking_content'], SQL_FETCHARRAY($result));
147 // Remember all values for later use
150 // Transfer data to template
151 $GLOBALS['ranking_content']['timemark'] = generateDateTime($GLOBALS['ranking_content']['timemark'], 1);
154 $GLOBALS['ranking_content']['own'] = loadTemplate('show_bonus_yr', TRUE, $GLOBALS['ranking_content']);
158 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s ORDER BY `level` ASC LIMIT {?bonus_lines?}",
159 array($type, $data), __FUNCTION__, __LINE__);
160 if (!SQL_HASZERONUMS($result)) {
161 // Output all ranks (levels)
162 for ($rank = 1; $rank <= SQL_NUMROWS($result); $rank++) {
164 $result_users = SQL_QUERY_ESC("SELECT
168 `{?_MYSQL_PREFIX?}_bonus_turbo`
173 array($type, $data, $rank), __FUNCTION__, __LINE__);
175 // Nothing found by default
176 $rows['userid'] = '---';
177 $rows['points'] = '---';
179 // Are you one of them?
180 if (SQL_NUMROWS($result_users) == 1) {
182 $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
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="bad">{%message,MEMBER_BONUS_NO_RANKS=' . $data . '%}</div>
213 // Hanle any bonus points the given user shall become
214 function handleBonusPoints ($mode, $userid) {
215 // Shall we add bonus points?
216 if (!isBonusRallyeActive()) {
220 // Default is not working
223 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
224 if ((getBonusMode() == 'UID') && (!isValidId($userid)) && (isExtensionActive('jackpot'))) {
225 // Update database & config
226 updateConfiguration('bonus_mode', 'JACKPOT');
229 if ($mode == 'login_bonus') {
230 // Login bonus detected
231 $points = getLoginBonus();
233 // Direct points supplied
237 // Check his amount first
238 $total = getTotalPoints($userid);
240 // Subtract points from...
241 switch (getBonusMode()) {
242 case 'ADD': // Only add them (no subtraction)
246 case 'JACKPOT': // ... jackpot
247 if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) === FALSE) && (isValidId($userid))) {
248 if ($total >= $points) {
249 // Subtract points from userid's account
250 $return = subtractPointsFromJackpot('bonus_payout_jackpot', $userid, $points);
255 case 'UID': // ... userid's account
256 if ($total >= $points) {
257 // Subtract points from userid's account
258 $return = subtractPoints('bonus_payout_userid', $userid, $points);
259 } elseif (isExtensionActive('jackpot')) {
260 // Try to subtract from jackpot
261 $return = subtractPointsFromJackpot($points);
265 default: // This should not happen
266 reportBug(__FUNCTION__, __LINE__, 'Invalid bonus-mode ' . getBonusMode() . ' detected.');
274 // Purges expired fast-click bonus entries
275 function purgeExpiredTurboBonus () {
277 $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__);
279 if (!SQL_HASZEROAFFECTED()) {
280 // Send out email to admin
281 sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_purge_turbo', SQL_AFFECTEDROWS());
285 //-----------------------------------------------------------------------------
287 //-----------------------------------------------------------------------------
289 // Determines whether the "bonus rallye" is active
290 function isBonusRallyeActive () {
292 if (!isset($GLOBALS['bonus_rallye_active'])) {
294 $GLOBALS['bonus_rallye_active'] = (getBonusActive() == 'Y');
298 return $GLOBALS['bonus_rallye_active'];
301 // Determines whether the "bonus new_member_notify" is active
302 function isBonusNewMemberNotifyEnabled () {
304 if (!isset($GLOBALS['bonus_new_member_notify_active'])) {
306 $GLOBALS['bonus_new_member_notify_active'] = (getBonusNewMemberNotify() == 'Y');
310 return $GLOBALS['bonus_new_member_notify_active'];
313 // Getter for bonus_timeout
314 function getBonusTimeout () {
316 if (!isset($GLOBALS[__FUNCTION__])) {
318 $GLOBALS[__FUNCTION__] = getConfig('bonus_timeout');
322 return $GLOBALS[__FUNCTION__];
325 // Getter for bonus_mode
326 function getBonusMode () {
328 if (!isset($GLOBALS[__FUNCTION__])) {
330 $GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
334 return $GLOBALS[__FUNCTION__];
337 // Getter for bonus_ranks
338 function getBonusRanks () {
340 if (!isset($GLOBALS[__FUNCTION__])) {
342 $GLOBALS[__FUNCTION__] = getConfig('bonus_ranks');
346 return $GLOBALS[__FUNCTION__];
349 // Getter for turbo_rates
350 function getTurboRates () {
352 if (!isset($GLOBALS[__FUNCTION__])) {
354 $GLOBALS[__FUNCTION__] = getConfig('turbo_rates');
358 return $GLOBALS[__FUNCTION__];
361 // Getter for login_timeout
362 function getLoginTimeout () {
364 if (!isset($GLOBALS[__FUNCTION__])) {
366 $GLOBALS[__FUNCTION__] = getConfig('login_timeout');
370 return $GLOBALS[__FUNCTION__];
373 // Getter for login_bonus
374 function getLoginBonus () {
376 if (!isset($GLOBALS[__FUNCTION__])) {
378 $GLOBALS[__FUNCTION__] = getConfig('login_bonus');
382 return $GLOBALS[__FUNCTION__];
385 // Getter for turbo_bonus
386 function getTurboBonus () {
388 if (!isset($GLOBALS[__FUNCTION__])) {
390 $GLOBALS[__FUNCTION__] = getConfig('turbo_bonus');
394 return $GLOBALS[__FUNCTION__];
397 // Getter for bonus_ref
398 function getBonusRef () {
400 if (!isset($GLOBALS[__FUNCTION__])) {
402 $GLOBALS[__FUNCTION__] = getConfig('bonus_ref');
406 return $GLOBALS[__FUNCTION__];
409 // Getter for bonus_userid
410 function getBonusUserid () {
412 if (!isset($GLOBALS[__FUNCTION__])) {
414 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
418 return $GLOBALS[__FUNCTION__];
421 // Getter for bonus_active
422 function getBonusActive () {
424 if (!isset($GLOBALS[__FUNCTION__])) {
426 $GLOBALS[__FUNCTION__] = getConfig('bonus_active');
430 return $GLOBALS[__FUNCTION__];
433 // Getter for bonus_notify_points
434 function getBonusNotifyPoints () {
436 if (!isset($GLOBALS[__FUNCTION__])) {
438 $GLOBALS[__FUNCTION__] = getConfig('bonus_notify_points');
442 return $GLOBALS[__FUNCTION__];
445 // Getter for bonus_new_member_notify
446 function getBonusNewMemberNotify () {
448 if (!isset($GLOBALS[__FUNCTION__])) {
450 $GLOBALS[__FUNCTION__] = getConfig('bonus_new_member_notify');
454 return $GLOBALS[__FUNCTION__];
457 // Getter for bonus_stats
458 function getBonusStats () {
460 if (!isset($GLOBALS[__FUNCTION__])) {
462 $GLOBALS[__FUNCTION__] = getConfig('bonus_stats');
466 return $GLOBALS[__FUNCTION__];
469 // Getter for bonus_order
470 function getBonusOrder () {
472 if (!isset($GLOBALS[__FUNCTION__])) {
474 $GLOBALS[__FUNCTION__] = getConfig('bonus_order');
478 return $GLOBALS[__FUNCTION__];
481 // Getter for bonus_lines
482 function getBonusLines () {
484 if (!isset($GLOBALS[__FUNCTION__])) {
486 $GLOBALS[__FUNCTION__] = getConfig('bonus_lines');
490 return $GLOBALS[__FUNCTION__];
493 // Getter for bonus_include_own
494 function getBonusIncludeOwn () {
496 if (!isset($GLOBALS[__FUNCTION__])) {
498 $GLOBALS[__FUNCTION__] = getConfig('bonus_include_own');
502 return $GLOBALS[__FUNCTION__];
505 // Checks whether bonus_include_own is set to 'Y'
506 function isBonusIncludeOwnEnabled () {
508 if (!isset($GLOBALS[__FUNCTION__])) {
510 $GLOBALS[__FUNCTION__] = (getBonusIncludeOwn() == 'Y');
514 return $GLOBALS[__FUNCTION__];
517 // Getter for bonus_disable_notify
518 function getBonusDisableNotify () {
520 if (!isset($GLOBALS[__FUNCTION__])) {
522 $GLOBALS[__FUNCTION__] = getConfig('bonus_disable_notify');
526 return $GLOBALS[__FUNCTION__];
529 // Getter for bonus_enable_notify
530 function getBonusEnableNotify () {
532 if (!isset($GLOBALS[__FUNCTION__])) {
534 $GLOBALS[__FUNCTION__] = getConfig('bonus_enable_notify');
538 return $GLOBALS[__FUNCTION__];
541 // Getter for include_bonus_click
542 function getIncludeBonusClick () {
544 if (!isset($GLOBALS[__FUNCTION__])) {
546 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_click');
550 return $GLOBALS[__FUNCTION__];
553 // Checks whether include_bonus_click is set to 'Y'
554 function isIncludeBonusClickEnabled () {
556 if (!isset($GLOBALS[__FUNCTION__])) {
558 $GLOBALS[__FUNCTION__] = (getIncludeBonusClick() == 'Y');
562 return $GLOBALS[__FUNCTION__];
565 // Getter for include_bonus_login
566 function getIncludeBonusLogin () {
568 if (!isset($GLOBALS[__FUNCTION__])) {
570 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_login');
574 return $GLOBALS[__FUNCTION__];
577 // Checks whether include_bonus_login is set to 'Y'
578 function isIncludeBonusLoginEnabled () {
580 if (!isset($GLOBALS[__FUNCTION__])) {
582 $GLOBALS[__FUNCTION__] = (getIncludeBonusLogin() == 'Y');
586 return $GLOBALS[__FUNCTION__];
589 // Getter for include_bonus_order
590 function getIncludeBonusOrder () {
592 if (!isset($GLOBALS[__FUNCTION__])) {
594 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_order');
598 return $GLOBALS[__FUNCTION__];
601 // Checks whether include_bonus_order is set to 'Y'
602 function isIncludeBonusOrderEnabled () {
604 if (!isset($GLOBALS[__FUNCTION__])) {
606 $GLOBALS[__FUNCTION__] = (getIncludeBonusOrder() == 'Y');
610 return $GLOBALS[__FUNCTION__];
613 // Getter for include_bonus_Ref
614 function getIncludeBonusRef () {
616 if (!isset($GLOBALS[__FUNCTION__])) {
618 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_ref');
622 return $GLOBALS[__FUNCTION__];
625 // Checks whether include_bonus_ref is set to 'Y'
626 function isIncludeBonusRefEnabled () {
628 if (!isset($GLOBALS[__FUNCTION__])) {
630 $GLOBALS[__FUNCTION__] = (getIncludeBonusRef() == 'Y');
634 return $GLOBALS[__FUNCTION__];
637 // Getter for include_bonus_stats
638 function getIncludeBonusStats () {
640 if (!isset($GLOBALS[__FUNCTION__])) {
642 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_stats');
646 return $GLOBALS[__FUNCTION__];
649 // Checks whether include_bonus_stats is set to 'Y'
650 function isIncludeBonusStatsEnabled () {
652 if (!isset($GLOBALS[__FUNCTION__])) {
654 $GLOBALS[__FUNCTION__] = (getIncludeBonusStats() == 'Y');
658 return $GLOBALS[__FUNCTION__];