unstable-Zweig als Kopie des "alten" trunks erstellt.
[kivitendo-erp.git] / bin / mozilla / login.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 ######################################################################
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #######################################################################
29
30
31 use DBI;
32 use SL::User;
33 use SL::Form;
34
35
36 $form = new Form;
37
38 $locale = new Locale $language, "login";
39
40 # customization
41 if (-f "$form->{path}/custom_$form->{script}") {
42   eval { require "$form->{path}/custom_$form->{script}"; };
43   $form->error($@) if ($@);
44 }
45
46 # per login customization
47 if (-f "$form->{path}/$form->{login}_$form->{script}") {
48   eval { require "$form->{path}/$form->{login}_$form->{script}"; };
49   $form->error($@) if ($@);
50 }
51
52 # window title bar, user info
53 $form->{titlebar} = "Lx-Office ".$locale->text('Version'). " $form->{version}";
54
55 if ($form->{action}) {
56   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
57   &{ $locale->findsub($form->{action}) };
58 } else {
59   &login_screen;
60 }
61
62
63 1;
64
65
66 sub login_screen {
67   $lxdebug->enter_sub();
68   
69   if (-f "css/lx-office-erp.css") {
70     $form->{stylesheet} = "lx-office-erp.css";
71   }
72   
73   $form->{fokus} = "loginscreen.login";
74   $form->header;
75
76   print qq|
77
78
79 <body class=login onLoad="fokus()">
80
81 <pre>
82
83 </pre>
84
85 <center>
86 <table class=login border=3 cellpadding=20>
87   <tr>
88     <td class=login align=center><a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
89 <h1 class=login align=center>|.$locale->text('Version').qq| $form->{version}
90 </h1>
91
92 <p>
93
94 <form method=post name=loginscreen action=$form->{script}>
95
96       <table width=100%>
97         <tr>
98           <td align=center>
99             <table>
100               <tr>
101                 <th align=right>|.$locale->text('Login Name').qq|</th>
102                 <td><input class=login name=login size=30 tabindex="1"></td>
103               </tr> 
104               <tr>
105                 <th align=right>|.$locale->text('Password').qq|</th>
106                 <td><input class=login type=password name=password size=30 tabindex="2"></td>
107               </tr>
108               <input type=hidden name=path value=$form->{path}>
109             </table>
110
111             <br>
112             <input type=submit name=action value="|.$locale->text('Login').qq|">
113
114           </td>
115         </tr>
116       </table>
117
118 </form>
119
120     </td>
121   </tr>
122 </table>
123   
124 </body>
125 </html>
126 |;
127
128   $lxdebug->leave_sub();
129 }
130
131
132 sub login {
133   $lxdebug->enter_sub();
134
135   $form->error($locale->text('You did not enter a name!')) unless ($form->{login});
136
137   $user = new User $memberfile, $form->{login};
138
139   # if we get an error back, bale out
140   if (($errno = $user->login(\%$form, $userspath)) <= -1) {
141     $errno *= -1;
142     $err[1] = $err[3] = $locale->text('Incorrect username or password!');
143     
144     if ($errno == 2) {
145       # upgraded dataset, login again
146       $form->redirect("<a href=menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display>Continue</a>");
147       exit;
148     }
149     
150     $form->error($err[$errno]);
151   }
152   
153   # made it this far, execute the menu
154   $form->{callback} = "menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
155
156   $form->redirect;
157   
158   $lxdebug->leave_sub();
159 }
160
161
162
163 sub logout {
164   $lxdebug->enter_sub();
165
166   unlink "$userspath/$form->{login}.conf";
167   
168   # remove the callback to display the message
169   $form->{callback} = "login.pl?path=$form->{path}&action=&login=";
170   $form->redirect($locale->text('You are logged out!'));
171
172   $lxdebug->leave_sub();
173 }
174
175
176     
177 sub company_logo {
178   $lxdebug->enter_sub();
179   
180   require "$userspath/$form->{login}.conf";
181   $locale = new Locale $myconfig{countrycode}, "login" unless ($language eq $myconfig{countrycode});
182
183   $myconfig{address} =~ s/\\n/<br>/g;
184   $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
185
186   map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet);
187   
188   $form->{title} = $locale->text('About');
189   
190  
191   # create the logo screen
192   $form->header unless $form->{noheader};
193
194   print qq|
195 <body>
196 <center>
197 <a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
198 <h2 class=login>|.$locale->text('Version').qq| $form->{version}</h2>
199
200 |.$locale->text('Licensed to').qq|
201 <p>
202 <b>
203 $myconfig{company}
204 <br>$myconfig{address}
205 </b>
206
207
208 <br>
209 <table border=0>
210   <tr>
211     <th align=left>|.$locale->text('User').qq|</th>
212     <td>$myconfig{name}</td>
213   </tr>
214   <tr>
215     <th align=left>|.$locale->text('Dataset').qq|</th>
216     <td>$myconfig{dbname}</td>
217   </tr>
218   <tr>
219     <th align=left>|.$locale->text('Database Host').qq|</th>
220     <td>$myconfig{dbhost}</td>
221   </tr>
222   <tr>
223   </tr>
224   <tr>
225   </tr>
226   <tr>
227     <th colspan="2" align="center"><a href="http://lx-office.org" target="blank">http://lx-office.org</a></th>
228   </tr>
229   <tr>
230     <th colspan="2" align="center"><a href="mailto:info&#064;lx-office.org" target="blank">info&#064;lx-office.org</a></th>
231   </tr>
232 </table>
233
234 </center>
235
236 </body>
237 </html>
238 |;
239
240   $lxdebug->leave_sub();
241 }
242
243
244