2bbe3d92017db5fa7d33de7f7904cc447c5629df
[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 - 2009 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         die();
42 } elseif (!isExtensionActive('bonus')) {
43         return;
44 }
45
46 // Do not execute when script is in CSS mode or no daily reset
47 if ((getOutputMode() == 1) || (!isResetModeEnabled())) return;
48 //* DEBUG: */ outputHtml(basename(__FILE__)."<br />");
49
50 // Get current month (2 digits)
51 $curr = date('m', time());
52
53 if (($curr != getConfig('last_month')) && (getConfig('bonus_ranks') > 0) && (getOutputMode() != 1)) {
54         // Extension 'autopurge' is inactive or purging of inactive accounts is deactivated
55         $whereStatement1 = "WHERE `status`='CONFIRMED'";
56         $whereStatement2 = getConfig('bonus_ranks');
57
58         // Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...)
59         if (isExtensionActive('autopurge')) {
60                 // Use last online stamp only when autopurge for inactive members is activated
61                 if (getConfig('ap_inactive_since') > 0) {
62                         // Okay, include last online timestamp
63                         $whereStatement1 = "WHERE `status`='CONFIRMED' AND `last_online` >= (UNIX_TIMESTAMP() - {?ap_inactive_since?})";
64                         $whereStatement2 = getConfig('bonus_ranks');
65                 } // END - if
66         } // END - if
67
68         // Add more bonus points here
69         $add = '';
70         // @TODO Rewrite this to a filter
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
85         `{?_MYSQL_PREFIX?}_user_data`
86 ".$whereStatement1."".$add."
87 ORDER BY
88         `points` DESC,
89         `userid` ASC
90 LIMIT %s",
91                 array($whereStatement2), __FILE__, __LINE__);
92
93         // Some entries were found?
94         if (SQL_NUMROWS($result_main) > 0) {
95                 // Load our winners...
96                 while ($content = SQL_FETCHARRAY($result_main)) {
97                         // Make sure zero points are not mailed
98                         if ($content['points'] > 0) {
99                                 // Add points to user's account directly
100                                 addPointsDirectly('monthly_bonus', $content['userid'], $content['points']);
101
102                                 // Translate gender/points
103                                 $content['gender'] = translateGender($content['gender']);
104                                 $content['points'] = translateComma($content['points']);
105
106                                 // Load email template and email it away
107                                 $message = loadEmailTemplate('member_bonus', $content['points'], bigintval($content['userid']));
108                                 sendEmail($content['email'], getMessage('BONUS_MONTHLY_ONLINE_BONUS'), $message);
109                         } // END - if
110                 } // END - while
111
112                 // Reset accounts
113                 $result = SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data`
114 SET
115         `turbo_bonus`=0,
116         `login_bonus`=0,
117         `bonus_order`=0,
118         `bonus_stats`=0,
119         `bonus_ref`=0', __FILE__, __LINE__);
120         } // END - if
121
122         // Free memory
123         SQL_FREERESULT($result_main);
124 } // END - if
125
126 //
127 ?>