Revision 49f0957f
Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt
SL/ReportGenerator.pm | ||
---|---|---|
1 | 1 |
package SL::ReportGenerator; |
2 | 2 |
|
3 | 3 |
use IO::Wrap; |
4 |
use List::Util qw(max); |
|
4 | 5 |
use Text::CSV_XS; |
5 | 6 |
|
6 | 7 |
use SL::Form; |
... | ... | |
28 | 29 |
'margin_bottom' => 1.5, |
29 | 30 |
'margin_right' => 1.5, |
30 | 31 |
'number' => 1, |
32 |
'print' => 0, |
|
33 |
'printer_id' => 0, |
|
34 |
'copies' => 1, |
|
31 | 35 |
}, |
32 | 36 |
'csv_export' => { |
33 | 37 |
'quote_char' => '"', |
... | ... | |
154 | 158 |
}; |
155 | 159 |
} |
156 | 160 |
|
157 |
sub generate_content { |
|
158 |
my $self = shift; |
|
159 |
my $format = lc $self->{options}->{output_format}; |
|
160 |
|
|
161 |
if (!$self->{columns}) { |
|
162 |
$self->{form}->error('Incorrect usage -- no columns specified'); |
|
163 |
} |
|
164 |
|
|
165 |
if ($format eq 'html') { |
|
166 |
return $self->generate_html_content(); |
|
167 |
|
|
168 |
} elsif ($format eq 'csv') { |
|
169 |
return $self->generate_csv_content(); |
|
170 |
|
|
171 |
} elsif ($format eq 'pdf') { |
|
172 |
return $self->generate_pdf_content(); |
|
173 |
|
|
174 |
} else { |
|
175 |
$self->{form}->error('Incorrect usage -- unknown format (supported are HTML, CSV, PDF)'); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 | 161 |
sub generate_with_headers { |
180 | 162 |
my $self = shift; |
181 | 163 |
my $format = lc $self->{options}->{output_format}; |
... | ... | |
199 | 181 |
$self->generate_csv_content(); |
200 | 182 |
|
201 | 183 |
} elsif ($format eq 'pdf') { |
202 |
print qq|content-type: application/pdf\n|; |
|
203 |
print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|; |
|
204 | 184 |
$self->generate_pdf_content(); |
205 | 185 |
|
206 | 186 |
} else { |
... | ... | |
368 | 348 |
END |
369 | 349 |
; |
370 | 350 |
|
351 |
my $printer_command; |
|
352 |
if ($opt->{print} && $opt->{printer_id}) { |
|
353 |
$form->{printer_id} = $opt->{printer_id}; |
|
354 |
$form->get_printer_code($myconfig); |
|
355 |
$printer_command = $form->{printer_command}; |
|
356 |
} |
|
357 |
|
|
371 | 358 |
my $cfg_file_name = Common::tmpname() . '-html2ps-config'; |
372 | 359 |
my $cfg_file = IO::File->new($cfg_file_name, 'w') || $form->error($locale->text('Could not write the html2ps config file.')); |
373 | 360 |
|
... | ... | |
391 | 378 |
|
392 | 379 |
my $gs = IO::File->new("${cmdline} |"); |
393 | 380 |
if ($gs) { |
394 |
while (my $line = <$gs>) { |
|
395 |
print $line; |
|
381 |
my $content; |
|
382 |
|
|
383 |
if (!$printer_command) { |
|
384 |
print qq|content-type: application/pdf\n|; |
|
385 |
print qq|content-disposition: attachment; filename=${filename}.pdf\n\n|; |
|
386 |
|
|
387 |
while (my $line = <$gs>) { |
|
388 |
print $line; |
|
389 |
} |
|
390 |
|
|
391 |
} else { |
|
392 |
while (my $line = <$gs>) { |
|
393 |
$content .= $line; |
|
394 |
} |
|
396 | 395 |
} |
396 |
|
|
397 | 397 |
$gs->close(); |
398 | 398 |
unlink $cfg_file_name, $html_file_name; |
399 | 399 |
|
400 |
if ($printer_command && $content) { |
|
401 |
foreach my $i (1 .. max $opt->{copies}, 1) { |
|
402 |
my $printer = IO::File->new("| ${printer_command}"); |
|
403 |
if (!$printer) { |
|
404 |
$form->error($locale->text('Could not spawn the printer command.')); |
|
405 |
} |
|
406 |
$printer->print($content); |
|
407 |
$printer->close(); |
|
408 |
} |
|
409 |
|
|
410 |
$form->{report_generator_printed} = 1; |
|
411 |
} |
|
412 |
|
|
400 | 413 |
} else { |
401 | 414 |
unlink $cfg_file_name, $html_file_name; |
402 | 415 |
$form->error($locale->text('Could not spawn html2ps or GhostScript.')); |
Auch abrufbar als: Unified diff
Reportgenerator: Beim Listenexport als PDF kann das PDF auch direkt ausgedruckt werden.