More language constants rewritten ({--LANGUAGE--} is for constants)
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Initial message part
41 $MSG = "<strong>{--VALIDATING_LOGIN--}</strong>";
42
43 if (!empty($GLOBALS['userid']) && (isSessionVariableSet('u_hash'))) {
44         // Login failures are supported since 0.4.7
45         // Do we have 0.4.7 of sql_patches or later?
46         $ADD = "";
47         if (GET_EXT_VERSION("sql_patches") >= "0.6.1") {
48                 // Load them here
49                 $ADD = ", login_failures, UNIX_TIMESTAMP(last_failure) AS last_failure";
50         } // END - if
51
52         // Get theme from profile
53         $result = SQL_QUERY_ESC("SELECT curr_theme".$ADD." FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
54                 array($GLOBALS['userid']), __FILE__, __LINE__);
55
56         // Load data
57         $data = SQL_FETCHARRAY($result);
58
59         // Free result
60         SQL_FREERESULT($result);
61
62         // Change to new theme
63         set_session('mxchange_theme', $data['curr_theme']);
64
65         // Remmeber login failures if available
66         if (GET_EXT_VERSION("sql_patches") >= "0.6.1") {
67                 // Reset login failures
68                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
69 SET login_failures=0, last_failure='0000-00-00 00:00:00'
70 WHERE userid=%s
71 LIMIT 1",
72                         array($GLOBALS['userid']), __FILE__, __LINE__);
73
74                 // Store it in session
75                 set_session('mxchange_member_failures', $data['login_failures']);
76                 set_session('mxchange_member_last_fail', $data['last_failure']);
77         } // END - if
78
79         // Bonus is not given by default ;-)
80         $bonus = false;
81         if ((GET_EXT_VERSION("sql_patches") >= "0.2.8") && (GET_EXT_VERSION("bonus") >= "0.2.1") && (getConfig('bonus_login_yn') == "Y")) {
82                 // Update last login if far enougth away
83                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
84 SET last_login=UNIX_TIMESTAMP()
85 WHERE userid=%s AND last_login < (UNIX_TIMESTAMP() - %s)
86 LIMIT 1",
87                         array(
88                                 $GLOBALS['userid'],
89                                 getConfig('login_timeout')
90                         ), __FILE__, __LINE__
91                 );
92                 if (SQL_AFFECTEDROWS() == 1) $bonus = true;
93         } // END - if
94
95         if (($bonus) && ($_GET['mode'] == "bonus") && (EXT_IS_ACTIVE("bonus"))) {
96                 // Output message with added points
97                 $MSG .= "<div class=\"tiny\">
98   {--BONUS_LOGIN_BONUS_ADDED_1--}
99   <strong>".TRANSLATE_COMMA(getConfig('login_bonus'))." {!POINTS!}</strong>
100   {--BONUS_LOGIN_BONUS_ADDED_2--}
101 </div>";
102         } elseif (EXT_IS_ACTIVE("bonus")) {
103                 // No login bonus added!
104                 $MSG .= "<div class=\"member_failed\">{--BONUS_LOGIN_BONUS_NOT_ADDED--}</div>";
105         }
106
107         // Redirect to member area
108         $MSG .= LOAD_TEMPLATE("member_login_js", true);
109 } else {
110         // Login failed!
111         $MSG .= LOAD_TEMPLATE("login_failed_js", true);
112 }
113
114 // Output final message
115 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
116
117 //
118 ?>