Changed login.php and logout.php to be neutral and tried to use our own api.
[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         this.form.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         if (!$login_timeout)
56         {
57                 echo $js2;
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     start_row();
79         if (!$login_timeout) { // FA version info
80                 echo "<td align='center' ><font size=2><b>"._("Version")." $version   Build $build_version</b></font></td>\n";
81         }; // end of FA version info
82         end_row();
83         br();
84         start_form(false, false, $_SESSION['timeout']['uri'], "loginform");
85         start_table("$table_style2 width=400 style='background-color:#eeeeee;'");
86         echo "<input type='hidden' id=ui_mode name='ui_mode' value='".$_SESSION["wa_current_user"]->ui_mode."' />\n";
87
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         echo "<tr><td>"._("Password")."</td><td><input type='password' name='password'  value='$password' /></td></tr>\n";
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                 echo "<tr><td>"._("Company")."</td><td><select name='company_login_name'>\n";
104                 for ($i = 0; $i < count($db_connections); $i++)
105                         echo "<option value=$i ".($i==$coy ? 'selected':'') .">" . $db_connections[$i]["name"] . "</option>";
106                 echo "</select>\n";
107                 start_row();
108                 label_cell($demo_text, "colspan=2 align='center'");
109                 end_row();
110         }; 
111         end_table(1);
112         echo "<center><input type='submit' value='"._("Login -->")."' name='SubmitUser' onclick='set_fullmode();' /></center>\n";
113         end_form(1);
114
115         foreach($_SESSION['timeout']['post'] as $p => $val) {
116                 // add all request variables to be resend together with login data
117                 if (!in_array($p, array('ui_mode', 'user_name_entry_field', 
118                         'password', 'SubmitUser', 'company_login_name'))) 
119                         echo "<input type='hidden' name='$p' value='$val'>";
120         }
121         end_table();
122     echo "<script language='JavaScript' type='text/javascript'>
123     //<![CDATA[
124             <!--
125             document.forms[0].user_name_entry_field.select();
126             document.forms[0].user_name_entry_field.focus();
127             //-->
128     //]]>
129     </script>";
130         echo "<table width=100%>\n";
131         echo "<tr>";
132         if (isset($_SESSION['wa_current_user'])) 
133                 $date = Today() . " | " . Now();
134         else    
135                 $date = date("m/d/Y") . " | " . date("h.i am");
136         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";
137         echo "</tr></table>\n";
138         echo "<table align='center' style='color:#cccccc;font-size:9px;margin-top:5px;'>\n";
139         echo "<tr>\n";
140         echo "<td align='center'><a target='_blank' href='$power_url' tabindex='-1'>$app_title $version - " . _("Theme:") . " " . $def_theme . "</a></td>\n";
141         echo "</tr>\n";
142         echo "<tr>\n";
143         echo "<td align='center'><a target='_blank' href='$power_url' tabindex='-1'>$power_by</a></td>\n";
144         echo "</tr>\n";
145         echo "</table><br><br>\n";
146         echo "</body></html>\n";
147
148 ?>