From: Sven Schöling Date: Mon, 3 Jan 2011 17:35:03 +0000 (+0100) Subject: Merge branch 'master' of ssh://lx-office/~/lx-office-erp X-Git-Tag: release-2.6.2beta1~6 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/commitdiff_plain/87ad1737166b8eb5ec26ec3ab27f686bdf4d3679?hp=829f6742c99fdf3b3ef78713c3ce1c1266f67d98 Merge branch 'master' of ssh://lx-office/~/lx-office-erp --- diff --git a/SL/AR.pm b/SL/AR.pm index a4d100039..1754fe6ea 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -171,7 +171,7 @@ sub post_transaction { # insert detail records in acc_trans $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; - @values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"amount_$i"}), conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, + @values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, conv_i($form->{"taxkey_$i"})); do_query($form, $dbh, $query, @values); @@ -179,7 +179,7 @@ sub post_transaction { # insert detail records in acc_trans $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; - @values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"tax_$i"}), conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, + @values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, conv_i($form->{"taxkey_$i"})); do_query($form, $dbh, $query, @values); } diff --git a/SL/Auth.pm b/SL/Auth.pm index 2bd2d09c0..087301a5e 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -13,6 +13,7 @@ use SL::Auth::DB; use SL::Auth::LDAP; use SL::User; +use SL::DBUpgrade2; use SL::DBUtils; use strict; @@ -303,7 +304,7 @@ sub create_tables { $charset ||= Common::DEFAULT_CHARSET; $dbh->rollback(); - User->process_query($main::form, $dbh, 'sql/auth_db.sql', undef, $charset); + SL::DBUpgrade2->new(form => $::form)->process_query($dbh, 'sql/auth_db.sql', undef, $charset); $main::lxdebug->leave_sub(); } diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index 8e61f222f..ca45510f0 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -4,6 +4,7 @@ use IO::File; use List::MoreUtils qw(any); use SL::Common; +use SL::DBUtils; use SL::Iconv; use strict; diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index cc886d8ca..4a3f131d3 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -22,6 +22,15 @@ use File::Basename; # number 'die' was called in. use constant END_OF_REQUEST => "END-OF-REQUEST\n"; +sub new { + my ($class, $interface) = @_; + + my $self = bless {}, $class; + $self->{interface} = lc($interface || 'cgi'); + + return $self; +} + sub pre_request_checks { if (!$::auth->session_tables_present) { if ($::form->{script} eq 'admin.pl') { @@ -138,15 +147,17 @@ sub _run_controller { } sub handle_request { + my $self = shift; + $self->{request} = shift; + $::lxdebug->enter_sub; $::lxdebug->begin_request; - my $interface = lc(shift || 'cgi'); my ($script, $path, $suffix, $script_name, $action, $routing_type); $script_name = $ENV{SCRIPT_NAME}; - unrequire_bin_mozilla($interface); + $self->unrequire_bin_mozilla; $::cgi = CGI->new(''); $::locale = Locale->new($::language); @@ -230,7 +241,8 @@ sub handle_request { } sub unrequire_bin_mozilla { - return unless $_[0] =~ m/^(?:fastcgi|fcgid|fcgi)$/; + my $self = shift; + return unless $self->{interface} =~ m/^(?:fastcgi|fcgid|fcgi)$/; for (keys %INC) { next unless m#^bin/mozilla/#; @@ -295,6 +307,12 @@ sub _route_controller_request { return ($controller, $action); } +sub get_standard_filehandles { + my $self = shift; + + return $self->{interface} =~ m/f(?:ast)cgi/i ? $self->{request}->GetHandles() : (\*STDIN, \*STDOUT, \*STDERR); +} + package main; use strict; diff --git a/SL/FCGIFixes.pm b/SL/FCGIFixes.pm index 47393aad6..d341f4a97 100644 --- a/SL/FCGIFixes.pm +++ b/SL/FCGIFixes.pm @@ -25,6 +25,7 @@ use version; sub fix_print_and_internal_encoding_after_0_68 { return if version->new("$FCGI::VERSION")->numify <= version->new("0.68")->numify; + return if lc($::dbcharset) !~ m/^(?:utf-?8|unicode)$/; my $encoder = Encode::find_encoding('UTF-8'); my $original_fcgi_print = \&FCGI::Stream::PRINT; diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 2b37e78f5..f6095a8a0 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -686,17 +686,26 @@ sub _print_content { } } -sub unescape_string { - my ($self, $text, $do_iconv) = @_; +sub _handle_quoting_and_encoding { + my ($self, $text, $do_unquote) = @_; - $text = $main::locale->unquote_special_chars('HTML', $text); - $text = $::locale->{iconv}->convert($text) if $do_iconv; + $text = $main::locale->unquote_special_chars('HTML', $text) if $do_unquote; + $text = Encode::encode('UTF-8', $text) if $::locale->is_utf8; return $text; } sub generate_csv_content { - my $self = shift; + my $self = shift; + my $stdout = ($::dispatcher->get_standard_filehandles)[1]; + + # Text::CSV_XS seems to downgrade to bytes already (see + # SL/FCGIFixes.pm). Therefore don't let FCGI do that again. + $::locale->with_raw_io($stdout, sub { $self->_generate_csv_content($stdout) }); +} + +sub _generate_csv_content { + my ($self, $stdout) = @_; my %valid_sep_chars = (';' => ';', ',' => ',', ':' => ':', 'TAB' => "\t"); my %valid_escape_chars = ('"' => 1, "'" => 1); @@ -718,13 +727,9 @@ sub generate_csv_content { my @visible_columns = $self->get_visible_columns('CSV'); - my $stdout; - open $stdout, '>-'; - binmode $stdout, ':encoding(utf8)' if $::locale->is_utf8; - if ($opts->{headers}) { if (!$self->{custom_headers}) { - $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}, 1) } @visible_columns ]); + $csv->print($stdout, [ map { $self->_handle_quoting_and_encoding($self->{columns}->{$_}->{text}, 1) } @visible_columns ]); } else { foreach my $row (@{ $self->{custom_headers} }) { @@ -732,7 +737,7 @@ sub generate_csv_content { foreach my $col (@{ $row }) { my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1; - push @{ $fields }, ($self->unescape_string($col->{text})) x $num_output; + push @{ $fields }, ($self->_handle_quoting_and_encoding($col->{text}, 1)) x $num_output; } $csv->print($stdout, $fields); @@ -754,7 +759,7 @@ sub generate_csv_content { my $num_output = ($row->{$col}{colspan} && ($row->{$col}->{colspan} > 1)) ? $row->{$col}->{colspan} : 1; $skip_next = $num_output - 1; - push @data, join($eol, map { s/\r?\n/$eol/g; $_ } @{ $row->{$col}->{data} }); + push @data, join($eol, map { s/\r?\n/$eol/g; $self->_handle_quoting_and_encoding($_, 0) } @{ $row->{$col}->{data} }); push @data, ('') x $skip_next if ($skip_next); } diff --git a/admin.pl b/admin.pl index 603d166b2..433ffe9d3 100755 --- a/admin.pl +++ b/admin.pl @@ -4,7 +4,8 @@ use strict; use SL::Dispatcher; -SL::Dispatcher::pre_startup(); -SL::Dispatcher::handle_request('CGI'); +our $dispatcher = SL::Dispatcher->new('CGI'); +$dispatcher->pre_startup; +$dispatcher->handle_request; 1; diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index 2819da00e..eac4d083e 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -84,10 +84,9 @@ sub run { if ($auth->session_tables_present()) { $::auth->set_session_value('rpw', $::form->{rpw}); $::auth->create_or_refresh_session(); + _apply_dbupgrade_scripts(); } - _apply_dbupgrade_scripts(); - call_sub($locale->findsub($form->{action})); } } else { @@ -363,8 +362,12 @@ sub add_user { "dateformat" => "dd.mm.yy", "stylesheet" => "lx-office-erp.css", "menustyle" => "old", + dbport => $::auth->{DB_config}->{port} || 5432, + dbuser => $::auth->{DB_config}->{user} || 'lxoffice', + dbhost => $::auth->{DB_config}->{host} || 'localhost', }; + edit_user_form($myconfig); } @@ -650,10 +653,10 @@ sub dbselect_source { my $form = $main::form; my $locale = $main::locale; - $form->{dbport} = '5432'; - $form->{dbuser} = 'lxoffice'; + $form->{dbport} = $::auth->{DB_config}->{port} || 5432; + $form->{dbuser} = $::auth->{DB_config}->{user} || 'lxoffice'; $form->{dbdefault} = 'template1'; - $form->{dbhost} = 'localhost'; + $form->{dbhost} = $::auth->{DB_config}->{host} || 'localhost'; $form->{title} = "Lx-Office ERP / " . $locale->text('Database Administration'); diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 35fef992e..74285e73e 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -92,7 +92,7 @@ sub add { $form->{title} = "Add"; - $form->{callback} = "ap.pl?action=add" unless $form->{callback}; + $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; AP->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 251c4644c..0e5ab85a9 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -95,7 +95,7 @@ sub add { # /saving the history $form->{title} = "Add"; - $form->{callback} = "ar.pl?action=add" unless $form->{callback}; + $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; @@ -983,12 +983,12 @@ sub update { $form->{invdate} = $form->{transdate}; my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 oldcustomer); - + &check_name("customer"); - + # check_name ruft get_customer auf, oldcustomer wird überschrieben, daher wird dies vorher gemerkt # get_customer holt Bemerkungen als intnotes, für Debitorenbuchungen gibt es aber nur das Feld notes - $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer}; + $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer}; $form->{AR} = $saved_variables{AR}; if ($saved_variables{AR_amount_1} =~ m/.--./) { diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 5417918fd..518e43052 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -1610,7 +1610,7 @@ sub post { remove_draft() if $form->{remove_draft}; - $form->{callback} = build_std_url("action=add", "show_details"); + $form->{callback} = build_std_url("action=add&DONT_LOAD_DRAFT=1", "show_details"); $form->redirect($form->{callback}); $main::lxdebug->leave_sub(); diff --git a/dispatcher.fpl b/dispatcher.fpl index afe1bc6ed..7d2dfb5be 100755 --- a/dispatcher.fpl +++ b/dispatcher.fpl @@ -6,10 +6,12 @@ use FCGI; use SL::Dispatcher; use SL::FCGIFixes; +our $dispatcher = SL::Dispatcher->new('FastCGI'); +$dispatcher->pre_startup_setup; SL::FCGIFixes::apply_fixes(); +$dispatcher->pre_startup_checks; -SL::Dispatcher::pre_startup(); my $request = FCGI::Request(); -SL::Dispatcher::handle_request('FastCGI') while $request->Accept() >= 0; +$dispatcher->handle_request($request) while $request->Accept() >= 0; 1;