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