1 package SL::ReportGenerator;
 
   5 use List::Util qw(max);
 
  13 # Cause locales.pl to parse these files:
 
  14 # parse_html_template('report_generator/html_report')
 
  21   $self->{myconfig} = shift;
 
  22   $self->{form}     = shift;
 
  26     'std_column_visibility' => 0,
 
  27     'output_format'         => 'HTML',
 
  28     'allow_pdf_export'      => 1,
 
  29     'allow_csv_export'      => 1,
 
  30     'html_template'         => 'report_generator/html_report',
 
  33       'orientation'         => 'landscape',
 
  34       'font_name'           => 'Verdana',
 
  38       'margin_bottom'       => 1.5,
 
  39       'margin_right'        => 1.5,
 
  49       'eol_style'           => 'Unix',
 
  55     'variable_list' => [],
 
  58   $self->{data_present} = 0;
 
  62   $self->set_options(@_) if (@_);
 
  71   $self->{columns} = \%columns;
 
  73   foreach my $column (values %{ $self->{columns} }) {
 
  74     $column->{visible} = $self->{options}->{std_column_visibility} unless defined $column->{visible};
 
  77   $self->set_column_order(sort keys %{ $self->{columns} });
 
  80 sub set_column_order {
 
  83   $self->{column_order} = [ grep { !$seen{$_}++ } @_, sort keys %{ $self->{columns} } ];
 
  86 sub set_sort_indicator {
 
  89   $self->{options}->{sort_indicator_column}    = shift;
 
  90   $self->{options}->{sort_indicator_direction} = shift;
 
  98   while (my $arg = shift) {
 
 101     if ('ARRAY' eq ref $arg) {
 
 104     } elsif ('HASH' eq ref $arg) {
 
 108       $self->{form}->error('Incorrect usage -- expecting hash or array ref');
 
 111     my @columns_with_default_alignment = grep { defined $self->{columns}->{$_}->{align} } keys %{ $self->{columns} };
 
 113     foreach my $row (@{ $row_set }) {
 
 114       foreach my $column (@columns_with_default_alignment) {
 
 115         $row->{$column}          ||= { };
 
 116         $row->{$column}->{align}   = $self->{columns}->{$column}->{align} unless (defined $row->{$column}->{align});
 
 119       foreach my $field (qw(data link)) {
 
 120         map { $row->{$_}->{$field} = [ $row->{$_}->{$field} ] if (ref $row->{$_}->{$field} ne 'ARRAY') } keys %{ $row };
 
 124     push @{ $self->{data} }, $row_set;
 
 125     $last_row_set = $row_set;
 
 127     $self->{data_present} = 1;
 
 130   return $last_row_set;
 
 136   push @{ $self->{data} }, { 'type' => 'separator' };
 
 143   push @{ $self->{data} }, $data;
 
 150   $self->{data_present} = 0;
 
 157   while (my ($key, $value) = each %options) {
 
 158     if ($key eq 'pdf_export') {
 
 159       map { $self->{options}->{pdf_export}->{$_} = $value->{$_} } keys %{ $value };
 
 161       $self->{options}->{$key} = $value;
 
 166 sub set_options_from_form {
 
 169   my $form     = $self->{form};
 
 170   my $myconfig = $self->{myconfig};
 
 172   foreach my $key (qw(output_format)) {
 
 173     my $full_key = "report_generator_${key}";
 
 174     $self->{options}->{$key} = $form->{$full_key} if (defined $form->{$full_key});
 
 177   foreach my $format (qw(pdf csv)) {
 
 178     my $opts = $self->{options}->{"${format}_export"};
 
 179     foreach my $key (keys %{ $opts }) {
 
 180       my $full_key = "report_generator_${format}_options_${key}";
 
 181       $opts->{$key} = $key =~ /^margin/ ? $form->parse_amount($myconfig, $form->{$full_key}) : $form->{$full_key};
 
 186 sub set_export_options {
 
 191     'variable_list' => [ @_ ],
 
 195 sub set_custom_headers {
 
 199     $self->{custom_headers} = [ @_ ];
 
 201     delete $self->{custom_headers};
 
 205 sub get_attachment_basename {
 
 207   my $filename =  $self->{options}->{attachment_basename} || 'report';
 
 208   $filename    =~ s|.*\\||;
 
 209   $filename    =~ s|.*/||;
 
 214 sub generate_with_headers {
 
 216   my $format = lc $self->{options}->{output_format};
 
 217   my $form   = $self->{form};
 
 219   if (!$self->{columns}) {
 
 220     $form->error('Incorrect usage -- no columns specified');
 
 223   if ($format eq 'html') {
 
 224     my $title      = $form->{title};
 
 225     $form->{title} = $self->{title} if ($self->{title});
 
 227     $form->{title} = $title;
 
 229     print $self->generate_html_content();
 
 231   } elsif ($format eq 'csv') {
 
 232     my $filename = $self->get_attachment_basename();
 
 233     print qq|content-type: text/csv\n|;
 
 234     print qq|content-disposition: attachment; filename=${filename}.csv\n\n|;
 
 235     $self->generate_csv_content();
 
 237   } elsif ($format eq 'pdf') {
 
 238     $self->generate_pdf_content();
 
 241     $form->error('Incorrect usage -- unknown format (supported are HTML, CSV, PDF)');
 
 245 sub get_visible_columns {
 
 249   return grep { my $c = $self->{columns}->{$_}; $c && $c->{visible} && (($c->{visible} == 1) || ($c->{visible} =~ /\Q${format}\E/i)) } @{ $self->{column_order} };
 
 256   $value =  $main::locale->quote_special_chars('HTML', $value);
 
 258   $value =~ s/\n/<br>/g;
 
 263 sub prepare_html_content {
 
 266   my ($column, $name, @column_headers);
 
 268   my $opts            = $self->{options};
 
 269   my @visible_columns = $self->get_visible_columns('HTML');
 
 271   foreach $name (@visible_columns) {
 
 272     $column = $self->{columns}->{$name};
 
 276       'align'                    => $column->{align},
 
 277       'link'                     => $column->{link},
 
 278       'text'                     => $column->{text},
 
 279       'show_sort_indicator'      => $name eq $opts->{sort_indicator_column},
 
 280       'sort_indicator_direction' => $opts->{sort_indicator_direction},
 
 283     push @column_headers, $header;
 
 287   if ($self->{custom_headers}) {
 
 288     $header_rows = $self->{custom_headers};
 
 290     $header_rows = [ \@column_headers ];
 
 293   my ($outer_idx, $inner_idx) = (0, 0);
 
 297   foreach my $row_set (@{ $self->{data} }) {
 
 298     if ('HASH' eq ref $row_set) {
 
 299       if ($row_set->{type} eq 'separator') {
 
 300         if (! scalar @rows) {
 
 301           $next_border_top = 1;
 
 303           $rows[-1]->{BORDER_BOTTOM} = 1;
 
 311         'IS_COLSPAN_DATA' => $row_set->{type} eq 'colspan_data',
 
 312         'NUM_COLUMNS'     => scalar @visible_columns,
 
 313         'BORDER_TOP'      => $next_border_top,
 
 314         'data'            => $row_set->{data},
 
 317       push @rows, $row_data;
 
 319       $next_border_top = 0;
 
 326     foreach my $row (@{ $row_set }) {
 
 329       my $output_columns = [ ];
 
 331       foreach my $col_name (@visible_columns) {
 
 337         my $col = $row->{$col_name};
 
 338         $col->{CELL_ROWS} = [ ];
 
 339         foreach my $i (0 .. scalar(@{ $col->{data} }) - 1) {
 
 340           push @{ $col->{CELL_ROWS} }, {
 
 341             'data' => $self->html_format($col->{data}->[$i]),
 
 342             'link' => $col->{link}->[$i],
 
 346         # Force at least a   to be displayed so that browsers
 
 347         # will format the table cell (e.g. borders etc).
 
 348         if (!scalar @{ $col->{CELL_ROWS} }) {
 
 349           push @{ $col->{CELL_ROWS} }, { 'data' => ' ' };
 
 350         } elsif ((1 == scalar @{ $col->{CELL_ROWS} }) && (!defined $col->{CELL_ROWS}->[0]->{data} || ($col->{CELL_ROWS}->[0]->{data} eq ''))) {
 
 351           $col->{CELL_ROWS}->[0]->{data} = ' ';
 
 354         push @{ $output_columns }, $col;
 
 355         $skip_next = $col->{colspan} ? $col->{colspan} - 1 : 0;
 
 359         'COLUMNS'       => $output_columns,
 
 360         'outer_idx'     => $outer_idx,
 
 361         'outer_idx_odd' => $outer_idx % 2,
 
 362         'inner_idx'     => $inner_idx,
 
 363         'BORDER_TOP'    => $next_border_top,
 
 366       push @rows, $row_data;
 
 368       $next_border_top = 0;
 
 372   my @export_variables = $self->{form}->flatten_variables(@{ $self->{export}->{variable_list} });
 
 374   my $allow_pdf_export = $opts->{allow_pdf_export};
 
 377     'TITLE'                => $opts->{title},
 
 378     'TOP_INFO_TEXT'        => $self->html_format($opts->{top_info_text}),
 
 379     'RAW_TOP_INFO_TEXT'    => $opts->{raw_top_info_text},
 
 380     'BOTTOM_INFO_TEXT'     => $self->html_format($opts->{bottom_info_text}),
 
 381     'RAW_BOTTOM_INFO_TEXT' => $opts->{raw_bottom_info_text},
 
 382     'ALLOW_PDF_EXPORT'     => $allow_pdf_export,
 
 383     'ALLOW_CSV_EXPORT'     => $opts->{allow_csv_export},
 
 384     'SHOW_EXPORT_BUTTONS'  => ($allow_pdf_export || $opts->{allow_csv_export}) && $self->{data_present},
 
 385     'HEADER_ROWS'          => $header_rows,
 
 386     'NUM_COLUMNS'          => scalar @column_headers,
 
 388     'EXPORT_VARIABLES'     => \@export_variables,
 
 389     'EXPORT_VARIABLE_LIST' => join(' ', @{ $self->{export}->{variable_list} }),
 
 390     'EXPORT_NEXTSUB'       => $self->{export}->{nextsub},
 
 391     'DATA_PRESENT'         => $self->{data_present},
 
 397 sub generate_html_content {
 
 399   my $variables = $self->prepare_html_content();
 
 401   return $self->{form}->parse_html_template($self->{options}->{html_template}, $variables);
 
 407   return $_[0] * 72 / 2.54;
 
 414   $text    = decode('UTF-8', $text) if ($self->{text_is_utf8});
 
 419 sub generate_pdf_content {
 
 426   my $variables  = $self->prepare_html_content();
 
 427   my $form       = $self->{form};
 
 428   my $myconfig   = $self->{myconfig};
 
 430   my $opts       = $self->{options};
 
 431   my $pdfopts    = $opts->{pdf_export};
 
 433   my (@data, @column_props, @cell_props);
 
 435   my ($data_row, $cell_props_row);
 
 436   my @visible_columns = $self->get_visible_columns('HTML');
 
 437   my $num_columns     = scalar @visible_columns;
 
 438   my $num_header_rows = 1;
 
 440   my $font_encoding     = $main::dbcharset || 'ISO-8859-15';
 
 441   $self->{text_is_utf8} = $font_encoding =~ m/^utf-?8$/i;
 
 443   foreach $name (@visible_columns) {
 
 444     push @column_props, { 'justify' => $self->{columns}->{$name}->{align} eq 'right' ? 'right' : 'left' };
 
 447   if (!$self->{custom_headers}) {
 
 449     $cell_props_row = [];
 
 450     push @data,       $data_row;
 
 451     push @cell_props, $cell_props_row;
 
 453     foreach $name (@visible_columns) {
 
 454       $column = $self->{columns}->{$name};
 
 456       push @{ $data_row },       $self->_decode_text($column->{text});
 
 457       push @{ $cell_props_row }, {};
 
 461     $num_header_rows = scalar @{ $self->{custom_headers} };
 
 463     foreach my $custom_header_row (@{ $self->{custom_headers} }) {
 
 465       $cell_props_row = [];
 
 466       push @data,       $data_row;
 
 467       push @cell_props, $cell_props_row;
 
 469       foreach my $custom_header_col (@{ $custom_header_row }) {
 
 470         push @{ $data_row }, $self->_decode_text($custom_header_col->{text});
 
 472         my $num_output  = ($custom_header_col->{colspan} * 1 > 1) ? $custom_header_col->{colspan} : 1;
 
 473         if ($num_output > 1) {
 
 474           push @{ $data_row },       ('') x ($num_output - 1);
 
 475           push @{ $cell_props_row }, { 'colspan' => $num_output };
 
 476           push @{ $cell_props_row }, ({ }) x ($num_output - 1);
 
 479           push @{ $cell_props_row }, {};
 
 485   foreach my $row_set (@{ $self->{data} }) {
 
 486     if ('HASH' eq ref $row_set) {
 
 487       if ($row_set->{type} eq 'colspan_data') {
 
 488         push @data, [ $self->_decode_text($row_set->{data}) ];
 
 490         $cell_props_row = [];
 
 491         push @cell_props, $cell_props_row;
 
 493         foreach (0 .. $num_columns - 1) {
 
 494           push @{ $cell_props_row }, { 'background_color' => '#666666',
 
 495                                        'font_color'       => '#ffffff',
 
 496                                        'colspan'          => $_ == 0 ? -1 : undef, };
 
 502     foreach my $row (@{ $row_set }) {
 
 504       $cell_props_row = [];
 
 506       push @data,       $data_row;
 
 507       push @cell_props, $cell_props_row;
 
 510       foreach my $col_name (@visible_columns) {
 
 511         my $col = $row->{$col_name};
 
 512         push @{ $data_row }, $self->_decode_text(join("\n", @{ $col->{data} }));
 
 514         $column_props[$col_idx]->{justify} = 'right' if ($col->{align} eq 'right');
 
 516         my $cell_props = { };
 
 517         push @{ $cell_props_row }, $cell_props;
 
 519         if ($col->{colspan} && $col->{colspan} > 1) {
 
 520           $cell_props->{colspan} = $col->{colspan};
 
 528   foreach my $i (0 .. scalar(@data) - 1) {
 
 529     my $aref             = $data[$i];
 
 530     my $num_columns_here = scalar @{ $aref };
 
 532     if ($num_columns_here < $num_columns) {
 
 533       push @{ $aref }, ('') x ($num_columns - $num_columns_here);
 
 534     } elsif ($num_columns_here > $num_columns) {
 
 535       splice @{ $aref }, $num_columns;
 
 540     'a3'         => [ 842, 1190 ],
 
 541     'a4'         => [ 595,  842 ],
 
 542     'a5'         => [ 420,  595 ],
 
 543     'letter'     => [ 612,  792 ],
 
 544     'legal'      => [ 612, 1008 ],
 
 547   my %supported_fonts = map { $_ => 1 } qw(courier georgia helvetica times verdana);
 
 549   my $paper_size  = defined $pdfopts->{paper_size} && defined $papersizes->{lc $pdfopts->{paper_size}} ? lc $pdfopts->{paper_size} : 'a4';
 
 550   my ($paper_width, $paper_height);
 
 552   if (lc $pdfopts->{orientation} eq 'landscape') {
 
 553     ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[1, 0];
 
 555     ($paper_width, $paper_height) = @{$papersizes->{$paper_size}}[0, 1];
 
 558   my $margin_top        = _cm2bp($pdfopts->{margin_top}    || 1.5);
 
 559   my $margin_bottom     = _cm2bp($pdfopts->{margin_bottom} || 1.5);
 
 560   my $margin_left       = _cm2bp($pdfopts->{margin_left}   || 1.5);
 
 561   my $margin_right      = _cm2bp($pdfopts->{margin_right}  || 1.5);
 
 563   my $table             = PDF::Table->new();
 
 564   my $pdf               = PDF::API2->new();
 
 565   my $page              = $pdf->page();
 
 567   $pdf->mediabox($paper_width, $paper_height);
 
 569   my $font              = $pdf->corefont(defined $pdfopts->{font_name} && $supported_fonts{lc $pdfopts->{font_name}} ? ucfirst $pdfopts->{font_name} : 'Verdana',
 
 570                                          '-encoding' => $font_encoding);
 
 571   my $font_size         = $pdfopts->{font_size} || 7;
 
 572   my $title_font_size   = $font_size + 1;
 
 574   my $font_height       = $font_size + 2 * $padding;
 
 575   my $title_font_height = $font_size + 2 * $padding;
 
 577   my $header_height     = 2 * $title_font_height if ($opts->{title});
 
 578   my $footer_height     = 2 * $font_height       if ($pdfopts->{number});
 
 580   my $top_text_height   = 0;
 
 582   if ($self->{options}->{top_info_text}) {
 
 583     my $top_text     =  $self->_decode_text($self->{options}->{top_info_text});
 
 584     $top_text        =~ s/\r//g;
 
 585     $top_text        =~ s/\n+$//;
 
 587     my @lines        =  split m/\n/, $top_text;
 
 588     $top_text_height =  $font_height * scalar @lines;
 
 590     foreach my $line_no (0 .. scalar(@lines) - 1) {
 
 591       my $y_pos    = $paper_height - $margin_top - $header_height - $line_no * $font_height;
 
 592       my $text_obj = $page->text();
 
 594       $text_obj->font($font, $font_size);
 
 595       $text_obj->translate($margin_left, $y_pos);
 
 596       $text_obj->text($lines[$line_no]);
 
 604                 'w'                     => $paper_width - $margin_left - $margin_right,
 
 605                 'start_y'               => $paper_height - $margin_top                  - $header_height                  - $top_text_height,
 
 606                 'next_y'                => $paper_height - $margin_top                  - $header_height,
 
 607                 'start_h'               => $paper_height - $margin_top - $margin_bottom - $header_height - $footer_height - $top_text_height,
 
 608                 'next_h'                => $paper_height - $margin_top - $margin_bottom - $header_height - $footer_height,
 
 610                 'background_color_odd'  => '#ffffff',
 
 611                 'background_color_even' => '#eeeeee',
 
 613                 'font_size'             => $font_size,
 
 614                 'font_color'            => '#000000',
 
 615                 'num_header_rows'       => $num_header_rows,
 
 617                   'bg_color'            => '#ffffff',
 
 619                   'font_color'          => '#000000',
 
 621                 'column_props'          => \@column_props,
 
 622                 'cell_props'            => \@cell_props,
 
 623                 'max_word_length'       => 60,
 
 626   foreach my $page_num (1..$pdf->pages()) {
 
 627     my $curpage  = $pdf->openpage($page_num);
 
 629     if ($pdfopts->{number}) {
 
 630       my $label    = $self->_decode_text($main::locale->text("Page #1/#2", $page_num, $pdf->pages()));
 
 631       my $text_obj = $curpage->text();
 
 633       $text_obj->font($font, $font_size);
 
 634       $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($label) / 2, $margin_bottom);
 
 635       $text_obj->text($label);
 
 638     if ($opts->{title}) {
 
 639       my $title    = $self->_decode_text($opts->{title});
 
 640       my $text_obj = $curpage->text();
 
 642       $text_obj->font($font, $title_font_size);
 
 643       $text_obj->translate(($paper_width - $margin_left - $margin_right) / 2 + $margin_left - $text_obj->advancewidth($title) / 2,
 
 644                            $paper_height - $margin_top);
 
 645       $text_obj->text($title, '-underline' => 1);
 
 649   my $content = $pdf->stringify();
 
 652   if ($pdfopts->{print} && $pdfopts->{printer_id}) {
 
 653     $form->{printer_id} = $pdfopts->{printer_id};
 
 654     $form->get_printer_code($myconfig);
 
 655     $printer_command = $form->{printer_command};
 
 658   if ($printer_command) {
 
 659     $self->_print_content('printer_command' => $printer_command,
 
 660                           'content'         => $content,
 
 661                           'copies'          => $pdfopts->{copies});
 
 662     $form->{report_generator_printed} = 1;
 
 665     my $filename = $self->get_attachment_basename();
 
 667     print qq|content-type: application/pdf\n|;
 
 668     print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|;
 
 674 sub verify_paper_size {
 
 676   my $requested_paper_size = lc shift;
 
 677   my $default_paper_size   = shift;
 
 679   my %allowed_paper_sizes  = map { $_ => 1 } qw(a3 a4 a5 letter legal);
 
 681   return $allowed_paper_sizes{$requested_paper_size} ? $requested_paper_size : $default_paper_size;
 
 688   foreach my $i (1 .. max $params{copies}, 1) {
 
 689     my $printer = IO::File->new("| $params{printer_command}");
 
 690     $main::form->error($main::locale->text('Could not spawn the printer command.')) if (!$printer);
 
 691     $printer->print($params{content});
 
 696 sub unescape_string {
 
 699   my $iconv = $main::locale->{iconv};
 
 701   $text     = $main::locale->unquote_special_chars('HTML', $text);
 
 702   $text     = $main::locale->{iconv}->convert($text) if ($main::locale->{iconv});
 
 707 sub generate_csv_content {
 
 710   my %valid_sep_chars    = (';' => ';', ',' => ',', ':' => ':', 'TAB' => "\t");
 
 711   my %valid_escape_chars = ('"' => 1, "'" => 1);
 
 712   my %valid_quote_chars  = ('"' => 1, "'" => 1);
 
 714   my $opts        = $self->{options}->{csv_export};
 
 715   my $eol         = $opts->{eol_style} eq 'DOS'               ? "\r\n"                              : "\n";
 
 716   my $sep_char    = $valid_sep_chars{$opts->{sep_char}}       ? $valid_sep_chars{$opts->{sep_char}} : ';';
 
 717   my $escape_char = $valid_escape_chars{$opts->{escape_char}} ? $opts->{escape_char}                : '"';
 
 718   my $quote_char  = $valid_quote_chars{$opts->{quote_char}}   ? $opts->{quote_char}                 : '"';
 
 720   $escape_char    = $quote_char if ($opts->{escape_char} eq 'QUOTE_CHAR');
 
 722   my $csv = Text::CSV_XS->new({ 'binary'      => 1,
 
 723                                 'sep_char'    => $sep_char,
 
 724                                 'escape_char' => $escape_char,
 
 725                                 'quote_char'  => $quote_char,
 
 728   my $stdout          = wraphandle(\*STDOUT);
 
 729   my @visible_columns = $self->get_visible_columns('CSV');
 
 731   if ($opts->{headers}) {
 
 732     if (!$self->{custom_headers}) {
 
 733       $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}) } @visible_columns ]);
 
 736       foreach my $row (@{ $self->{custom_headers} }) {
 
 739         foreach my $col (@{ $row }) {
 
 740           my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
 
 741           push @{ $fields }, ($self->unescape_string($col->{text})) x $num_output;
 
 744         $csv->print($stdout, $fields);
 
 749   foreach my $row_set (@{ $self->{data} }) {
 
 750     next if ('ARRAY' ne ref $row_set);
 
 751     foreach my $row (@{ $row_set }) {
 
 754       foreach my $col (@visible_columns) {
 
 760         my $num_output = ($col->{colspan} && ($col->{colspan} > 1)) ? $col->{colspan} : 1;
 
 761         $skip_next     = $num_output - 1;
 
 763         push @data, join($eol, map { s/\r?\n/$eol/g; $_ } @{ $row->{$col}->{data} });
 
 764         push @data, ('') x $skip_next if ($skip_next);
 
 767       $csv->print($stdout, \@data);
 
 778 SL::ReportGenerator.pm: the Lx-Office way of getting data in shape
 
 782   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
 783      $report->set_options(%options);                         # optional
 
 784      $report->set_columns(%column_defs);
 
 785      $report->set_sort_indicator($column, $direction);       # optional
 
 786      $report->add_data($row1, $row2, @more_rows);
 
 787      $report->generate_with_headers();
 
 789 This creates a report object, sets a few columns, adds some data and generates a standard report. 
 
 790 Sorting of columns will be alphabetic, and options will be set to their defaults.
 
 791 The report will be printed including table headers, html headers and http headers.
 
 795 Imagine the following scenario:
 
 796 There's a simple form, which loads some data from the database, and needs to print it out. You write a template for it.
 
 797 Then there may be more than one line. You add a loop in the template.
 
 798 Then there are some options made by the user, such as hidden columns. You add more to the template.
 
 799 Then it lacks usability. You want it to be able to sort the data. You add code for that.
 
 800 Then there are too many results, you need pagination, you want to print or export that data..... and so on.
 
 802 The ReportGenerator class was designed because this exact scenario happened about half a dozen times in Lx-Office. 
 
 803 It's purpose is to manage all those formating, culling, sorting, and templating. 
 
 804 Which makes it almost as complicated to use as doing the work for yourself.
 
 810 =item new \%myconfig,$form,%options
 
 812 Creates a new ReportGenerator object, sets all given options, and returns it.
 
 814 =item set_columns %columns
 
 816 Sets the columns available to this report.
 
 818 =item set_column_order @columns
 
 820 Sets the order of columns. Any columns not present here are appended in alphabetic order.
 
 822 =item set_sort_indicator $column,$direction
 
 824 Sets sorting ot the table by specifying a column and a direction, where the direction will be evaluated to ascending if true.
 
 825 Note that this is only for displaying. The data has to be presented already sorted.
 
 827 =item add_data \@data
 
 829 =item add_data \%data
 
 831 Adds data to the report. A given hash_ref is interpreted as a single line of data, every array_ref as a collection of lines. 
 
 832 Every line will be expected to be in a kay => value format. Note that the rows have to be already sorted. 
 
 833 ReportGenerator does only colum sorting on its own, and provides links to sorting and visual cue as to which column was sorted by.
 
 837 Adds a separator line to the report.
 
 839 =item add_control \%data
 
 841 Adds a control element to the data. Control elements are an experimental feature to add functionality to a report the regular data cannot.
 
 842 Every control element needs to set IS_CONTROL_DATA, in order to be recongnized by the template. 
 
 843 Currently the only control element is a colspan element, which can be used as a mini header further down the report.
 
 847 Deletes all data filled into the report, but keeps options set.
 
 849 =item set_options %options
 
 851 Sets options. For an incomplete list of options, see section configuration.
 
 853 =item set_options_from_form
 
 855 Tries to import options from the $form object given at creation
 
 857 =item set_export_options $next_sub,@variable_list
 
 859 Sets next_sub and additional variables needed for export.
 
 861 =item get_attachment_basename
 
 863 Returns the set attachment_basename option, or 'report' if nothing was set. See configuration for the option.
 
 865 =item generate_with_headers
 
 867 Parses the report, adds headers and prints it out. Headers depend on the option 'output_format', 
 
 868 for example 'HTML' will add proper table headers, html headers and http headers. See configuration for this option.
 
 870 =item get_visible_columns $format
 
 872 Returns a list of columns that will be visible in the report after considering all options or match the given format.
 
 874 =item html_format $value
 
 876 Escapes HTML characters in $value and substitutes newlines with '<br>'. Returns the escaped $value.
 
 878 =item prepare_html_content $column,$name,@column_headers
 
 880 Parses the data, and sets internal data needed for certain output format. Must be called once before the template is invoked. 
 
 881 Should not be called extrenally, since all render and generate functions invoke it anyway.
 
 883 =item generate_html_content
 
 885 The html generation function. Is invoked by generate_with_headers.
 
 887 =item generate_pdf_content
 
 889 The PDF generation function. It is invoked by generate_with_headers, tests whether or not the Perl module PDF::API2 is installed and calls render_pdf_with_pdf_api2 if it is and render_pdf_with_html2ps otherwise.
 
 891 =item generate_csv_content
 
 893 The CSV generation function. Uses XS_CSV to parse the information into csv.
 
 895 =item render_pdf_with_pdf_api2
 
 897 PDF render function using the Perl module PDF::API2.
 
 899 =item render_pdf_with_html2ps
 
 901 PDF render function using the external application html2ps.
 
 907 These are known options and their defaults. Options for pdf export and csv export need to be set as a hashref inside the export option.
 
 909 =head2 General Options
 
 913 =item std_column_visibility
 
 915 Standard column visibility. Used if no visibility is set. Use this to save the trouble of enabling every column. Default is no.
 
 919 Output format. Used by generate_with_headers to determine the format. Supported options are HTML, CSV, and PDF. Default is HTML.
 
 921 =item allow_pdf_export
 
 923 Used to determine if a button for PDF export should be displayed. Default is yes.
 
 925 =item allow_csv_export
 
 927 Used to determine if a button for CSV export should be displayed. Default is yes.
 
 931 The template to be used for HTML reports. Default is 'report_generator/html_report'.
 
 941 Paper size. Default is a4. Supported paper sizes are a3, a4, a5, letter and legal.
 
 943 =item orientation (landscape)
 
 945 Landscape or portrait. Default is landscape.
 
 949 Default is Verdana. Supported font names are Courier, Georgia, Helvetica, Times and Verdana. This option only affects the rendering with PDF::API2.
 
 953 Default is 7. This option only affects the rendering with PDF::API2.
 
 963 The paper margins in cm. They all default to 1.5.
 
 967 Set to a true value if the pages should be numbered. Default is 1.
 
 971 If set then the resulting PDF will be output to a printer. If not it will be downloaded by the user. Default is no.
 
 989 Character to enclose entries. Default is double quote (").
 
 993 Character to separate entries. Default is semicolon (;).
 
 997 Character to escape the quote_char. Default is double quote (").
 
1001 End of line style. Default is Unix.
 
1005 Include headers? Default is yes.
 
1013 =head1 MODULE AUTHORS
 
1015 Moritz Bunkus E<lt>mbunkus@linet-services.deE<gt>
 
1017 L<http://linet-services.de>