Extension ext-earning introduced (unfinished), renamings:
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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                 debug_report_bug(__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()) && (getConfig('include_bonus_login') == 'Y')) {
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                 SQL_QUERY_ESC('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 = (!SQL_HASZEROAFFECTED());
72         } // END - if
73
74         if (($bonus === true) && (getRequestElement('mode') == '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         // Is the type 'bid'?
90         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
91         if ($filterData['type'] == 'bid') {
92                 // Load template
93                 $filterData['__output'] .= loadTemplate('admin_links_bonus_mail', true, $filterData);
94         } // END - if
95
96         // Return data
97         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
98         return $filterData;
99 }
100
101 // Filter for adding bonus columns with a plus (+) sign
102 function FILTER_ADD_BONUS_POINTS_USER_COLUMNS ($add = '') {
103         // Skip out-dated extension, because this causes an error
104         if (isExtensionInstalledAndOlder('bonus', '0.9.7')) {
105                 // Skip this silently
106                 return $add;
107         } // END - if
108
109         // Add more columns only when the corresponding configuration is enabled, too
110         if (getConfig('include_bonus_click') == 'Y') $add .= ' + `turbo_bonus`';
111         if (getConfig('include_bonus_login') == 'Y') $add .= ' + `login_bonus`';
112         if (getConfig('include_bonus_order') == 'Y') $add .= ' + `bonus_order`';
113         if (getConfig('include_bonus_stats') == 'Y') $add .= ' + `bonus_stats`';
114         if (getConfig('include_bonus_ref')   == 'Y') $add .= ' + `bonus_ref`';
115
116         // Return $add
117         return $add;
118 }
119
120 // [EOF]
121 ?>