X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/a939b72794643b5ad273886ff6d66b782eecb601..24e8b08430fe09e219b61b07d40bfc12c8f5ed1e:/SL/ReportGenerator.pm diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 35a3d83e8..6a78c5370 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -86,17 +86,30 @@ sub set_sort_indicator { sub add_data { my $self = shift; + my $last_row_set; + while (my $arg = shift) { if ('ARRAY' eq ref $arg) { push @{ $self->{data} }, $arg; + $last_row_set = $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'); } } + + return $last_row_set; +} + +sub add_separator { + my $self = shift; + + push @{ $self->{data} }, { 'type' => 'separator' }; } sub clear_data { @@ -181,8 +194,8 @@ sub generate_with_headers { 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') { @@ -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} }; } +sub html_format { + my $self = shift; + my $value = shift; + + $value = $self->{form}->quote_html($value); + $value =~ s/\r//g; + $value =~ s/\n/
/g; + + return $value; +} + sub prepare_html_content { my $self = shift; @@ -228,11 +252,25 @@ sub prepare_html_content { 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++; + map { $row->{$_}->{data} = $self->html_format($row->{$_}->{data}) } @visible_columns; + 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}, - '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}, - '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}, @@ -391,6 +429,7 @@ sub generate_csv_content { } 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 ]); }