]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/ReportGenerator.pm
Wenn das "Pfeil"-Bild Teil eines Links ist, dann keinen Rahmen daraum zeichnen.
[kivitendo-erp.git] / SL / ReportGenerator.pm
index 35a3d83e80d1a26dfb6f1eeca25611963adc71a3..306236fb22a78f7934ea8932ab60802b158cf2d8 100644 (file)
@@ -86,17 +86,30 @@ sub set_sort_indicator {
 sub add_data {
   my $self = shift;
 
 sub add_data {
   my $self = shift;
 
+  my $last_row_set;
+
   while (my $arg = shift) {
     if ('ARRAY' eq ref $arg) {
       push @{ $self->{data} }, $arg;
   while (my $arg = shift) {
     if ('ARRAY' eq ref $arg) {
       push @{ $self->{data} }, $arg;
+      $last_row_set = $arg;
 
     } elsif ('HASH' eq ref $arg) {
 
     } elsif ('HASH' eq ref $arg) {
-      push @{ $self->{data} }, [ $arg ];
+      my $row_set = [ $arg ];
+      push @{ $self->{data} }, $row_set;
+      $last_row_set = $row_set;
 
     } else {
       $self->{form}->error('Incorrect usage -- expecting hash or array ref');
     }
   }
 
     } else {
       $self->{form}->error('Incorrect usage -- expecting hash or array ref');
     }
   }
+
+  return $last_row_set;
+}
+
+sub add_separator {
+  my $self = shift;
+
+  push @{ $self->{data} }, { 'type' => 'separator' };
 }
 
 sub clear_data {
 }
 
 sub clear_data {
@@ -181,8 +194,8 @@ sub generate_with_headers {
     print $self->generate_html_content();
 
   } elsif ($format eq 'csv') {
     print $self->generate_html_content();
 
   } elsif ($format eq 'csv') {
-    print qq|content-type: text/plain\n\n|;
-    print qq|content-disposition: attachment; filename=${filename}.csv\n\n|;
+    print qq|content-type: text/csv\n|;
+    print qq|content-disposition: attachment; filename=${filename}.csv\n\n|;
     $self->generate_csv_content();
 
   } elsif ($format eq 'pdf') {
     $self->generate_csv_content();
 
   } elsif ($format eq 'pdf') {
@@ -202,6 +215,17 @@ sub get_visible_columns {
   return grep { my $c = $self->{columns}->{$_}; $c && $c->{visible} && (($c->{visible} == 1) || ($c->{visible} =~ /${format}/i)) } @{ $self->{column_order} };
 }
 
   return grep { my $c = $self->{columns}->{$_}; $c && $c->{visible} && (($c->{visible} == 1) || ($c->{visible} =~ /${format}/i)) } @{ $self->{column_order} };
 }
 
+sub html_format {
+  my $self  = shift;
+  my $value = shift;
+
+  $value =  $self->{form}->quote_html($value);
+  $value =~ s/\r//g;
+  $value =~ s/\n/<br>/g;
+
+  return $value;
+}
+
 sub prepare_html_content {
   my $self = shift;
 
 sub prepare_html_content {
   my $self = shift;
 
@@ -228,11 +252,25 @@ sub prepare_html_content {
   my @rows;
 
   foreach my $row_set (@{ $self->{data} }) {
   my @rows;
 
   foreach my $row_set (@{ $self->{data} }) {
+    if ('HASH' eq ref $row_set) {
+      my $row_data = {
+        'IS_CONTROL'    => 1,
+        'IS_SEPARATOR'  => $row_set->{type} eq 'separator',
+        'NUM_COLUMNS'   => scalar @visible_columns,
+      };
+
+      push @rows, $row_data;
+
+      next;
+    }
+
     $outer_idx++;
 
     foreach my $row (@{ $row_set }) {
       $inner_idx++;
 
     $outer_idx++;
 
     foreach my $row (@{ $row_set }) {
       $inner_idx++;
 
+      map { $row->{$_}->{data} = $self->html_format($row->{$_}->{data}) } @visible_columns;
+
       my $row_data = {
         'COLUMNS'       => [ map { $row->{$_} } @visible_columns ],
         'outer_idx'     => $outer_idx,
       my $row_data = {
         'COLUMNS'       => [ map { $row->{$_} } @visible_columns ],
         'outer_idx'     => $outer_idx,
@@ -253,9 +291,9 @@ sub prepare_html_content {
 
   my $variables = {
     'TITLE'                => $opts->{title},
 
   my $variables = {
     'TITLE'                => $opts->{title},
-    'TOP_INFO_TEXT'        => $opts->{top_info_text},
+    'TOP_INFO_TEXT'        => $self->html_format($opts->{top_info_text}),
     'RAW_TOP_INFO_TEXT'    => $opts->{raw_top_info_text},
     'RAW_TOP_INFO_TEXT'    => $opts->{raw_top_info_text},
-    'BOTTOM_INFO_TEXT'     => $opts->{bottom_info_text},
+    'BOTTOM_INFO_TEXT'     => $self->html_format($opts->{bottom_info_text}),
     'RAW_BOTTOM_INFO_TEXT' => $opts->{raw_bottom_info_text},
     'ALLOW_PDF_EXPORT'     => $allow_pdf_export,
     'ALLOW_CSV_EXPORT'     => $opts->{allow_csv_export},
     'RAW_BOTTOM_INFO_TEXT' => $opts->{raw_bottom_info_text},
     'ALLOW_PDF_EXPORT'     => $allow_pdf_export,
     'ALLOW_CSV_EXPORT'     => $opts->{allow_csv_export},
@@ -347,8 +385,11 @@ END
   $html_file->print($form->parse_html_template('report_generator/pdf_report', $variables));
   $html_file->close();
 
   $html_file->print($form->parse_html_template('report_generator/pdf_report', $variables));
   $html_file->close();
 
-  my $gs = IO::File->new("\"${main::html2ps_bin}\" -f \"${cfg_file_name}\" \"${html_file_name}\" | " .
-                         "\"${main::ghostscript_bin}\" -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=${opt_paper_size} -sOutputFile=- -c .setpdfwrite - |");
+  my $cmdline =
+    "\"${main::html2ps_bin}\" -f \"${cfg_file_name}\" \"${html_file_name}\" | " .
+    "\"${main::ghostscript_bin}\" -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=${opt_paper_size} -sOutputFile=- -c .setpdfwrite -";
+
+  my $gs = IO::File->new("${cmdline} |");
   if ($gs) {
     while (my $line = <$gs>) {
       print $line;
   if ($gs) {
     while (my $line = <$gs>) {
       print $line;
@@ -391,6 +432,7 @@ sub generate_csv_content {
   }
 
   foreach my $row_set (@{ $self->{data} }) {
   }
 
   foreach my $row_set (@{ $self->{data} }) {
+    next if ('ARRAY' ne ref $row_set);
     foreach my $row (@{ $row_set }) {
       $csv->print($stdout, [ map { $row->{$_}->{data} } @visible_columns ]);
     }
     foreach my $row (@{ $row_set }) {
       $csv->print($stdout, [ map { $row->{$_}->{data} } @visible_columns ]);
     }