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 ($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) {
124 $self = FALSE; $OUT = ''; $GLOBALS['ranking_content'] = array();
126 // Clear rankings by default
127 $GLOBALS['ranking_content']['rankings'] = '';
129 // How many ranks do we have?
130 $ranks = count(explode(';', getTurboRates())) + 1;
132 // Load current user's data
133 $result = SQL_QUERY_ESC("SELECT `level`, `points`, `timemark` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s AND `userid`=%s LIMIT 1",
138 ), __FUNCTION__, __LINE__);
141 if (SQL_NUMROWS($result) == 1) {
143 $GLOBALS['ranking_content'] = merge_array($GLOBALS['ranking_content'], SQL_FETCHARRAY($result));
145 // Remember all values for later use
148 // Transfer data to template
149 $GLOBALS['ranking_content']['timemark'] = generateDateTime($GLOBALS['ranking_content']['timemark'], 1);
152 $GLOBALS['ranking_content']['own'] = loadTemplate('show_bonus_yr', TRUE, $GLOBALS['ranking_content']);
156 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE `%s`=%s ORDER BY `level` ASC LIMIT {?bonus_lines?}",
157 array($type, $data), __FUNCTION__, __LINE__);
158 if (!SQL_HASZERONUMS($result)) {
159 // Output all ranks (levels)
160 for ($rank = 1; $rank <= SQL_NUMROWS($result); $rank++) {
162 $result_users = SQL_QUERY_ESC("SELECT
166 `{?_MYSQL_PREFIX?}_bonus_turbo`
171 array($type, $data, $rank), __FUNCTION__, __LINE__);
173 // Nothing found by default
174 $rows['userid'] = '---';
175 $rows['points'] = '---';
177 // Are you one of them?
178 if (SQL_NUMROWS($result_users) == 1) {
180 $rows = merge_array($rows, SQL_FETCHARRAY($result_users));
184 SQL_FREERESULT($result_users);
187 $rows['rank'] = $rank;
190 $OUT .= loadTemplate('member_bonus_turbo_row', TRUE, $rows);
193 if ($self === FALSE) {
194 // If current user was not found set constant
195 $GLOBALS['ranking_content']['rankings'] = '{--MEMBER_BONUS_RANK_YOU_ARE_404--}';
199 // @TODO Move this HTML to a template
201 <td colspan="3" align="center" height="30" class="bottom">
202 <div class="bad">{%message,MEMBER_BONUS_NO_RANKS=' . $data . '%}</div>
211 // Hanle any bonus points the given user shall become
212 function handleBonusPoints ($mode, $userid) {
213 // Shall we add bonus points?
214 if (!isBonusRallyeActive()) {
218 // Default is not working
221 // Switch to jackpot-mode when no UID is supplied but userid-mode is selected
222 if ((getBonusMode() == 'UID') && (!isValidId($userid)) && (isExtensionActive('jackpot'))) {
223 // Update database & config
224 updateConfiguration('bonus_mode', 'JACKPOT');
227 if ($mode == 'login_bonus') {
228 // Login bonus detected
229 $points = getLoginBonus();
231 // Direct points supplied
235 // Check his amount first
236 $total = getTotalPoints($userid);
238 // Subtract points from...
239 switch (getBonusMode()) {
240 case 'ADD': // Only add them (no subtraction)
244 case 'JACKPOT': // ... jackpot
245 if ((isExtensionActive('jackpot')) && (subtractPointsFromJackpot($points) === FALSE) && (isValidId($userid))) {
246 if ($total >= $points) {
247 // Subtract points from userid's account
248 $return = subtractPointsFromJackpot('bonus_payout_jackpot', $userid, $points);
253 case 'UID': // ... userid's account
254 if ($total >= $points) {
255 // Subtract points from userid's account
256 $return = subtractPoints('bonus_payout_userid', $userid, $points);
257 } elseif (isExtensionActive('jackpot')) {
258 // Try to subtract from jackpot
259 $return = subtractPointsFromJackpot($points);
263 default: // This should not happen
264 reportBug(__FUNCTION__, __LINE__, 'Invalid bonus-mode ' . getBonusMode() . ' detected.');
272 // Purges expired fast-click bonus entries
273 function purgeExpiredTurboBonus() {
275 $result = SQL_QUERY('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus_turbo` WHERE (UNIX_TIMESTAMP() - `timemark`) >= {?bonus_timeout?}', __FUNCTION__, __LINE__);
277 if (!SQL_HASZEROAFFECTED()) {
278 // Send out email to admin
279 sendAdminNotification('{--ADMIN_AUTOPURGE_TURBO_SUBJECT--}', 'admin_autopurge_turbo', SQL_AFFECTEDROWS());
283 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
287 // Determines whether the "bonus rallye" is active
288 function isBonusRallyeActive () {
290 if (!isset($GLOBALS['bonus_rallye_active'])) {
292 $GLOBALS['bonus_rallye_active'] = (getBonusActive() == 'Y');
296 return $GLOBALS['bonus_rallye_active'];
299 // Determines whether the "bonus new_member_notify" is active
300 function isBonusNewMemberNotifyEnabled () {
302 if (!isset($GLOBALS['bonus_new_member_notify_active'])) {
304 $GLOBALS['bonus_new_member_notify_active'] = (getBonusNewMemberNotify() == 'Y');
308 return $GLOBALS['bonus_new_member_notify_active'];
311 // Getter for bonus_timeout
312 function getBonusTimeout () {
314 if (!isset($GLOBALS[__FUNCTION__])) {
316 $GLOBALS[__FUNCTION__] = getConfig('bonus_timeout');
320 return $GLOBALS[__FUNCTION__];
323 // Getter for bonus_mode
324 function getBonusMode () {
326 if (!isset($GLOBALS[__FUNCTION__])) {
328 $GLOBALS[__FUNCTION__] = getConfig('bonus_mode');
332 return $GLOBALS[__FUNCTION__];
335 // Getter for bonus_ranks
336 function getBonusRanks () {
338 if (!isset($GLOBALS[__FUNCTION__])) {
340 $GLOBALS[__FUNCTION__] = getConfig('bonus_ranks');
344 return $GLOBALS[__FUNCTION__];
347 // Getter for turbo_rates
348 function getTurboRates () {
350 if (!isset($GLOBALS[__FUNCTION__])) {
352 $GLOBALS[__FUNCTION__] = getConfig('turbo_rates');
356 return $GLOBALS[__FUNCTION__];
359 // Getter for login_timeout
360 function getLoginTimeout () {
362 if (!isset($GLOBALS[__FUNCTION__])) {
364 $GLOBALS[__FUNCTION__] = getConfig('login_timeout');
368 return $GLOBALS[__FUNCTION__];
371 // Getter for login_bonus
372 function getLoginBonus () {
374 if (!isset($GLOBALS[__FUNCTION__])) {
376 $GLOBALS[__FUNCTION__] = getConfig('login_bonus');
380 return $GLOBALS[__FUNCTION__];
383 // Getter for turbo_bonus
384 function getTurboBonus () {
386 if (!isset($GLOBALS[__FUNCTION__])) {
388 $GLOBALS[__FUNCTION__] = getConfig('turbo_bonus');
392 return $GLOBALS[__FUNCTION__];
395 // Getter for bonus_ref
396 function getBonusRef () {
398 if (!isset($GLOBALS[__FUNCTION__])) {
400 $GLOBALS[__FUNCTION__] = getConfig('bonus_ref');
404 return $GLOBALS[__FUNCTION__];
407 // Getter for bonus_userid
408 function getBonusUserid () {
410 if (!isset($GLOBALS[__FUNCTION__])) {
412 $GLOBALS[__FUNCTION__] = getConfig('bonus_userid');
416 return $GLOBALS[__FUNCTION__];
419 // Getter for bonus_active
420 function getBonusActive () {
422 if (!isset($GLOBALS[__FUNCTION__])) {
424 $GLOBALS[__FUNCTION__] = getConfig('bonus_active');
428 return $GLOBALS[__FUNCTION__];
431 // Getter for bonus_notify_points
432 function getBonusNotifyPoints () {
434 if (!isset($GLOBALS[__FUNCTION__])) {
436 $GLOBALS[__FUNCTION__] = getConfig('bonus_notify_points');
440 return $GLOBALS[__FUNCTION__];
443 // Getter for bonus_new_member_notify
444 function getBonusNewMemberNotify () {
446 if (!isset($GLOBALS[__FUNCTION__])) {
448 $GLOBALS[__FUNCTION__] = getConfig('bonus_new_member_notify');
452 return $GLOBALS[__FUNCTION__];
455 // Getter for bonus_stats
456 function getBonusStats () {
458 if (!isset($GLOBALS[__FUNCTION__])) {
460 $GLOBALS[__FUNCTION__] = getConfig('bonus_stats');
464 return $GLOBALS[__FUNCTION__];
467 // Getter for bonus_order
468 function getBonusOrder () {
470 if (!isset($GLOBALS[__FUNCTION__])) {
472 $GLOBALS[__FUNCTION__] = getConfig('bonus_order');
476 return $GLOBALS[__FUNCTION__];
479 // Getter for bonus_lines
480 function getBonusLines () {
482 if (!isset($GLOBALS[__FUNCTION__])) {
484 $GLOBALS[__FUNCTION__] = getConfig('bonus_lines');
488 return $GLOBALS[__FUNCTION__];
491 // Getter for bonus_include_own
492 function getBonusIncludeOwn () {
494 if (!isset($GLOBALS[__FUNCTION__])) {
496 $GLOBALS[__FUNCTION__] = getConfig('bonus_include_own');
500 return $GLOBALS[__FUNCTION__];
503 // Checks whether bonus_include_own is set to 'Y'
504 function isBonusIncludeOwnEnabled () {
506 if (!isset($GLOBALS[__FUNCTION__])) {
508 $GLOBALS[__FUNCTION__] = (getBonusIncludeOwn() == 'Y');
512 return $GLOBALS[__FUNCTION__];
515 // Getter for bonus_disable_notify
516 function getBonusDisableNotify () {
518 if (!isset($GLOBALS[__FUNCTION__])) {
520 $GLOBALS[__FUNCTION__] = getConfig('bonus_disable_notify');
524 return $GLOBALS[__FUNCTION__];
527 // Getter for bonus_enable_notify
528 function getBonusEnableNotify () {
530 if (!isset($GLOBALS[__FUNCTION__])) {
532 $GLOBALS[__FUNCTION__] = getConfig('bonus_enable_notify');
536 return $GLOBALS[__FUNCTION__];
539 // Getter for include_bonus_click
540 function getIncludeBonusClick () {
542 if (!isset($GLOBALS[__FUNCTION__])) {
544 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_click');
548 return $GLOBALS[__FUNCTION__];
551 // Checks whether include_bonus_click is set to 'Y'
552 function isIncludeBonusClickEnabled () {
554 if (!isset($GLOBALS[__FUNCTION__])) {
556 $GLOBALS[__FUNCTION__] = (getIncludeBonusClick() == 'Y');
560 return $GLOBALS[__FUNCTION__];
563 // Getter for include_bonus_login
564 function getIncludeBonusLogin () {
566 if (!isset($GLOBALS[__FUNCTION__])) {
568 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_login');
572 return $GLOBALS[__FUNCTION__];
575 // Checks whether include_bonus_login is set to 'Y'
576 function isIncludeBonusLoginEnabled () {
578 if (!isset($GLOBALS[__FUNCTION__])) {
580 $GLOBALS[__FUNCTION__] = (getIncludeBonusLogin() == 'Y');
584 return $GLOBALS[__FUNCTION__];
587 // Getter for include_bonus_order
588 function getIncludeBonusOrder () {
590 if (!isset($GLOBALS[__FUNCTION__])) {
592 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_order');
596 return $GLOBALS[__FUNCTION__];
599 // Checks whether include_bonus_order is set to 'Y'
600 function isIncludeBonusOrderEnabled () {
602 if (!isset($GLOBALS[__FUNCTION__])) {
604 $GLOBALS[__FUNCTION__] = (getIncludeBonusOrder() == 'Y');
608 return $GLOBALS[__FUNCTION__];
611 // Getter for include_bonus_Ref
612 function getIncludeBonusRef () {
614 if (!isset($GLOBALS[__FUNCTION__])) {
616 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_ref');
620 return $GLOBALS[__FUNCTION__];
623 // Checks whether include_bonus_ref is set to 'Y'
624 function isIncludeBonusRefEnabled () {
626 if (!isset($GLOBALS[__FUNCTION__])) {
628 $GLOBALS[__FUNCTION__] = (getIncludeBonusRef() == 'Y');
632 return $GLOBALS[__FUNCTION__];
635 // Getter for include_bonus_stats
636 function getIncludeBonusStats () {
638 if (!isset($GLOBALS[__FUNCTION__])) {
640 $GLOBALS[__FUNCTION__] = getConfig('include_bonus_stats');
644 return $GLOBALS[__FUNCTION__];
647 // Checks whether include_bonus_stats is set to 'Y'
648 function isIncludeBonusStatsEnabled () {
650 if (!isset($GLOBALS[__FUNCTION__])) {
652 $GLOBALS[__FUNCTION__] = (getIncludeBonusStats() == 'Y');
656 return $GLOBALS[__FUNCTION__];