displayable_filter
[kivitendo-erp.git] / SL / Dispatcher.pm
index 0071e81..30a4b81 100644 (file)
@@ -23,6 +23,7 @@ use SL::Locale;
 use SL::Common;
 use SL::Form;
 use SL::Helper::DateTime;
+use SL::InstanceConfiguration;
 use SL::Template::Plugin::HTMLFixes;
 
 # Trailing new line is added so that Perl will not add the line
@@ -67,7 +68,6 @@ sub show_error {
   $::form->{error}         = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
   $::form->{error}         = $::locale->text('Incorrect password!.')                   if ($error_type eq 'password');
   $::myconfig{countrycode} = $::lx_office_conf{system}->{language};
-  $::form->{stylesheet}    = 'css/lx-office-erp.css';
 
   $::form->header;
   print $::form->parse_html_template($template);
@@ -80,7 +80,6 @@ sub pre_startup_setup {
   my ($self) = @_;
 
   SL::LxOfficeConf->read;
-  _init_environment();
 
   eval {
     package main;
@@ -95,7 +94,7 @@ sub pre_startup_setup {
     $::auth        = SL::Auth->new;
     $::form        = undef;
     %::myconfig    = ();
-    %::called_subs = (); # currently used for recursion detection
+    $::request     = undef;
   }
 
   $SIG{__WARN__} = sub {
@@ -168,10 +167,10 @@ sub handle_request {
 
   $self->unrequire_bin_mozilla;
 
-  $::cgi         = CGI->new('');
-  $::locale      = Locale->new($::lx_office_conf{system}->{language});
-  $::form        = Form->new;
-  %::called_subs = ();
+  $::locale        = Locale->new($::lx_office_conf{system}->{language});
+  $::form          = Form->new;
+  $::instance_conf = SL::InstanceConfiguration->new;
+  $::request       = { cgi => CGI->new({}) };
 
   my $session_result = $::auth->restore_session;
   $::auth->create_or_refresh_session;
@@ -205,7 +204,7 @@ sub handle_request {
 
     } else {
       show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
-      %::myconfig = $::auth->read_user($::form->{login});
+      %::myconfig = $::auth->read_user(login => $::form->{login});
 
       show_error('login/password_error', 'password') unless $::myconfig{login};
 
@@ -219,7 +218,9 @@ sub handle_request {
       delete $::form->{password};
 
       if ($action) {
-        map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
+        $::instance_conf->init;
+
+        map { $::form->{$_} = $::myconfig{$_} } qw(charset)
           unless $action eq 'save' && $::form->{type} eq 'preferences';
 
         $::form->set_standard_title;
@@ -237,7 +238,7 @@ sub handle_request {
   } or do {
     if ($EVAL_ERROR ne END_OF_REQUEST) {
       print STDERR $EVAL_ERROR;
-      $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+      $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
       eval { show_error('generic/error') };
     }
   };
@@ -250,6 +251,7 @@ sub handle_request {
   $::locale   = undef;
   $::form     = undef;
   $::myconfig = ();
+  $::request  = undef;
   Form::disconnect_standard_dbh;
 
   $::lxdebug->end_request;
@@ -307,7 +309,7 @@ sub _route_dispatcher_request {
 
     1;
   } or do {
-    $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+    $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
     show_error('generic/error');
   };
 
@@ -324,7 +326,7 @@ sub _route_controller_request {
 
     1;
   } or do {
-    $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+    $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
     show_error('generic/error');
   };
 
@@ -366,33 +368,11 @@ sub get_standard_filehandles {
   return $self->{interface} =~ m/f(?:ast)cgi/i ? $self->{request}->GetHandles() : (\*STDIN, \*STDOUT, \*STDERR);
 }
 
-sub _init_environment {
-  my %key_map = ( lib  => { name => 'PERL5LIB', append_path => 1 },
-                  path => { name => 'PATH',     append_path => 1 },
-                );
-  my $cfg     = $::lx_office_conf{environment} || {};
-
-  while (my ($key, $value) = each %{ $cfg }) {
-    next unless $value;
-
-    my $info = $key_map{$key} || {};
-    $key     = $info->{name}  || $key;
-
-    if ($info->{append_path}) {
-      $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key};
-      $value = $ENV{$key} . $value;
-    }
-
-    $ENV{$key} = $value;
-  }
-}
-
 sub _check_for_old_config_files {
   my @old_files = grep { -f "config/${_}" } qw(authentication.pl console.conf lx-erp.conf lx-erp-local.conf);
   return unless @old_files;
 
   $::form->{title}      = $::locale->text('Old configuration files');
-  $::form->{stylesheet} = 'lx-office-erp.css';
   $::form->header;
   print $::form->parse_html_template('login/old_configuration_files', { FILES => \@old_files });