2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/14/2004 *
4 * =============== Last change: 11/19/2004 *
6 * -------------------------------------------------------------------- *
7 * File : monthly_bonus.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Monthly bonus from click-bonus *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Monatlicher Bonus von Klick-Verguetung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43 } elseif (!EXT_IS_ACTIVE('bonus')) {
47 // Do not execute when script is in CSS mode or no daily reset
48 if ((getOutputMode() == 1) || (!isResetModeEnabled())) return;
49 //* DEBUG: */ echo basename(__FILE__)."<br />\n";
51 // Get current month (2 digits)
52 $curr = date('m', time());
54 if (($curr != getConfig('last_month')) && (getConfig('bonus_ranks') > 0) && (getOutputMode() != 1)) {
55 // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated
56 $whereStatement1 = "WHERE `status`='CONFIRMED'";
57 $whereStatement2 = getConfig('bonus_ranks');
59 // Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...)
60 if (EXT_IS_ACTIVE('autopurge')) {
61 // Use last online stamp only when autopurge for inactive members is activated
62 if (getConfig('ap_inactive_since') > 0) {
63 // Okay, include last online timestamp
64 $whereStatement1 = sprintf("WHERE `status`='CONFIRMED' AND `last_online` >= (UNIX_TIMESTAMP() - %s)", getConfig('ap_inactive_since'));
65 $whereStatement2 = getConfig('bonus_ranks');
69 // Add more bonus points here
71 // @TODO Rewrite this to a filter
72 if (getConfig('bonus_click_yn') == 'Y') $add .= " + `turbo_bonus`";
73 if (getConfig('bonus_login_yn') == 'Y') $add .= " + `login_bonus`";
74 if (getConfig('bonus_order_yn') == 'Y') $add .= " + `bonus_order`";
75 if (getConfig('bonus_stats_yn') == 'Y') $add .= " + `bonus_stats`";
76 if (getConfig('bonus_ref_yn') == 'Y') $add .= " + `bonus_ref`";
78 // Shall we add some entries?
80 $whereStatement1 .= " AND (0" . $add . ") > 0";
83 // Run SQL string to check for accounts
84 $result_main = SQL_QUERY_ESC("SELECT `userid`, `email`, `gender`, `surname`, `family`, (0".$add.") AS points
86 `{!_MYSQL_PREFIX!}_user_data`
87 ".$whereStatement1."".$add."
92 array($whereStatement2), __FILE__, __LINE__);
94 // Some entries were found?
95 if (SQL_NUMROWS($result_main) > 0) {
96 // Load our winners...
97 while ($content = SQL_FETCHARRAY($result_main)) {
98 // Make sure zero points are not mailed
99 if ($content['points'] > 0) {
100 // Add points to user's account directly
101 ADD_POINTS_REFSYSTEM_DIRECT('monthly_bonus', $content['uid'], $content['points']);
103 // Translate gender/points
104 $content['gender'] = translateGender($content['gender']);
105 $content['points'] = translateComma($content['points']);
107 // Load email template and email it away
108 $message = LOAD_EMAIL_TEMPLATE('member_bonus', $content['points'], bigintval($content['uid']));
109 sendEmail($content['email'], getMessage('BONUS_MONTHLY_ONLINE_BONUS'), $message);
114 $result = SQL_QUERY("UPDATE `{!_MYSQL_PREFIX!}_user_data`
115 SET turbo_bonus=0, login_bonus=0, bonus_order=0, bonus_stats=0, bonus_ref=0", __FILE__, __LINE__);
119 SQL_FREERESULT($result_main);