Favicon improvements (ApMuthu).
[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         }
33
34         if (check_faillog())
35         {
36                 $blocked_msg = '<span class=redfg>'._('Too many failed login attempts.<br>Please wait a while or try later.').'</span>';
37
38             $js .= "<script>setTimeout(function() {
39                 document.getElementsByName('SubmitUser')[0].disabled=0;
40                 document.getElementById('log_msg').innerHTML='$demo_text'}, 1000*$login_delay);</script>";
41             $demo_text = $blocked_msg;
42         }
43         if (!isset($def_coy))
44                 $def_coy = 0;
45         $def_theme = "default";
46
47         $login_timeout = $_SESSION["wa_current_user"]->last_act;
48
49         $title = $login_timeout ? _('Authorization timeout') : $app_title." ".$version." - "._("Login");
50         $encoding = isset($_SESSION['language']->encoding) ? $_SESSION['language']->encoding : "iso-8859-1";
51         $rtl = isset($_SESSION['language']->dir) ? $_SESSION['language']->dir : "ltr";
52         $onload = !$login_timeout ? "onload='defaultCompany()'" : "";
53
54         echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
55         echo "<html dir='$rtl' >\n";
56         echo "<head profile=\"http://www.w3.org/2005/10/profile\"><title>$title</title>\n";
57         echo "<meta http-equiv='Content-type' content='text/html; charset=$encoding' />\n";
58         echo "<link href='$path_to_root/themes/$def_theme/default.css' rel='stylesheet' type='text/css'> \n";
59         echo "<link href='$path_to_root/themes/default/images/favicon.ico' rel='icon' type='image/x-icon'> \n";
60         send_scripts();
61         if (!$login_timeout)
62         {
63                 echo $js;
64         }
65         echo "</head>\n";
66
67         echo "<body id='loginscreen' $onload>\n";
68
69         echo "<table class='titletext'><tr><td>$title</td></tr></table>\n";
70         
71         div_start('_page_body');
72         br();br();
73         start_form(false, false, $_SESSION['timeout']['uri'], "loginform");
74         start_table(false, "class='login'");
75         start_row();
76         echo "<td align='center' colspan=2>";
77         if (!$login_timeout) { // FA logo
78         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>";
79         } else { 
80                 echo "<font size=5>"._('Authorization timeout')."</font>";
81         } 
82         echo "</td>\n";
83         end_row();
84
85         echo "<input type='hidden' id=ui_mode name='ui_mode' value='".$_SESSION["wa_current_user"]->ui_mode."' />\n";
86         if (!$login_timeout)
87                 table_section_title(_("Version")." $version   Build $build_version - "._("Login"));
88         $value = $login_timeout ? $_SESSION['wa_current_user']->loginname : ($allow_demo_mode ? "demouser":"");
89
90         text_row(_("User name"), "user_name_entry_field", $value, 20, 30);
91
92         $password = $allow_demo_mode ? "password":"";
93
94         password_row(_("Password:"), 'password', $password);
95
96         if ($login_timeout) {
97                 hidden('company_login_name', $_SESSION["wa_current_user"]->company);
98         } else {
99                 if (isset($_SESSION['wa_current_user']->company))
100                         $coy =  $_SESSION['wa_current_user']->company;
101                 else
102                         $coy = $def_coy;
103                 if (!@$text_company_selection) {
104                         echo "<tr><td>"._("Company")."</td><td><select name='company_login_name'>\n";
105                         for ($i = 0; $i < count($db_connections); $i++)
106                                 echo "<option value=$i ".($i==$coy ? 'selected':'') .">" . $db_connections[$i]["name"] . "</option>";
107                         echo "</select>\n";
108                         echo "</td></tr>";
109                 } else {
110 //                      $coy = $def_coy;
111                         text_row(_("Company"), "company_login_nickname", "", 20, 50);
112                 }
113                 start_row();
114                 label_cell($demo_text, "colspan=2 align='center' id='log_msg'");
115                 end_row();
116         }; 
117         end_table(1);
118         echo "<center><input type='submit' value='&nbsp;&nbsp;"._("Login -->")."&nbsp;&nbsp;' name='SubmitUser'"
119                 .($login_timeout ? '':" onclick='set_fullmode();'").(isset($blocked_msg) ? " disabled" : '')." /></center>\n";
120
121         foreach($_SESSION['timeout']['post'] as $p => $val) {
122                 // add all request variables to be resend together with login data
123                 if (!in_array($p, array('ui_mode', 'user_name_entry_field', 
124                         'password', 'SubmitUser', 'company_login_name'))) 
125                         echo "<input type='hidden' name='$p' value='$val'>";
126         }
127         end_form(1);
128         $Ajax->addScript(true, "document.forms[0].password.focus();");
129
130     echo "<script language='JavaScript' type='text/javascript'>
131     //<![CDATA[
132             <!--
133             document.forms[0].user_name_entry_field.select();
134             document.forms[0].user_name_entry_field.focus();
135             //-->
136     //]]>
137     </script>";
138     div_end();
139         echo "<table class='bottomBar'>\n";
140         echo "<tr>";
141         if (isset($_SESSION['wa_current_user'])) 
142                 $date = Today() . " | " . Now();
143         else    
144                 $date = date("m/d/Y") . " | " . date("h.i am");
145         echo "<td class='bottomBarCell'>$date</td>\n";
146         echo "</tr></table>\n";
147         echo "<table class='footer'>\n";
148         echo "<tr>\n";
149         echo "<td><a target='_blank' href='$power_url' tabindex='-1'>$app_title $version - " . _("Theme:") . " " . $def_theme . "</a></td>\n";
150         echo "</tr>\n";
151         echo "<tr>\n";
152         echo "<td><a target='_blank' href='$power_url' tabindex='-1'>$power_by</a></td>\n";
153         echo "</tr>\n";
154         echo "</table><br><br>\n";
155         echo "</body></html>\n";
156
157 ?>