unstable-Zweig als Kopie des "alten" trunks erstellt.
[kivitendo-erp.git] / am.pl
1 #!/usr/bin/perl
2 #
3 ######################################################################
4 # SQL-Ledger Accounting
5 # Copyright (C) 2001
6 #
7 #  Author: Dieter Simader
8 #   Email: dsimader@sql-ledger.org
9 #     Web: http://www.sql-ledger.org
10 #
11 #  Contributors:
12 #
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #######################################################################
26 #
27 # this script is the frontend called from bin/$terminal/$script
28 # all the accounting modules are linked to this script which in
29 # turn execute the same script in bin/$terminal/
30 #
31 #######################################################################
32
33 # setup defaults, DO NOT CHANGE
34 $userspath = "users";
35 $templates = "templates";
36 $memberfile = "users/members";
37 $sendmail = "| /usr/sbin/sendmail -t";
38 ########## end ###########################################
39
40
41 $| = 1;
42
43 use SL::LXDebug;
44 $lxdebug = LXDebug->new();
45
46 use SL::Form;
47
48 eval { require "lx-erp.conf"; };
49
50
51 $form = new Form;
52
53 # name of this script
54 $0 =~ tr/\\/\//;
55 $pos = rindex $0, '/';
56 $script = substr($0, $pos + 1);
57
58 # we use $script for the language module
59 $form->{script} = $script;
60 # strip .pl for translation files
61 $script =~ s/\.pl//;
62
63 # pull in DBI
64 use DBI;
65
66 # check for user config file, could be missing or ???
67 eval { require("$userspath/$form->{login}.conf"); };
68 if ($@) {
69   $locale = new Locale "$language", "$script";
70   
71   $form->{callback} = "";
72   $msg1 = $locale->text('You are logged out!');
73   $msg2 = $locale->text('Login');
74   $form->redirect("$msg1 <p><a href=login.pl target=_top>$msg2</a>");
75 }
76
77
78 $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
79 map { $form->{$_} = $myconfig{$_} } qw(stylesheet charset) unless (($form->{action} eq 'save') && ($form->{type} eq 'preferences'));
80
81 # locale messages
82 $locale = new Locale "$myconfig{countrycode}", "$script";
83
84 # check password
85 $form->error($locale->text('Incorrect Password!')) if ($form->{password} ne $myconfig{password});
86  
87
88 $form->{path} =~ s/\.\.\///g;
89 if ($form->{path} !~ /^bin\//) {
90   $form->error($locale->text('Invalid path!')."\n");
91 }
92
93 # did sysadmin lock us out
94 if (-e "$userspath/nologin") {
95   $form->error($locale->text('System currently down for maintenance!'));
96 }
97
98
99 # pull in the main code
100 require "$form->{path}/$form->{script}";
101
102 # customized scripts
103 if (-f "$form->{path}/custom_$form->{script}") {
104   eval { require "$form->{path}/custom_$form->{script}"; };
105   $form->error($@) if ($@);
106 }
107
108 # customized scripts for login
109 if (-f "$form->{path}/$form->{login}_$form->{script}") {
110   eval { require "$form->{path}/$form->{login}_$form->{script}"; };
111   $form->error($@) if ($@);
112 }
113
114 if ($form->{action}) {
115   # window title bar, user info
116   $form->{titlebar} = "Lx-Office ".$locale->text('Version'). " $form->{version} - $myconfig{name} - $myconfig{dbname}";
117
118   &{ $locale->findsub($form->{action}) };
119 } else {
120   $form->error($locale->text('action= not defined!'));
121 }
122
123
124 # end
125