Projekt

Allgemein

Profil

Herunterladen (5,16 KB) Statistiken
| Zweig: | Markierung: | Revision:
d319704a Moritz Bunkus
#=====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
# Web http://www.lx-office.org
#
######################################################################
# SQL-Ledger Accounting
# Copyright (c) 1998-2002
#
# Author: Dieter Simader
# Email: dsimader@sql-ledger.org
# Web: http://www.sql-ledger.org
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#######################################################################

use DBI;
8c7e4493 Moritz Bunkus
use SL::Auth;
d319704a Moritz Bunkus
use SL::User;
use SL::Form;

40782548 Moritz Bunkus
require "bin/mozilla/common.pl";
7a7f33b5 Moritz Bunkus
require "bin/mozilla/todo.pl";
40782548 Moritz Bunkus
bc3eec3a Sven Schöling
use strict;

dc50b737 Sven Schöling
our $cgi;
our $form;
our $auth;
8c7e4493 Moritz Bunkus
dc50b737 Sven Schöling
sub run {
$::lxdebug->enter_sub;
my $session_result = shift;
d319704a Moritz Bunkus
dc50b737 Sven Schöling
$cgi = $::cgi;
$form = $::form;
$auth = $::auth;
64e47b81 Moritz Bunkus
dc50b737 Sven Schöling
$form->{stylesheet} = "lx-office-erp.css";
$form->{favicon} = "favicon.ico";
8c7e4493 Moritz Bunkus
dc50b737 Sven Schöling
if (SL::Auth::SESSION_EXPIRED == $session_result) {
c7edb248 Sven Schöling
$form->{error_message} = $::locale->text('The session is invalid or has expired.');
8c7e4493 Moritz Bunkus
login_screen();
b2945bf6 Sven Schöling
::end_of_request();
8c7e4493 Moritz Bunkus
}
dc50b737 Sven Schöling
my $action = $form->{action};
if (!$action && $auth->{SESSION}->{login}) {
$action = 'login';
}
if ($action) {
a0d77095 Sven Schöling
%::myconfig = $auth->read_user($form->{login}) if ($form->{login});
$::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
dc50b737 Sven Schöling
a0d77095 Sven Schöling
if (!$::myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
4b937d1a Sven Donath
$form->{error_message} = $::locale->text('Incorrect username or password!');
dc50b737 Sven Schöling
login_screen();
} else {
$auth->set_session_value('login', $form->{login}, 'password', $form->{password});
$auth->create_or_refresh_session();

a0d77095 Sven Schöling
$form->{titlebar} .= " - $::myconfig{name} - $::myconfig{dbname}";
c7edb248 Sven Schöling
call_sub($::locale->findsub($action));
dc50b737 Sven Schöling
}
} else {
login_screen();
}
8c7e4493 Moritz Bunkus
dc50b737 Sven Schöling
$::lxdebug->leave_sub;
d319704a Moritz Bunkus
}

sub login_screen {
bc3eec3a Sven Schöling
$main::lxdebug->enter_sub();
b0a92688 Sven Schöling
my ($msg) = @_;
d319704a Moritz Bunkus
if (-f "css/lx-office-erp.css") {
$form->{stylesheet} = "lx-office-erp.css";
}

33c1a7f1 Moritz Bunkus
$form->{msg} = $msg;
$form->header();
d319704a Moritz Bunkus
d1e4ee79 Moritz Bunkus
print $form->parse_html_template('login/login_screen');
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub login {
bc3eec3a Sven Schöling
$main::lxdebug->enter_sub();
d319704a Moritz Bunkus
b0a92688 Sven Schöling
unless ($form->{login}) {
c7edb248 Sven Schöling
login_screen($::locale->text('You did not enter a name!'));
b2945bf6 Sven Schöling
::end_of_request();
b0a92688 Sven Schöling
}
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
my $user = new User $form->{login};
d319704a Moritz Bunkus
# if we get an error back, bale out
bc3eec3a Sven Schöling
my $result;
8c7e4493 Moritz Bunkus
if (($result = $user->login($form)) <= -1) {
b2945bf6 Sven Schöling
::end_of_request() if $result == -2;
c7edb248 Sven Schöling
login_screen($::locale->text('Incorrect username or password!'));
b2945bf6 Sven Schöling
::end_of_request();
d319704a Moritz Bunkus
}

d1e4ee79 Moritz Bunkus
my %style_to_script_map = ( 'v3' => 'v3',
'neu' => 'new',
b1513dcc Holger Lindemann
'v4' => 'v4',
d1e4ee79 Moritz Bunkus
'xml' => 'XML',
);

my $menu_script = $style_to_script_map{$user->{menustyle}} || '';

d319704a Moritz Bunkus
# made it this far, execute the menu
dc50b737 Sven Schöling
# standard redirect does not seem to work for this invocation, (infinite loops?)
# do a manual invocation instead
# $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display', "callback=" . $form->escape($form->{callback}));
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::auth->set_cookie_environment_variable();
8c7e4493 Moritz Bunkus
dc50b737 Sven Schöling
$::form->{script} = "menu${menu_script}.pl";
$::form->{action} = 'display';
$::form->{callback} = $::form->escape($::form->{callback});

require "bin/mozilla/$::form->{script}";
display();

# $form->redirect();
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub logout {
bc3eec3a Sven Schöling
$main::lxdebug->enter_sub();
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::auth->destroy_session();
d319704a Moritz Bunkus
# remove the callback to display the message
8c7e4493 Moritz Bunkus
$form->{callback} = "login.pl?action=";
c7edb248 Sven Schöling
$form->redirect($::locale->text('You are logged out!'));
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::lxdebug->leave_sub();
d319704a Moritz Bunkus
}

sub company_logo {
bc3eec3a Sven Schöling
$main::lxdebug->enter_sub();
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
my %myconfig = %main::myconfig;
713a6d70 Moritz Bunkus
$form->{todo_list} = create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
7a7f33b5 Moritz Bunkus
d1e4ee79 Moritz Bunkus
$form->{stylesheet} = $myconfig{stylesheet};
1de53cbf Sven Donath
$form->{title} = $::locale->text('Lx-Office');
d319704a Moritz Bunkus
# create the logo screen
d1e4ee79 Moritz Bunkus
$form->header() unless $form->{noheader};

print $form->parse_html_template('login/company_logo');
d319704a Moritz Bunkus
bc3eec3a Sven Schöling
$main::lxdebug->leave_sub();
d319704a Moritz Bunkus
}
8c7e4493 Moritz Bunkus
sub show_error {
my $template = shift;
c7edb248 Sven Schöling
my %myconfig = %main::myconfig;
bc3eec3a Sven Schöling
$myconfig{countrycode} = $main::language;
8c7e4493 Moritz Bunkus
$form->{stylesheet} = 'css/lx-office-erp.css';

$form->header();
print $form->parse_html_template($template);

# $form->parse_html_template('login/auth_db_unreachable');
# $form->parse_html_template('login/authentication_pl_missing');

b2945bf6 Sven Schöling
::end_of_request();
8c7e4493 Moritz Bunkus
}
7a7f33b5 Moritz Bunkus
dc50b737 Sven Schöling
1;

__END__