New files from unstable 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/default.css' rel='stylesheet' type='text/css'> \n";
55         if (!$login_timeout)
56         {
57                 echo $js;
58         }       
59         echo $js2;
60         echo "</head>\n";
61
62         echo "<body id='loginscreen' $onload>\n";
63
64         echo "<table class='titletext'><tr><td>$title</td></tr></table>\n";
65         
66         div_start('_page_body');
67         br();br();
68         start_form(false, false, $_SESSION['timeout']['uri'], "loginform");
69         start_table(false, "class='login'");
70         start_row();
71         echo "<td align='center' colspan=2>";
72         if (!$login_timeout) { // FA logo
73         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>";
74         } else { 
75                 echo "<font size=5>"._('Authorization timeout')."</font>";
76         } 
77         echo "</td>\n";
78         end_row();
79
80         echo "<input type='hidden' id=ui_mode name='ui_mode' value='".$_SESSION["wa_current_user"]->ui_mode."' />\n";
81         if (!$login_timeout)
82                 table_section_title(_("Version")." $version   Build $build_version - "._("Login"));
83         $value = $login_timeout ? $_SESSION['wa_current_user']->loginname : ($allow_demo_mode ? "demouser":"");
84
85         text_row(_("User name"), "user_name_entry_field", $value, 20, 30);
86
87         $password = $allow_demo_mode ? "password":"";
88
89         password_row(_("Password:"), 'password', $password);
90
91                 if ($login_timeout) {
92                 hidden('company_login_name', $_SESSION["wa_current_user"]->company);
93         } else {
94                 if (isset($_SESSION['wa_current_user']->company))
95                         $coy =  $_SESSION['wa_current_user']->company;
96                 else
97                         $coy = $def_coy;
98                 echo "<tr><td>"._("Company")."</td><td><select name='company_login_name'>\n";
99                 for ($i = 0; $i < count($db_connections); $i++)
100                         echo "<option value=$i ".($i==$coy ? 'selected':'') .">" . $db_connections[$i]["name"] . "</option>";
101                 echo "</select>\n";
102                 start_row();
103                 label_cell($demo_text, "colspan=2 align='center'");
104                 end_row();
105         }; 
106         end_table(1);
107         echo "<center><input type='submit' value='&nbsp;&nbsp;"._("Login -->")."&nbsp;&nbsp;' name='SubmitUser'"
108                 .($login_timeout ? '':" onclick='set_fullmode();'")." /></center>\n";
109
110         foreach($_SESSION['timeout']['post'] as $p => $val) {
111                 // add all request variables to be resend together with login data
112                 if (!in_array($p, array('ui_mode', 'user_name_entry_field', 
113                         'password', 'SubmitUser', 'company_login_name'))) 
114                         echo "<input type='hidden' name='$p' value='$val'>";
115         }
116         end_form(1);
117     echo "<script language='JavaScript' type='text/javascript'>
118     //<![CDATA[
119             <!--
120             document.forms[0].user_name_entry_field.select();
121             document.forms[0].user_name_entry_field.focus();
122             //-->
123     //]]>
124     </script>";
125     div_end();
126         echo "<table class='bottomBar'>\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 class='bottomBarCell'>$date</td>\n";
133         echo "</tr></table>\n";
134         echo "<table class='footer'>\n";
135         echo "<tr>\n";
136         echo "<td><a 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><a 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 ?>