New naming convention applied to many functions, see #118 for details
[mailer.git] / inc / monthly / monthly_bonus.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/14/2004 *
4  * ===============                              Last change: 11/19/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : monthly_bonus.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Monthly bonus from click-bonus                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Monatlicher Bonus von Klick-Verguetung           *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!EXT_IS_ACTIVE('bonus')) {
44         return;
45 }
46
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";
50
51 // Get current month (2 digits)
52 $curr = date('m', time());
53
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'));
58
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'));
66                 } // END - if
67         } // END - if
68
69         // Add more bonus points here
70         $add = '';
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";
76
77         // Shall we add some entries?
78         if (!empty($add)) {
79                 $whereStatement1 .= " AND (0".$add.") > 0";
80         } // END - if
81
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
87 LIMIT %s",
88                 array($whereStatement2), __FILE__, __LINE__);
89
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_DIRECT('monthly_bonus', $content['uid'], $content['points']);
98
99                                 // Translate gender/points
100                                 $content['gender']       = translateGender($content['gender']);
101                                 $content['points'] = translateComma($content['points']);
102
103                                 // Load email template and email it away
104                                 $msg = LOAD_EMAIL_TEMPLATE("member_bonus", $content['points'], bigintval($content['uid']));
105                                 sendEmail($content['email'], getMessage('BONUS_MONTHLY_ONLINE_BONUS'), $msg);
106                         } // END - if
107                 } // END - while
108
109                 // Reset accounts
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__);
112         } // END - if
113
114         // Free memory
115         SQL_FREERESULT($result_main);
116 } // END - if
117
118 //
119 ?>