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