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.')); |
bin/mozilla/report_generator.pl | ||
---|---|---|
9 | 9 |
# |
10 | 10 |
###################################################################### |
11 | 11 |
|
12 |
use List::Util qw(max); |
|
13 |
|
|
12 | 14 |
use SL::Form; |
13 | 15 |
use SL::Common; |
14 | 16 |
use SL::MoreCommon; |
... | ... | |
18 | 20 |
$lxdebug->enter_sub(); |
19 | 21 |
|
20 | 22 |
if ($form->{report_generator_pdf_options_set}) { |
23 |
my $saved_form = save_form(); |
|
24 |
|
|
21 | 25 |
report_generator_do('PDF'); |
26 |
|
|
27 |
if ($form->{report_generator_printed}) { |
|
28 |
restore_form($saved_form); |
|
29 |
$form->{MESSAGE} = $locale->text('The list has been printed.'); |
|
30 |
report_generator_do('HTML'); |
|
31 |
} |
|
32 |
|
|
22 | 33 |
$lxdebug->leave_sub(); |
23 | 34 |
return; |
24 | 35 |
} |
... | ... | |
26 | 37 |
my @form_values; |
27 | 38 |
map { push @form_values, { 'key' => $_, 'value' => $form->{$_} } } keys %{ $form }; |
28 | 39 |
|
40 |
$form->get_lists('printers' => 'ALL_PRINTERS'); |
|
41 |
map { $_->{selected} = $myconfig{default_printer_id} == $_->{id} } @{ $form->{ALL_PRINTERS} }; |
|
42 |
|
|
43 |
$form->{copies} = max $myconfig{copies} * 1, 1; |
|
44 |
|
|
29 | 45 |
$form->{title} = $locale->text('PDF export -- options'); |
30 | 46 |
$form->header(); |
31 | 47 |
print $form->parse_html_template('report_generator/pdf_export_options', |
32 | 48 |
{ 'HIDDEN' => \@form_values, |
33 |
'default_margin' => $form->format_amount(\%myconfig, 1.5) }); |
|
49 |
'default_margin' => $form->format_amount(\%myconfig, 1.5), |
|
50 |
'SHOW_PRINTERS' => scalar @{ $form->{ALL_PRINTERS} }, |
|
51 |
}); |
|
34 | 52 |
|
35 | 53 |
$lxdebug->leave_sub(); |
36 | 54 |
} |
locale/de/all | ||
---|---|---|
874 | 874 |
'Print' => 'Drucken', |
875 | 875 |
'Print and Post' => 'Drucken und Buchen', |
876 | 876 |
'Print dunnings' => 'Mahnungen drucken', |
877 |
'Print list' => 'Liste ausdrucken', |
|
877 | 878 |
'Print options' => 'Druckoptionen', |
878 | 879 |
'Printer' => 'Drucker', |
879 | 880 |
'Printer Command' => 'Druckbefehl', |
templates/webpages/report_generator/pdf_export_options_de.html | ||
---|---|---|
72 | 72 |
<td valign="top"> |
73 | 73 |
<input type="checkbox" name="report_generator_pdf_options_number" value="1" checked> |
74 | 74 |
Seiten nummerieren |
75 |
<TMPL_IF SHOW_PRINTERS> |
|
76 |
<br> |
|
77 |
<input type="checkbox" name="report_generator_pdf_options_print" value="1"> |
|
78 |
Liste ausdrucken |
|
79 |
</TMPL_IF> |
|
75 | 80 |
</td> |
76 | 81 |
</tr> |
77 | 82 |
|
78 |
|
|
83 |
<TMPL_IF SHOW_PRINTERS> |
|
84 |
<tr> |
|
85 |
<td align="right">Drucker</td> |
|
86 |
<td> |
|
87 |
<select name="report_generator_pdf_options_printer_id"> |
|
88 |
<TMPL_LOOP ALL_PRINTERS><option value="<TMPL_VAR id ESCAPE=HTML>"<TMPL_IF selected> selected</TMPL_IF>><TMPL_VAR printer_description ESCAPE=HTML></option></TMPL_LOOP> |
|
89 |
</select> |
|
90 |
</td> |
|
91 |
</tr> |
|
92 |
|
|
93 |
<tr> |
|
94 |
<td align="right">Kopien</td> |
|
95 |
<td><input name="report_generator_pdf_options_copies" size="4" value="<TMPL_VAR copies ESCAPE=HTML>"></td> |
|
96 |
</tr> |
|
97 |
</TMPL_IF> |
|
79 | 98 |
</table> |
80 | 99 |
|
81 | 100 |
<p> |
templates/webpages/report_generator/pdf_export_options_master.html | ||
---|---|---|
72 | 72 |
<td valign="top"> |
73 | 73 |
<input type="checkbox" name="report_generator_pdf_options_number" value="1" checked> |
74 | 74 |
<translate>Number pages</translate> |
75 |
<TMPL_IF SHOW_PRINTERS> |
|
76 |
<br> |
|
77 |
<input type="checkbox" name="report_generator_pdf_options_print" value="1"> |
|
78 |
<translate>Print list</translate> |
|
79 |
</TMPL_IF> |
|
75 | 80 |
</td> |
76 | 81 |
</tr> |
77 | 82 |
|
78 |
|
|
83 |
<TMPL_IF SHOW_PRINTERS> |
|
84 |
<tr> |
|
85 |
<td align="right"><translate>Printer</translate></td> |
|
86 |
<td> |
|
87 |
<select name="report_generator_pdf_options_printer_id"> |
|
88 |
<TMPL_LOOP ALL_PRINTERS><option value="<TMPL_VAR id ESCAPE=HTML>"<TMPL_IF selected> selected</TMPL_IF>><TMPL_VAR printer_description ESCAPE=HTML></option></TMPL_LOOP> |
|
89 |
</select> |
|
90 |
</td> |
|
91 |
</tr> |
|
92 |
|
|
93 |
<tr> |
|
94 |
<td align="right"><translate>Copies</translate></td> |
|
95 |
<td><input name="report_generator_pdf_options_copies" size="4" value="<TMPL_VAR copies ESCAPE=HTML>"></td> |
|
96 |
</tr> |
|
97 |
</TMPL_IF> |
|
79 | 98 |
</table> |
80 | 99 |
|
81 | 100 |
<p> |
Auch abrufbar als: Unified diff
Reportgenerator: Beim Listenexport als PDF kann das PDF auch direkt ausgedruckt werden.