X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/66e5ad7be944770f6c4e71fd84c9dd33cd1460c9..d0779d015d862645b9f63140f7e7af2596238c8e:/SL/ReportGenerator.pm diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 617a27474..29e2d9480 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -3,6 +3,7 @@ package SL::ReportGenerator; use IO::Wrap; use List::Util qw(max); use Text::CSV_XS; +use Text::Iconv; use SL::Form; @@ -52,9 +53,34 @@ sub new { $self->set_options(@_) if (@_); + $self->_init_escaped_strings_map(); + return $self; } +sub _init_escaped_strings_map { + my $self = shift; + + $self->{escaped_strings_map} = { + 'ä' => 'ä', + 'ö' => 'ö', + 'ü' => 'ü', + 'Ä' => 'Ä', + 'Ö' => 'Ö', + 'Ü' => 'Ü', + 'ß' => 'ß', + '>' => '>', + '<' => '<', + '"' => '"', + }; + + my $iconv = $main::locale->{iconv_iso8859}; + + if ($iconv) { + map { $self->{escaped_strings_map}->{$_} = $iconv->convert($self->{escaped_strings_map}->{$_}) } keys %{ $self->{escaped_strings_map} }; + } +} + sub set_columns { my $self = shift; my %columns = @_; @@ -311,7 +337,15 @@ sub prepare_html_content { 'data' => $self->html_format($col->{data}->[$i]), 'link' => $col->{link}->[$i], }; - }; + } + + # Force at least a   to be displayed so that browsers + # will format the table cell (e.g. borders etc). + if (!scalar @{ $col->{CELL_ROWS} }) { + push @{ $col->{CELL_ROWS} }, { 'data' => ' ' }; + } elsif ((1 == scalar @{ $col->{CELL_ROWS} }) && !$col->{CELL_ROWS}->[0]->{data}) { + $col->{CELL_ROWS}->[0]->{data} = ' '; + } } my $row_data = { @@ -484,6 +518,19 @@ END } } +sub unescape_string { + my $self = shift; + my $text = shift; + + foreach my $key (keys %{ $self->{escaped_strings_map} }) { + $text =~ s/\Q$key\E/$self->{escaped_strings_map}->{$key}/g; + } + + $text =~ s/\Q&\E/&/g; + + return $text; +} + sub generate_csv_content { my $self = shift; @@ -509,7 +556,7 @@ sub generate_csv_content { my @visible_columns = $self->get_visible_columns('CSV'); if ($opts->{headers}) { - $csv->print($stdout, [ map { $self->{columns}->{$_}->{text} } @visible_columns ]); + $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}) } @visible_columns ]); } foreach my $row_set (@{ $self->{data} }) {