Whitespace an den Zeilenenden entfernt.
[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 use DBI;
31 use SL::User;
32 use SL::Form;
33
34 $form = new Form;
35
36 $locale = new Locale $language, "login";
37
38 # customization
39 if (-f "$form->{path}/custom_$form->{script}") {
40   eval { require "$form->{path}/custom_$form->{script}"; };
41   $form->error($@) if ($@);
42 }
43
44 # per login customization
45 if (-f "$form->{path}/$form->{login}_$form->{script}") {
46   eval { require "$form->{path}/$form->{login}_$form->{script}"; };
47   $form->error($@) if ($@);
48 }
49
50 # window title bar, user info
51 $form->{titlebar} =
52   "Lx-Office " . $locale->text('Version') . " $form->{version}";
53
54 if ($form->{action}) {
55   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
56   &{ $locale->findsub($form->{action}) };
57 } else {
58   &login_screen;
59 }
60
61 1;
62
63 sub login_screen {
64   $lxdebug->enter_sub();
65
66   if (-f "css/lx-office-erp.css") {
67     $form->{stylesheet} = "lx-office-erp.css";
68   }
69
70   $form->{fokus} = "loginscreen.login";
71   $form->header;
72
73   print qq|
74
75
76 <body class=login onLoad="fokus()">
77
78 <pre>
79
80 </pre>
81
82 <center>
83 <table class=login border=3 cellpadding=20>
84   <tr>
85     <td class=login align=center><a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
86 <h1 class=login align=center>|
87     . $locale->text('Version')
88     . qq| $form->{version}
89 </h1>
90
91 <p>
92
93 <form method=post name=loginscreen action=$form->{script}>
94
95       <table width=100%>
96         <tr>
97           <td align=center>
98             <table>
99               <tr>
100                 <th align=right>| . $locale->text('Login Name') . qq|</th>
101                 <td><input class=login name=login size=30 tabindex="1"></td>
102               </tr>
103               <tr>
104                 <th align=right>| . $locale->text('Password') . qq|</th>
105                 <td><input class=login type=password name=password size=30 tabindex="2"></td>
106               </tr>
107               <input type=hidden name=path value=$form->{path}>
108             </table>
109
110             <br>
111             <input type=submit name=action value="| . $locale->text('Login') . qq|">
112
113           </td>
114         </tr>
115       </table>
116
117 </form>
118
119     </td>
120   </tr>
121 </table>
122
123 </body>
124 </html>
125 |;
126
127   $lxdebug->leave_sub();
128 }
129
130 sub login {
131   $lxdebug->enter_sub();
132
133   $form->error($locale->text('You did not enter a name!'))
134     unless ($form->{login});
135
136   $user = new User $memberfile, $form->{login};
137
138   # if we get an error back, bale out
139   if (($errno = $user->login(\%$form, $userspath)) <= -1) {
140     $errno *= -1;
141     $err[1] = $err[3] = $locale->text('Incorrect username or password!');
142
143     if ($errno == 2) {
144
145       # upgraded dataset, login again
146       $form->redirect(
147         "<a href=menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display>Continue</a>"
148       );
149       exit;
150     }
151
152     $form->error($err[$errno]);
153   }
154
155   # made it this far, execute the menu
156   $form->{callback} =
157     "menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
158
159   $form->redirect;
160
161   $lxdebug->leave_sub();
162 }
163
164 sub logout {
165   $lxdebug->enter_sub();
166
167   unlink "$userspath/$form->{login}.conf";
168
169   # remove the callback to display the message
170   $form->{callback} = "login.pl?path=$form->{path}&action=&login=";
171   $form->redirect($locale->text('You are logged out!'));
172
173   $lxdebug->leave_sub();
174 }
175
176 sub company_logo {
177   $lxdebug->enter_sub();
178
179   require "$userspath/$form->{login}.conf";
180   $locale = new Locale $myconfig{countrycode}, "login"
181     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   # create the logo screen
191   $form->header unless $form->{noheader};
192
193   print qq|
194 <body>
195 <center>
196 <a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
197 <h2 class=login>| . $locale->text('Version') . qq| $form->{version}</h2>
198
199 | . $locale->text('Licensed to') . qq|
200 <p>
201 <b>
202 $myconfig{company}
203 <br>$myconfig{address}
204 </b>
205
206
207 <br>
208 <table border=0>
209   <tr>
210     <th align=left>| . $locale->text('User') . qq|</th>
211     <td>$myconfig{name}</td>
212   </tr>
213   <tr>
214     <th align=left>| . $locale->text('Dataset') . qq|</th>
215     <td>$myconfig{dbname}</td>
216   </tr>
217   <tr>
218     <th align=left>| . $locale->text('Database Host') . qq|</th>
219     <td>$myconfig{dbhost}</td>
220   </tr>
221   <tr>
222   </tr>
223   <tr>
224   </tr>
225   <tr>
226     <th colspan="2" align="center"><a href="http://lx-office.org" target="blank">http://lx-office.org</a></th>
227   </tr>
228   <tr>
229     <th colspan="2" align="center"><a href="mailto:info&#064;lx-office.org" target="blank">info&#064;lx-office.org</a></th>
230   </tr>
231 </table>
232
233 </center>
234
235 </body>
236 </html>
237 |;
238
239   $lxdebug->leave_sub();
240 }