Rewritten all THEME_FOO variables to GLOBALS
[mailer.git] / inc / modules / chk_login.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/26/2003 *
4  * ===============                              Last change: 02/27/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : chk_login.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Check if user has logged in (delay)              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Pruefen ob die Login-Cookies gesetzt sind        *
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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // Initial message part
46 $message = "<strong>{--VALIDATING_LOGIN--}</strong>";
47
48 if (isUserIdSet() && (isSessionVariableSet('u_hash'))) {
49         // Login failures are supported since 0.4.7
50         // Do we have 0.4.7 of sql_patches or later?
51         $add = "";
52         if (GET_EXT_VERSION("sql_patches") >= "0.6.1") {
53                 // Load them here
54                 $add = ", login_failures, UNIX_TIMESTAMP(last_failure) AS last_failure";
55         } // END - if
56
57         // Get theme from profile
58         $result = SQL_QUERY_ESC("SELECT curr_theme".$add." FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
59                 array(getUserId()), __FILE__, __LINE__);
60
61         // Load data
62         $data = SQL_FETCHARRAY($result);
63
64         // Free result
65         SQL_FREERESULT($result);
66
67         // Change to new theme
68         set_session('mxchange_theme', $data['curr_theme']);
69
70         // Remmeber login failures if available
71         if (GET_EXT_VERSION("sql_patches") >= "0.6.1") {
72                 // Reset login failures
73                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
74 SET login_failures=0, last_failure='0000-00-00 00:00:00'
75 WHERE userid=%s
76 LIMIT 1",
77                         array(getUserId()), __FILE__, __LINE__);
78
79                 // Store it in session
80                 set_session('mxchange_member_failures', $data['login_failures']);
81                 set_session('mxchange_member_last_fail', $data['last_failure']);
82         } // END - if
83
84         // Bonus is not given by default ;-)
85         $bonus = false;
86         if ((GET_EXT_VERSION("sql_patches") >= "0.2.8") && (GET_EXT_VERSION("bonus") >= "0.2.1") && (getConfig('bonus_login_yn') == "Y")) {
87                 // Update last login if far enougth away
88                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
89 SET last_login=UNIX_TIMESTAMP()
90 WHERE userid=%s AND last_login < (UNIX_TIMESTAMP() - %s)
91 LIMIT 1",
92                         array(
93                                 getUserId(),
94                                 getConfig('login_timeout')
95                         ), __FILE__, __LINE__
96                 );
97                 if (SQL_AFFECTEDROWS() == 1) $bonus = true;
98         } // END - if
99
100         if (($bonus) && (REQUEST_GET('mode') == "bonus") && (EXT_IS_ACTIVE("bonus"))) {
101                 // Output message with added points
102                 $message .= "<div class=\"tiny\">
103   ".sprintf(getMessage('BONUS_LOGIN_BONUS_ADDED'), TRANSLATE_COMMA(getConfig('login_bonus')))."
104 </div>";
105         } elseif (EXT_IS_ACTIVE("bonus")) {
106                 // No login bonus added!
107                 $message .= "<div class=\"member_failed\">{--BONUS_LOGIN_BONUS_NOT_ADDED--}</div>";
108         }
109
110         // Redirect to member area
111         $message .= LOAD_TEMPLATE("member_login_js", true);
112 } else {
113         // Login failed!
114         $message .= LOAD_TEMPLATE("login_failed_js", true);
115 }
116
117 // Output final message
118 LOAD_TEMPLATE("admin_settings_saved", false, $message);
119
120 //
121 ?>