Added update_year.sh (still not fully flexible) and updated all years with it.
[mailer.git] / inc / filter / bonus_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/02/2011 *
4  * ===================                          Last change: 06/02/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : _filter.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-                                 *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Filter for adding login bonus to the user's account
44 function FILTER_ADD_LOGIN_BONUS ($filterData) {
45         // Is the user data valid?
46         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
47         if (!isMember()) {
48                 // Do only run for logged in members
49                 reportBug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
50         } // END - if
51
52         // Bonus is not given by default ;-)
53         $bonus = FALSE;
54         if ((isExtensionInstalledAndNewer('sql_patches', '0.2.8')) && (isBonusRallyeActive()) && (isIncludeBonusLoginEnabled())) {
55                 // Update last login if far enougth away
56                 // @TODO This query isn't right, it will only update if the user was for a longer time away!
57                 sqlQueryEscaped('UPDATE
58         `{?_MYSQL_PREFIX?}_user_data`
59 SET
60         `last_login`=UNIX_TIMESTAMP()
61 WHERE
62         `userid`=%s AND
63          (UNIX_TIMESTAMP() - `last_login`) >= {?login_timeout?}
64 LIMIT 1',
65                         array(
66                                 getMemberId()
67                         ), __FUNCTION__, __LINE__
68                 );
69
70                 // Updated entry?
71                 $bonus = (!ifSqlHasZeroAffectedRows());
72         } // END - if
73
74         if (($bonus === TRUE) && (getRequestElement('do') == 'bonus')) {
75                 // Output message with added points
76                 $GLOBALS['message'] .= '<div class="tiny">{--MEMBER_BONUS_LOGIN_BONUS_ADDED--}</div>';
77         } else {
78                 // No login bonus added!
79                 $GLOBALS['message'] .= '<div class="notice">{--MEMBER_BONUS_LOGIN_BONUS_NOT_ADDED--}</div>';
80         }
81
82         // Return data
83         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
84         return $filterData;
85 }
86
87 // Filter for generating admin mail links for bonus mails
88 function FILTER_GENERATE_BONUS_MAIL_LINKS ($filterData) {
89         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
90
91         // Is the type 'bonus'?
92         if ($filterData['type'] == 'bonus') {
93                 // Load template
94                 $filterData['__output'] .= loadTemplate('admin_links_bonus_mail', TRUE, $filterData);
95         } // END - if
96
97         // Return data
98         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
99         return $filterData;
100 }
101
102 // Filter for adding bonus columns with a plus (+) sign
103 function FILTER_ADD_BONUS_POINTS_USER_COLUMNS ($add = '') {
104         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
105
106         // Skip out-dated extension, because this causes an error
107         if (isExtensionInstalledAndOlder('bonus', '0.9.7')) {
108                 // Skip this silently
109                 return $add;
110         } // END - if
111
112         // Add more columns only when the corresponding configuration is enabled, too
113         if (isIncludeBonusClickEnabled()) $add .= ' + `turbo_bonus`';
114         if (isIncludeBonusLoginEnabled()) $add .= ' + `login_bonus`';
115         if (isIncludeBonusOrderEnabled()) $add .= ' + `bonus_order`';
116         if (isIncludeBonusRefEnabled()  ) $add .= ' + `bonus_ref`';
117         if (isIncludeBonusStatsEnabled()) $add .= ' + `bonus_stats`';
118
119         // Return $add
120         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
121         return $add;
122 }
123
124 // Filter for adding SQL columns on user registration for bonus/"active" rallye notification
125 function FILTER_BONUS_USER_REGISTRATION_ADD_SQL_COLUMNS ($filterData) {
126         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
127
128         // Next: active rallye
129         if (!isBonusNewMemberNotifyEnabled()) {
130                 addExtraRegistrationColumns(', `bonus_rallye_enable_notify`, `bonus_rallye_disable_notify`');
131                 $GLOBALS['register_sql_data']    .= ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()';
132         } // END - if
133
134         // Return filter data
135         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
136         //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,TRUE).'</pre>';
137         return $filterData;
138 }
139
140 // Filter for sending out bonus rallye notifications
141 function FILTER_SEND_BONUS_NOTIFICATIONS ($filterData) {
142         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
143         // Check for bonus rallye is active and send mails out
144         if ((isBonusRallyeActive()) && (isBonusNewMemberNotifyEnabled())) {
145                 // Include file for sending out mails
146                 addIncludeToPool('notify', 'inc/mails/bonus_mails.php');
147         } // END - if
148
149         // Return filter data
150         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
151         //* NOISY-DEBUG: */ print __FUNCTION__.':filterData=<pre>'.print_r($filterData,TRUE).'</pre>';
152         return $filterData;
153 }
154
155 // Filter to add exclusion SQL for configured userid
156 function FILTER_EXLCUDE_BONUS_USERID ($filterData = array()) {
157         // Is it valid?
158         if (isValidId(getBonusUserid())) {
159                 // Exclude it
160                 array_push($filterData, '{?bonus_userid?}');
161         } // END - if
162
163         // Return it
164         return $filterData;
165 }
166
167 // [EOF]
168 ?>