Altes CSS menĂ¼ wg. Probleme mit Opera wiederhergestellt.
[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::Auth;
32 use SL::User;
33 use SL::Form;
34
35 require "bin/mozilla/common.pl";
36 require "bin/mozilla/todo.pl";
37
38 # This is required because the am.pl in the root directory
39 # is not scanned by locales.pl:
40 # $form->parse_html_template('login/password_error')
41
42 $form = new Form;
43
44 if (! -f 'config/authentication.pl') {
45   show_error('login/authentication_pl_missing');
46 }
47
48 $locale = new Locale $language, "login";
49
50 our $auth = SL::Auth->new();
51 if (!$auth->session_tables_present()) {
52   show_error('login/auth_db_unreachable');
53 }
54 $auth->expire_sessions();
55 my $session_result = $auth->restore_session();
56
57 # customization
58 if (-f "bin/mozilla/custom_$form->{script}") {
59   eval { require "bin/mozilla/custom_$form->{script}"; };
60   $form->error($@) if ($@);
61 }
62
63 # per login customization
64 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
65   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
66   $form->error($@) if ($@);
67 }
68
69 # window title bar, user info
70 $form->{titlebar} = "Lx-Office " . $locale->text('Version') . " $form->{version}";
71
72 if (SL::Auth::SESSION_EXPIRED == $session_result) {
73   $form->{error_message} = $locale->text('The session is invalid or has expired.');
74   login_screen();
75   exit;
76 }
77
78 my $action = $form->{action};
79
80 if (!$action && $auth->{SESSION}->{login}) {
81   $action = 'login';
82 }
83
84 if ($action) {
85   our %myconfig = $auth->read_user($form->{login}) if ($form->{login});
86
87   if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
88     $form->{error_message} = $locale->text('Incorrect Password!');
89     login_screen();
90     exit;
91   }
92
93   $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
94   $auth->create_or_refresh_session();
95
96   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
97   call_sub($locale->findsub($action));
98
99 } else {
100   login_screen();
101 }
102
103 1;
104
105 sub login_screen {
106   $lxdebug->enter_sub();
107   my ($msg) = @_;
108
109   if (-f "css/lx-office-erp.css") {
110     $form->{stylesheet} = "lx-office-erp.css";
111   }
112
113   $form->{msg} = $msg;
114   $form->header();
115
116   print $form->parse_html_template('login/login_screen');
117
118   $lxdebug->leave_sub();
119 }
120
121 sub login {
122   $lxdebug->enter_sub();
123
124   unless ($form->{login}) {
125     login_screen($locale->text('You did not enter a name!'));
126     exit;
127   }
128
129   $user = new User $form->{login};
130
131   # if we get an error back, bale out
132   if (($result = $user->login($form)) <= -1) {
133     exit if $result == -2;
134     login_screen($locale->text('Incorrect username or password!'));
135     exit;
136   }
137
138   my %style_to_script_map = ( 'v3'  => 'v3',
139                               'neu' => 'new',
140                               'v4' => 'v4',
141                               'xml' => 'XML',
142     );
143
144   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
145
146   # made it this far, execute the menu
147   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display');
148
149   $auth->set_cookie_environment_variable();
150
151   $form->redirect();
152
153   $lxdebug->leave_sub();
154 }
155
156 sub logout {
157   $lxdebug->enter_sub();
158
159   $auth->destroy_session();
160
161   # remove the callback to display the message
162   $form->{callback} = "login.pl?action=";
163   $form->redirect($locale->text('You are logged out!'));
164
165   $lxdebug->leave_sub();
166 }
167
168 sub company_logo {
169   $lxdebug->enter_sub();
170
171   $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
172
173   $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
174
175   $form->{stylesheet} =  $myconfig{stylesheet};
176   $form->{title}      =  $locale->text('About');
177
178   # create the logo screen
179   $form->header() unless $form->{noheader};
180
181   print $form->parse_html_template('login/company_logo');
182
183   $lxdebug->leave_sub();
184 }
185
186 sub show_error {
187   my $template           = shift;
188   $locale                = Locale->new($language, 'all');
189   $myconfig{countrycode} = $language;
190   $form->{stylesheet}    = 'css/lx-office-erp.css';
191
192   $form->header();
193   print $form->parse_html_template($template);
194
195   # $form->parse_html_template('login/auth_db_unreachable');
196   # $form->parse_html_template('login/authentication_pl_missing');
197
198   exit;
199 }
200