Cleaning from javascript errors.
[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 = isset($_SESSION["wa_current_user"]) ? user_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/default.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 style='background-color:#f9f9f9;' $onload>\n";
63
64         echo "<table id='title'><tr><td class='titletext'>$title</td></tr></table>\n";
65         
66         br();br();
67         start_table("$table_style2 width=400");
68         start_row();
69         echo "<td align='center' valign='bottom'>";
70         if (!$login_timeout) { // FA logo
71         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>";
72         } else { 
73                 echo "<font size=5>"._('Authorization timeout')."</font>";
74         } 
75         echo "</td>\n";
76         end_row();
77
78         br();
79         start_form(false, false, $_SESSION['timeout']['uri'], "loginform");
80         start_table("$table_style2 width=400 style='background-color:#eeeeee;'");
81         echo "<input type='hidden' id=ui_mode name='ui_mode' value='".$_SESSION["wa_current_user"]->ui_mode."' />\n";
82         if (!$login_timeout)
83                 table_section_title(_("Version")." $version   Build $build_version - "._("Login"));
84         $value = $login_timeout ? $_SESSION['wa_current_user']->loginname : ($allow_demo_mode ? "demouser":"");
85
86         text_row(_("User name"), "user_name_entry_field", $value, 20, 30);
87
88         $password = $allow_demo_mode ? "password":"";
89
90         echo "<tr><td>"._("Password")."</td><td><input type='password' name='password'  value='$password' /></td></tr>\n";
91
92         if ($login_timeout) {
93                 hidden('company_login_name', $_SESSION["wa_current_user"]->company);
94         } else {
95                 if (isset($_SESSION['wa_current_user']->company))
96                         $coy =  $_SESSION['wa_current_user']->company;
97                 else
98                         $coy = $def_coy;
99                 echo "<tr><td>"._("Company")."</td><td><select name='company_login_name'>\n";
100                 for ($i = 0; $i < count($db_connections); $i++)
101                         echo "<option value=$i ".($i==$coy ? 'selected':'') .">" . $db_connections[$i]["name"] . "</option>";
102                 echo "</select>\n";
103                 start_row();
104                 label_cell($demo_text, "colspan=2 align='center'");
105                 end_row();
106         }; 
107         end_table(1);
108         echo "<center><input type='submit' value='"._("Login -->")."' name='SubmitUser' onclick='set_fullmode();' /></center>\n";
109         end_form(1);
110
111         foreach($_SESSION['timeout']['post'] as $p => $val) {
112                 // add all request variables to be resend together with login data
113                 if (!in_array($p, array('ui_mode', 'user_name_entry_field', 
114                         'password', 'SubmitUser', 'company_login_name'))) 
115                         echo "<input type='hidden' name='$p' value='$val'>";
116         }
117         end_table();
118     echo "<script language='JavaScript' type='text/javascript'>
119     //<![CDATA[
120             <!--
121             document.forms[0].user_name_entry_field.select();
122             document.forms[0].user_name_entry_field.focus();
123             //-->
124     //]]>
125     </script>";
126         echo "<table width=100%>\n";
127         echo "<tr>";
128         if (isset($_SESSION['wa_current_user'])) 
129                 $date = Today() . " | " . Now();
130         else    
131                 $date = date("m/d/Y") . " | " . date("h.i am");
132         echo "<td style='font-family:Verdana,Arial,Helvetica;font-size:9px;background:#dee7ec;color:black;border-bottom:1px solid #8cacbb;width:100%;'>$date</td>\n";
133         echo "</tr></table>\n";
134         echo "<table align='center' style='margin-top:5px;'>\n";
135         echo "<tr>\n";
136         echo "<td align='center' ><a style='color:#666666;font-size:9px;' target='_blank' href='$power_url' tabindex='-1'>$app_title $version - " . _("Theme:") . " " . $def_theme . "</a></td>\n";
137         echo "</tr>\n";
138         echo "<tr>\n";
139         echo "<td align='center'><a style='color:#666666;font-size:9px;' target='_blank' href='$power_url' tabindex='-1'>$power_by</a></td>\n";
140         echo "</tr>\n";
141         echo "</table><br><br>\n";
142         echo "</body></html>\n";
143
144 ?>