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 (($GLOBALS['output_mode'] == 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) && ($GLOBALS['output_mode'] != 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 if (getConfig('bonus_click_yn') == "Y") $ADD .= " + turbo_bonus";
72 if (getConfig('bonus_login_yn') == "Y") $ADD .= " + login_bonus";
73 if (getConfig('bonus_order_yn') == "Y") $ADD .= " + bonus_order";
74 if (getConfig('bonus_stats_yn') == "Y") $ADD .= " + bonus_stats";
75 if (getConfig('bonus_ref_yn') == "Y") $ADD .= " + bonus_ref";
77 // Shall we add some entries?
79 $whereStatement1 .= " AND (0".$ADD.") > 0";
82 // Run SQL string to check for accounts
83 $result_main = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, (0".$ADD.") AS points
84 FROM `{!_MYSQL_PREFIX!}_user_data`
85 ".$whereStatement1."".$ADD."
86 ORDER BY points DESC, userid
88 array($whereStatement2), __FILE__, __LINE__);
90 // Some entries were found?
91 if (SQL_NUMROWS($result_main) > 0) {
92 // Load our winners...
93 while ($content = SQL_FETCHARRAY($result_main)) {
94 // Make sure zero points are not mailed
95 if ($content['points'] > 0) {
96 // Add points to user's account directly
97 ADD_POINTS_REFSYSTEM("monthly_bonus", $content['uid'], $content['points'], false, "0", false, "direct");
99 // Translate gender/points
100 $content['gender'] = TRANSLATE_GENDER($content['gender']);
101 $content['points'] = TRANSLATE_COMMA($content['points']);
103 // Load email template and email it away
104 $msg = LOAD_EMAIL_TEMPLATE("member_bonus", $content['points'], bigintval($content['uid']));
105 SEND_EMAIL($content['email'], BONUS_MONTHLY_ONLINE_BONUS, $msg);
110 $result = SQL_QUERY("UPDATE `{!_MYSQL_PREFIX!}_user_data`
111 SET turbo_bonus=0, login_bonus=0, bonus_order=0, bonus_stats=0, bonus_ref=0", __FILE__, __LINE__);
115 SQL_FREERESULT($result_main);