Lines 47-77
runreport.pl - Run pre-existing saved reports
Link Here
|
47 |
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] |
47 |
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] |
48 |
|
48 |
|
49 |
Options: |
49 |
Options: |
50 |
-h --help brief help message |
50 |
-h --help brief help message |
51 |
-m --man full documentation, same as --help --verbose |
51 |
-m --man full documentation, same as --help --verbose |
52 |
-v --verbose verbose output |
52 |
-v --verbose verbose output |
53 |
|
53 |
|
54 |
--format=s selects format. Choice of text, html, csv or tsv |
54 |
--format=s selects format. Choice of text, html, csv or tsv |
55 |
|
55 |
|
56 |
-e --email whether to use e-mail (implied by --to or --from) |
56 |
-e --email whether to use e-mail (implied by --to or --from) |
57 |
--send_empty whether to send an email when there are no results from the |
57 |
--send_empty whether to send an email when there are no results from the |
58 |
specified report |
58 |
specified report |
59 |
-a --attachment additionally attach the report as a file. cannot be used with html format |
59 |
-a --attachment additionally attach the report as a file. cannot be used with html format |
60 |
--username username to pass to the SMTP server for authentication |
60 |
-ao --attach_only additionally only send the results as attachment, not in message body |
61 |
--password password to pass to the SMTP server for authentication |
61 |
--username username to pass to the SMTP server for authentication |
62 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
62 |
--password password to pass to the SMTP server for authentication |
63 |
--to=s e-mail address to send report to |
63 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
64 |
--from=s e-mail address to send report from |
64 |
--to=s e-mail address to send report to |
65 |
--subject=s subject for the e-mail |
65 |
--from=s e-mail address to send report from |
66 |
--param=s parameters for the report |
66 |
--subject=s subject for the e-mail |
67 |
--store-results store the result of the report |
67 |
--param=s parameters for the report |
68 |
--separator separator character for csv |
68 |
--store-results store the result of the report |
69 |
--quote quote character for csv |
69 |
--separator separator character for csv |
70 |
--csv-header add column names as first line of csv output |
70 |
--quote quote character for csv |
|
|
71 |
--csv-header add column names as first line of csv output |
71 |
|
72 |
|
72 |
|
73 |
|
73 |
Arguments: |
74 |
Arguments: |
74 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
75 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
75 |
|
76 |
|
76 |
=head1 OPTIONS |
77 |
=head1 OPTIONS |
77 |
|
78 |
|
Lines 106-111
Empty string is allowed.
Link Here
|
106 |
|
107 |
|
107 |
Whether to use e-mail (implied by --to or --from). |
108 |
Whether to use e-mail (implied by --to or --from). |
108 |
|
109 |
|
|
|
110 |
=item B<--attachment> |
111 |
|
112 |
Whether to include the results as an attachment (requires --email|--to|--from) |
113 |
|
114 |
=item B<--attach_only> |
115 |
|
116 |
Whether to use include the results as an attachment (implies --attachment) |
117 |
|
109 |
=item B<--username> |
118 |
=item B<--username> |
110 |
|
119 |
|
111 |
Username to pass to the SMTP server for authentication |
120 |
Username to pass to the SMTP server for authentication |
Lines 188-193
my $verbose = 0;
Link Here
|
188 |
my $send_email = 0; |
197 |
my $send_email = 0; |
189 |
my $send_empty = 0; |
198 |
my $send_empty = 0; |
190 |
my $attachment = 0; |
199 |
my $attachment = 0; |
|
|
200 |
my $attach_only = 0; |
191 |
my $format = "text"; |
201 |
my $format = "text"; |
192 |
my $to = ""; |
202 |
my $to = ""; |
193 |
my $from = ""; |
203 |
my $from = ""; |
Lines 207-230
my $method = 'LOGIN';
Link Here
|
207 |
my $command_line_options = join(" ",@ARGV); |
217 |
my $command_line_options = join(" ",@ARGV); |
208 |
|
218 |
|
209 |
GetOptions( |
219 |
GetOptions( |
210 |
'help|?' => \$help, |
220 |
'help|?' => \$help, |
211 |
'man' => \$man, |
221 |
'man' => \$man, |
212 |
'verbose' => \$verbose, |
222 |
'verbose' => \$verbose, |
213 |
'format=s' => \$format, |
223 |
'format=s' => \$format, |
214 |
'separator=s' => \$csv_separator, |
224 |
'separator=s' => \$csv_separator, |
215 |
'quote=s' => \$csv_quote, |
225 |
'quote=s' => \$csv_quote, |
216 |
'to=s' => \$to, |
226 |
'to=s' => \$to, |
217 |
'from=s' => \$from, |
227 |
'from=s' => \$from, |
218 |
'subject=s' => \$subject, |
228 |
'subject=s' => \$subject, |
219 |
'param=s' => \@params, |
229 |
'param=s' => \@params, |
220 |
'email' => \$send_email, |
230 |
'email' => \$send_email, |
221 |
'send_empty' => \$send_empty, |
231 |
'send_empty' => \$send_empty, |
222 |
'a|attachment' => \$attachment, |
232 |
'a|attachment' => \$attachment, |
223 |
'username:s' => \$username, |
233 |
'ao|attach_only' => \$attach_only, |
224 |
'password:s' => \$password, |
234 |
'username:s' => \$username, |
225 |
'method:s' => \$method, |
235 |
'password:s' => \$password, |
226 |
'store-results' => \$store_results, |
236 |
'method:s' => \$method, |
227 |
'csv-header' => \$csv_header, |
237 |
'store-results' => \$store_results, |
|
|
238 |
'csv-header' => \$csv_header, |
228 |
|
239 |
|
229 |
) or pod2usage(2); |
240 |
) or pod2usage(2); |
230 |
pod2usage( -verbose => 2 ) if ($man); |
241 |
pod2usage( -verbose => 2 ) if ($man); |
Lines 238-243
unless ($format) {
Link Here
|
238 |
$format = 'text'; |
249 |
$format = 'text'; |
239 |
} |
250 |
} |
240 |
|
251 |
|
|
|
252 |
$attachment = 1 if $attach_only; |
253 |
|
241 |
if ($csv_separator) { |
254 |
if ($csv_separator) { |
242 |
if ( $format eq 'csv' ) { |
255 |
if ( $format eq 'csv' ) { |
243 |
$separator = "$csv_separator"; |
256 |
$separator = "$csv_separator"; |
Lines 364-377
foreach my $report_id (@ARGV) {
Link Here
|
364 |
} |
377 |
} |
365 |
); |
378 |
); |
366 |
|
379 |
|
367 |
if ( $format eq 'html' ) { |
|
|
368 |
$message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; |
369 |
$email->html_body($message); |
370 |
} |
371 |
else { |
372 |
$email->text_body($message); |
373 |
} |
374 |
|
375 |
$email->attach( |
380 |
$email->attach( |
376 |
Encode::encode_utf8($message), |
381 |
Encode::encode_utf8($message), |
377 |
content_type => "text/$format", |
382 |
content_type => "text/$format", |
Lines 379-384
foreach my $report_id (@ARGV) {
Link Here
|
379 |
disposition => 'attachment', |
384 |
disposition => 'attachment', |
380 |
) if $attachment; |
385 |
) if $attachment; |
381 |
|
386 |
|
|
|
387 |
if ( $attach_only && $count ){ |
388 |
$message = 'Report results attached to email'; |
389 |
} |
390 |
elsif ( $format eq 'html' ) { |
391 |
$message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; |
392 |
$email->html_body($message); |
393 |
} |
394 |
else { |
395 |
$email->text_body($message); |
396 |
} |
397 |
|
382 |
my $smtp_server = Koha::SMTP::Servers->get_default; |
398 |
my $smtp_server = Koha::SMTP::Servers->get_default; |
383 |
$smtp_server->set( |
399 |
$smtp_server->set( |
384 |
{ |
400 |
{ |
385 |
- |
|
|