b72d994b6c20ec9b848e4533f72ad070ae96b80d
[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 () {
45         // Is the user data valid?
46         if (!isMember()) {
47                 // Do only run for logged in members
48                 debug_report_bug(__FUNCTION__, __LINE__, 'Please only run this filter for logged in users.');
49         } // END - if
50
51         // Bonus is not given by default ;-)
52         $bonus = false;
53         if ((isExtensionInstalledAndNewer('sql_patches', '0.2.8')) && (isBonusRallyeActive()) && (getConfig('bonus_login_yn') == 'Y')) {
54                 // Update last login if far enougth away
55                 // @TODO This query isn't right, it will only update if the user was for a longer time away!
56                 SQL_QUERY_ESC('UPDATE
57         `{?_MYSQL_PREFIX?}_user_data`
58 SET
59         `last_login`=UNIX_TIMESTAMP()
60 WHERE
61         `userid`=%s AND
62         `last_login` < (UNIX_TIMESTAMP() - {?login_timeout?})
63 LIMIT 1',
64                         array(
65                                 getMemberId()
66                         ), __FUNCTION__, __LINE__
67                 );
68
69                 // Updated entry?
70                 $bonus = (!SQL_HASZEROAFFECTED());
71         } // END - if
72
73         if (($bonus === true) && (getRequestParameter('mode') == 'bonus')) {
74                 // Output message with added points
75                 $GLOBALS['message'] .= '<div class="tiny">{--MEMBER_BONUS_LOGIN_BONUS_ADDED--}</div>';
76         } elseif (isExtensionActive('bonus')) {
77                 // No login bonus added!
78                 $GLOBALS['message'] .= '<div class="notice">{--MEMBER_BONUS_LOGIN_BONUS_NOT_ADDED--}</div>';
79         }
80 }
81
82 // [EOF]
83 ?>