88f9d5281a1d808e79fc07786b712a236e439123
[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 // @TODO Replace with own template!
41 OPEN_TABLE("500", "guest_login_header dashed", "center");
42 OUTPUT_HTML("<br /><strong>".VALIDATING_LOGIN."</strong><br />");
43
44 if (!empty($GLOBALS['userid']) && (isSessionVariableSet('u_hash')) && (isSessionVariableSet('lifetime'))) {
45         // Login failtures are supported since 0.4.7
46         // Do we have 0.4.7 of sql_patches or later?
47         $ADD = "";
48         if (GET_EXT_VERSION("sql_patches") >= "0.4.7") {
49                 // Load them here
50                 $ADD = ", login_failtures, UNIX_TIMESTAMP(last_failture) AS last_failture";
51         } // END - if
52
53         // Get theme from profile
54         $result = SQL_QUERY_ESC("SELECT curr_theme".$ADD." FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
55                 array($GLOBALS['userid']), __FILE__, __LINE__);
56
57         // Load data
58         $data = SQL_FETCHARRAY($result);
59
60         // Free result
61         SQL_FREERESULT($result);
62
63         // Change to new theme
64         set_session("mxchange_theme", $data['curr_theme']);
65
66         // Remmeber login failtures if available
67         if (GET_EXT_VERSION("sql_patches") >= "0.4.7") {
68                 // Reset login failtures
69                 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
70 SET login_failtures=0, last_failture='0000-00-00 00:00:00'
71 WHERE userid=%s
72 LIMIT 1",
73                         array($GLOBALS['userid']), __FILE__, __LINE__);
74
75                 // Store it in session
76                 set_session('mxchange_member_failtures', $data['login_failtures']);
77                 set_session('mxchange_member_last_fail', $data['last_failture']);
78         } // END - if
79
80         // Bonus is not given by default ;-)
81         $bonus = false;
82         if ((GET_EXT_VERSION("sql_patches") >= "0.2.8") && (GET_EXT_VERSION("bonus") >= "0.2.1") && (getConfig('bonus_login_yn') == "Y")) {
83                 // Update last login if far enougth away
84                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
85 SET last_login=UNIX_TIMESTAMP()
86 WHERE userid=%s AND last_login < (UNIX_TIMESTAMP() - %s)
87 LIMIT 1",
88                         array(
89                                 $GLOBALS['userid'],
90                                 getConfig('login_timeout')
91                         ), __FILE__, __LINE__
92                 );
93                 if (SQL_AFFECTEDROWS() == 1) $bonus = true;
94         } // END - if
95
96         if (($bonus) && ($_GET['mode'] == "bonus") && (EXT_IS_ACTIVE("bonus"))) {
97                 // Output message with added points
98                 OUTPUT_HTML("<font class=\"tiny\">
99   ".BONUS_LOGIN_BONUS_ADDED_1."
100   <strong>".TRANSLATE_COMMA(getConfig('login_bonus'))." ".POINTS."</strong>
101   ".BONUS_LOGIN_BONUS_ADDED_2."
102 </font>");
103         } elseif (EXT_IS_ACTIVE("bonus")) {
104                 // No login bonus added!
105                 OUTPUT_HTML("<font class=\"member_failed\">".BONUS_LOGIN_BONUS_NOT_ADDED."</font>");
106         }
107
108         // Redirect to member area
109         LOAD_TEMPLATE("member_login_js");
110 } else {
111         // Login failed!
112         LOAD_TEMPLATE("login_failed_js");
113 }
114
115 // Close table
116 CLOSE_TABLE();
117
118 //
119 ?>