Mailer used in many places, we still need a good 'selling' title
[mailer.git] / inc / monthly / monthly_bonus.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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
57         // Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...)
58         if (isExtensionActive('autopurge')) {
59                 // Use last online stamp only when autopurge for inactive members is activated
60                 if (getConfig('ap_inactive_since') > 0) {
61                         // Okay, include last online timestamp
62                         $whereStatement1 = "WHERE `status`='CONFIRMED' AND `last_online` >= (UNIX_TIMESTAMP() - {?ap_inactive_since?})";
63                 } // END - if
64         } // END - if
65
66         // Add more bonus points here
67         $add = '';
68         // @TODO Rewrite this to a filter
69         if (getConfig('bonus_click_yn') == 'Y') $add .= ' + `turbo_bonus`';
70         if (getConfig('bonus_login_yn') == 'Y') $add .= ' + `login_bonus`';
71         if (getConfig('bonus_order_yn') == 'Y') $add .= ' + `bonus_order`';
72         if (getConfig('bonus_stats_yn') == 'Y') $add .= ' + `bonus_stats`';
73         if (getConfig('bonus_ref_yn')   == 'Y') $add .= ' + `bonus_ref`';
74
75         // Shall we add some entries?
76         if (!empty($add)) {
77                 $whereStatement1 .= ' AND (0' . $add . ') > 0';
78         } // END - if
79
80         // Run SQL string to check for accounts
81         $result_main = SQL_QUERY("SELECT
82         `userid`, `email`, `gender`, `surname`, `family`, (0" . $add . ") AS points
83 FROM
84         `{?_MYSQL_PREFIX?}_user_data`
85 " . $whereStatement1 . "
86 ORDER BY
87         `points` DESC,
88         `userid` ASC
89 LIMIT {?bonus_ranks?}", __FILE__, __LINE__);
90
91         // Some entries were found?
92         if (SQL_NUMROWS($result_main) > 0) {
93                 // Load our winners...
94                 while ($content = SQL_FETCHARRAY($result_main)) {
95                         // Make sure zero points are not mailed
96                         if ($content['points'] > 0) {
97                                 // Add points to user's account directly
98                                 addPointsDirectly('monthly_bonus', $content['userid'], $content['points']);
99
100                                 // Translate gender/points
101                                 $content['gender'] = translateGender($content['gender']);
102                                 $content['points'] = translateComma($content['points']);
103
104                                 // Load email template and email it away
105                                 $message = loadEmailTemplate('member_bonus', $content, bigintval($content['userid']));
106                                 sendEmail($content['email'], getMessage('BONUS_MONTHLY_ONLINE_BONUS'), $message);
107                         } // END - if
108                 } // END - while
109
110                 // Reset all accounts
111                 $result = SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data`
112 SET
113         `turbo_bonus`=0,
114         `login_bonus`=0,
115         `bonus_order`=0,
116         `bonus_stats`=0,
117         `bonus_ref`=0', __FILE__, __LINE__);
118         } // END - if
119
120         // Free memory
121         SQL_FREERESULT($result_main);
122 } // END - if
123
124 //
125 ?>