X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/42b702a6bbfdef8a094b1fafbdf205c986efd7be..03ea97647e3fbdea4323f4f2136bdfa87cb15c1b:/SL/ReportGenerator.pm diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 2a40ab5e1..988d295e6 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -60,34 +60,9 @@ 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 = @_; @@ -277,7 +252,7 @@ sub html_format { my $self = shift; my $value = shift; - $value = $self->{form}->quote_html($value); + $value = $main::locale->quote_special_chars('HTML', $value); $value =~ s/\r//g; $value =~ s/\n/
/g; @@ -423,7 +398,7 @@ sub render_pdf_with_pdf_api2 { my $myconfig = $self->{myconfig}; my $opts = $self->{options}; - my $params = $opts->{pdf_export}; + my $pdfopts = $opts->{pdf_export}; my (@data, @column_props, @cell_props); @@ -453,8 +428,9 @@ sub render_pdf_with_pdf_api2 { push @cell_props, $cell_props_row; foreach (0 .. $num_columns - 1) { - push @{ $cell_props_row }, { 'background_color' => '#000000', - 'font_color' => '#ffffff', }; + push @{ $cell_props_row }, { 'background_color' => '#666666', + 'font_color' => '#ffffff', + 'colspan' => $_ == 0 ? -1 : undef, }; } } next; @@ -504,19 +480,19 @@ sub render_pdf_with_pdf_api2 { my %supported_fonts = map { $_ => 1 } qw(courier georgia helvetica times verdana); - my $paper_size = defined $params->{paper_size} && defined $papersizes->{lc $params->{paper_size}} ? lc $params->{paper_size} : 'a4'; + my $paper_size = defined $pdfopts->{paper_size} && defined $papersizes->{lc $pdfopts->{paper_size}} ? lc $pdfopts->{paper_size} : 'a4'; my ($paper_width, $paper_height); - if (lc $params->{orientation} eq 'landscape') { + if (lc $pdfopts->{orientation} eq 'landscape') { ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[1, 0]; } else { ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[0, 1]; } - my $margin_top = _cm2bp($params->{margin_top} || 1.5); - my $margin_bottom = _cm2bp($params->{margin_bottom} || 1.5); - my $margin_left = _cm2bp($params->{margin_left} || 1.5); - my $margin_right = _cm2bp($params->{margin_right} || 1.5); + my $margin_top = _cm2bp($pdfopts->{margin_top} || 1.5); + my $margin_bottom = _cm2bp($pdfopts->{margin_bottom} || 1.5); + my $margin_left = _cm2bp($pdfopts->{margin_left} || 1.5); + my $margin_right = _cm2bp($pdfopts->{margin_right} || 1.5); my $table = PDF::Table->new(); my $pdf = PDF::API2->new(); @@ -524,16 +500,16 @@ sub render_pdf_with_pdf_api2 { $pdf->mediabox($paper_width, $paper_height); - my $font = $pdf->corefont(defined $params->{font_name} && $supported_fonts{lc $params->{font_name}} ? ucfirst $params->{font_name} : 'Verdana', + my $font = $pdf->corefont(defined $pdfopts->{font_name} && $supported_fonts{lc $pdfopts->{font_name}} ? ucfirst $pdfopts->{font_name} : 'Verdana', '-encoding' => $main::dbcharset || 'ISO-8859-15'); - my $font_size = $params->{font_size} || 7; + my $font_size = $pdfopts->{font_size} || 7; my $title_font_size = $font_size + 1; my $padding = 1; my $font_height = $font_size + 2 * $padding; my $title_font_height = $font_size + 2 * $padding; my $header_height = 2 * $title_font_height if ($opts->{title}); - my $footer_height = 2 * $font_height if ($params->{number}); + my $footer_height = 2 * $font_height if ($pdfopts->{number}); my $top_text_height = 0; @@ -582,7 +558,7 @@ sub render_pdf_with_pdf_api2 { foreach my $page_num (1..$pdf->pages()) { my $curpage = $pdf->openpage($page_num); - if ($params->{number}) { + if ($pdfopts->{number}) { my $label = $main::locale->text("Page #1/#2", $page_num, $pdf->pages()); my $text_obj = $curpage->text(); @@ -601,12 +577,29 @@ sub render_pdf_with_pdf_api2 { } } - my $filename = $self->get_attachment_basename(); + my $content = $pdf->stringify(); + + my $printer_command; + if ($pdfopts->{print} && $pdfopts->{printer_id}) { + $form->{printer_id} = $pdfopts->{printer_id}; + $form->get_printer_code($myconfig); + $printer_command = $form->{printer_command}; + } - print qq|content-type: application/pdf\n|; - print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|; + if ($printer_command) { + $self->_print_content('printer_command' => $printer_command, + 'content' => $content, + 'copies' => $pdfopts->{copies}); + $form->{report_generator_printed} = 1; - print $pdf->stringify(); + } else { + my $filename = $self->get_attachment_basename(); + + print qq|content-type: application/pdf\n|; + print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|; + + print $content; + } } sub verify_paper_size { @@ -614,7 +607,7 @@ sub verify_paper_size { my $requested_paper_size = lc shift; my $default_paper_size = shift; - my %allowed_paper_sizes = map { $_ => 1 } qw(a3 a4 letter legal); + my %allowed_paper_sizes = map { $_ => 1 } qw(a3 a4 a5 letter legal); return $allowed_paper_sizes{$requested_paper_size} ? $requested_paper_size : $default_paper_size; } @@ -712,15 +705,9 @@ END unlink $cfg_file_name, $html_file_name; if ($printer_command && $content) { - foreach my $i (1 .. max $opt->{copies}, 1) { - my $printer = IO::File->new("| ${printer_command}"); - if (!$printer) { - $form->error($locale->text('Could not spawn the printer command.')); - } - $printer->print($content); - $printer->close(); - } - + $self->_print_content('printer_command' => $printer_command, + 'content' => $content, + 'copies' => $opt->{copies}); $form->{report_generator_printed} = 1; } @@ -730,6 +717,18 @@ END } } +sub _print_content { + my $self = shift; + my %params = @_; + + foreach my $i (1 .. max $params{copies}, 1) { + my $printer = IO::File->new("| $params{printer_command}"); + $main::form->error($main::locale->text('Could not spawn the printer command.')) if (!$printer); + $printer->print($params{content}); + $printer->close(); + } +} + sub generate_pdf_content { my $self = shift; @@ -743,14 +742,12 @@ sub generate_pdf_content { } 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; - } + my $self = shift; + my $text = shift; + my $iconv = $main::locale->{iconv}; - $text =~ s/\Q&\E/&/g; + $text = $main::locale->unquote_special_chars('HTML', $text); + $text = $main::locale->{iconv}->convert($text) if ($main::locale->{iconv}); return $text; }