b9a29c3ede341b61613a65238f94e7370c2e62e3
[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 require "bin/mozilla/common.pl";
35
36 $form = new Form;
37
38 $locale = new Locale $language, "login";
39
40 # customization
41 if (-f "bin/mozilla/custom_$form->{script}") {
42   eval { require "bin/mozilla/custom_$form->{script}"; };
43   $form->error($@) if ($@);
44 }
45
46 # per login customization
47 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
48   eval { require "bin/mozilla/$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   call_sub($locale->findsub($form->{action}));
58
59 } else {
60   login_screen();
61 }
62
63 1;
64
65 sub login_screen {
66   $lxdebug->enter_sub();
67
68   if (-f "css/lx-office-erp.css") {
69     $form->{stylesheet} = "lx-office-erp.css";
70   }
71
72   $form->{fokus} = "loginscreen.login";
73   $form->header;
74
75   print $form->parse_html_template('login/login_screen');
76
77   $lxdebug->leave_sub();
78 }
79
80 sub login {
81   $lxdebug->enter_sub();
82
83   $form->error($locale->text('You did not enter a name!')) unless ($form->{login});
84
85   $user = new User $memberfile, $form->{login};
86
87   # if we get an error back, bale out
88   if (($result = $user->login(\%$form, $userspath)) <= -1) {
89     if ($result == -2) {
90       exit;
91     }
92
93     $form->error($locale->text('Incorrect username or password!'));
94   }
95
96   my %style_to_script_map = ( 'v3'  => 'v3',
97                               'neu' => 'new',
98                               'xml' => 'XML',
99     );
100
101   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
102
103   # made it this far, execute the menu
104   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display');
105
106   $form->redirect();
107
108   $lxdebug->leave_sub();
109 }
110
111 sub logout {
112   $lxdebug->enter_sub();
113
114   unlink "$userspath/$form->{login}.conf";
115
116   # remove the callback to display the message
117   $form->{callback} = "login.pl?action=&login=";
118   $form->redirect($locale->text('You are logged out!'));
119
120   $lxdebug->leave_sub();
121 }
122
123 sub company_logo {
124   $lxdebug->enter_sub();
125
126   require "$userspath/$form->{login}.conf";
127
128   $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
129
130   $form->{stylesheet} =  $myconfig{stylesheet};
131   $form->{title}      =  $locale->text('About');
132
133   # create the logo screen
134   $form->header() unless $form->{noheader};
135
136   print $form->parse_html_template('login/company_logo');
137
138   $lxdebug->leave_sub();
139 }