45294376db2c38bfc262a99fac70dd554ab62cf2
[fa-stable.git] / access / login.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12         if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
13                 die(_("Restricted access"));
14         include_once($path_to_root . "/includes/ui.inc");
15         include_once($path_to_root . "/includes/page/header.inc");
16
17         $js = "<script language='JavaScript' type='text/javascript'>
18 function defaultCompany()
19 {
20         document.forms[0].company_login_name.options[".$_SESSION["wa_current_user"]->company."].selected = true;
21 }
22 </script>";
23         add_js_file('login.js');
24         // Display demo user name and password within login form if "$allow_demo_mode" is true
25         if ($allow_demo_mode == true)
26         {
27             $demo_text = _("Login as user: demouser and password: password");
28         }
29         else
30         {
31                 $demo_text = _("Please login here");
32     if (@$allow_password_reset) {
33       $demo_text .= " "._("or")." <a href='$path_to_root/index.php?reset=1'>"._("request new password")."</a>";
34     }
35         }
36
37         if (check_faillog())
38         {
39                 $blocked_msg = '<span class=redfg>'._('Too many failed login attempts.<br>Please wait a while or try later.').'</span>';
40
41             $js .= "<script>setTimeout(function() {
42                 document.getElementsByName('SubmitUser')[0].disabled=0;
43                 document.getElementById('log_msg').innerHTML='$demo_text'}, 1000*$login_delay);</script>";
44             $demo_text = $blocked_msg;
45         }
46         if (!isset($def_coy))
47                 $def_coy = 0;
48         $def_theme = "default";
49
50         $login_timeout = $_SESSION["wa_current_user"]->last_act;
51
52         $title = $login_timeout ? _('Authorization timeout') : $app_title." ".$version." - "._("Login");
53         $encoding = isset($_SESSION['language']->encoding) ? $_SESSION['language']->encoding : "iso-8859-1";
54         $rtl = isset($_SESSION['language']->dir) ? $_SESSION['language']->dir : "ltr";
55         $onload = !$login_timeout ? "onload='defaultCompany()'" : "";
56
57         echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
58         echo "<html dir='$rtl' >\n";
59         echo "<head profile=\"http://www.w3.org/2005/10/profile\"><title>$title</title>\n";
60         echo "<meta http-equiv='Content-type' content='text/html; charset=$encoding' />\n";
61         echo "<link href='$path_to_root/themes/$def_theme/default.css' rel='stylesheet' type='text/css'> \n";
62         echo "<link href='$path_to_root/themes/default/images/favicon.ico' rel='icon' type='image/x-icon'> \n";
63         send_scripts();
64         if (!$login_timeout)
65         {
66                 echo $js;
67         }
68         echo "</head>\n";
69
70         echo "<body id='loginscreen' $onload>\n";
71
72         echo "<table class='titletext'><tr><td>$title</td></tr></table>\n";
73         
74         div_start('_page_body');
75         br();br();
76         start_form(false, false, $_SESSION['timeout']['uri'], "loginform");
77         start_table(false, "class='login'");
78         start_row();
79         echo "<td align='center' colspan=2>";
80         if (!$login_timeout) { // FA logo
81         echo "<a target='_blank' href='$power_url'><img src='$path_to_root/themes/$def_theme/images/logo_frontaccounting.png' alt='FrontAccounting' height='50' onload='fixPNG(this)' border='0' /></a>";
82         } else { 
83                 echo "<font size=5>"._('Authorization timeout')."</font>";
84         } 
85         echo "</td>\n";
86         end_row();
87
88         echo "<input type='hidden' id=ui_mode name='ui_mode' value='".$_SESSION["wa_current_user"]->ui_mode."' />\n";
89         if (!$login_timeout)
90                 table_section_title(_("Version")." $version   Build $build_version - "._("Login"));
91         $value = $login_timeout ? $_SESSION['wa_current_user']->loginname : ($allow_demo_mode ? "demouser":"");
92
93         text_row(_("User name"), "user_name_entry_field", $value, 20, 30);
94
95         $password = $allow_demo_mode ? "password":"";
96
97         password_row(_("Password:"), 'password', $password);
98
99         if ($login_timeout) {
100                 hidden('company_login_name', $_SESSION["wa_current_user"]->company);
101         } else {
102                 if (isset($_SESSION['wa_current_user']->company))
103                         $coy =  $_SESSION['wa_current_user']->company;
104                 else
105                         $coy = $def_coy;
106                 if (!@$text_company_selection) {
107                         echo "<tr><td>"._("Company")."</td><td><select name='company_login_name'>\n";
108                         for ($i = 0; $i < count($db_connections); $i++)
109                                 echo "<option value=$i ".($i==$coy ? 'selected':'') .">" . $db_connections[$i]["name"] . "</option>";
110                         echo "</select>\n";
111                         echo "</td></tr>";
112                 } else {
113 //                      $coy = $def_coy;
114                         text_row(_("Company"), "company_login_nickname", "", 20, 50);
115                 }
116                 start_row();
117                 label_cell($demo_text, "colspan=2 align='center' id='log_msg'");
118                 end_row();
119         }; 
120         end_table(1);
121         echo "<center><input type='submit' value='&nbsp;&nbsp;"._("Login -->")."&nbsp;&nbsp;' name='SubmitUser'"
122                 .($login_timeout ? '':" onclick='set_fullmode();'").(isset($blocked_msg) ? " disabled" : '')." /></center>\n";
123
124         foreach($_SESSION['timeout']['post'] as $p => $val) {
125                 // add all request variables to be resend together with login data
126                 if (!in_array($p, array('ui_mode', 'user_name_entry_field', 
127                         'password', 'SubmitUser', 'company_login_name'))) 
128                         if (!is_array($val))
129                                 echo "<input type='hidden' name='$p' value='$val'>";
130                         else
131                                 foreach($val as $i => $v)
132                                         echo "<input type='hidden' name='{$p}[$i]' value='$v'>";
133         }
134         end_form(1);
135         $Ajax->addScript(true, "document.forms[0].password.focus();");
136
137     echo "<script language='JavaScript' type='text/javascript'>
138     //<![CDATA[
139             <!--
140             document.forms[0].user_name_entry_field.select();
141             document.forms[0].user_name_entry_field.focus();
142             //-->
143     //]]>
144     </script>";
145     div_end();
146         echo "<table class='bottomBar'>\n";
147         echo "<tr>";
148         if (isset($_SESSION['wa_current_user'])) 
149                 $date = Today() . " | " . Now();
150         else    
151                 $date = date("m/d/Y") . " | " . date("h.i am");
152         echo "<td class='bottomBarCell'>$date</td>\n";
153         echo "</tr></table>\n";
154         echo "<table class='footer'>\n";
155         echo "<tr>\n";
156         echo "<td><a target='_blank' href='$power_url' tabindex='-1'>$app_title $version - " . _("Theme:") . " " . $def_theme . "</a></td>\n";
157         echo "</tr>\n";
158         echo "<tr>\n";
159         echo "<td><a target='_blank' href='$power_url' tabindex='-1'>$power_by</a></td>\n";
160         echo "</tr>\n";
161         echo "</table><br><br>\n";
162         echo "</body></html>\n";
163
164 ?>