Lines 21-28
use Pod::Usage;
Link Here
|
21 |
use Getopt::Long; |
21 |
use Getopt::Long; |
22 |
use File::Basename qw( dirname ); |
22 |
use File::Basename qw( dirname ); |
23 |
use Koha::DateUtils; |
23 |
use Koha::DateUtils; |
|
|
24 |
use MIME::Lite; |
24 |
|
25 |
|
25 |
my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes ); |
26 |
my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes, @emails ); |
26 |
|
27 |
|
27 |
GetOptions( |
28 |
GetOptions( |
28 |
'h|help' => \$help, |
29 |
'h|help' => \$help, |
Lines 32-37
GetOptions(
Link Here
|
32 |
'ods' => \$ods, |
33 |
'ods' => \$ods, |
33 |
'd|delimiter:s' => \$delimiter, |
34 |
'd|delimiter:s' => \$delimiter, |
34 |
'letter_code:s' => \@letter_codes, |
35 |
'letter_code:s' => \@letter_codes, |
|
|
36 |
'e|email:s' => \@emails, |
35 |
) || pod2usage(1); |
37 |
) || pod2usage(1); |
36 |
|
38 |
|
37 |
pod2usage(0) if $help; |
39 |
pod2usage(0) if $help; |
Lines 77-82
my @all_messages = @{ GetPrintMessages() };
Link Here
|
77 |
exit unless @all_messages; |
79 |
exit unless @all_messages; |
78 |
|
80 |
|
79 |
my ( $html_filenames, $csv_filenames, $ods_filenames ); |
81 |
my ( $html_filenames, $csv_filenames, $ods_filenames ); |
|
|
82 |
|
80 |
$csv_filenames = print_notices({ |
83 |
$csv_filenames = print_notices({ |
81 |
messages => \@all_messages, |
84 |
messages => \@all_messages, |
82 |
split => $split, |
85 |
split => $split, |
Lines 108-113
if ( $html ) {
Link Here
|
108 |
}); |
111 |
}); |
109 |
} |
112 |
} |
110 |
|
113 |
|
|
|
114 |
if ( @emails ) { |
115 |
my $files = { |
116 |
html => $html_filenames, |
117 |
csv => $csv_filenames, |
118 |
ods => $ods_filenames, |
119 |
}; |
120 |
for my $email ( @emails ) { |
121 |
send_files({ |
122 |
directory => $output_directory, |
123 |
files => $files, |
124 |
to => $email, |
125 |
from => C4::Context->preference('KohaAdminEmailAddress'), # Should be replaced if bug 8000 is pushed |
126 |
}); |
127 |
} |
128 |
} |
129 |
|
111 |
sub print_notices { |
130 |
sub print_notices { |
112 |
my ( $params ) = @_; |
131 |
my ( $params ) = @_; |
113 |
|
132 |
|
Lines 263-275
sub generate_ods {
Link Here
|
263 |
$doc->save(); |
282 |
$doc->save(); |
264 |
} |
283 |
} |
265 |
|
284 |
|
|
|
285 |
sub send_files { |
286 |
my ( $params ) = @_; |
287 |
my $directory = $params->{directory}; |
288 |
my $files = $params->{files}; |
289 |
my $to = $params->{to}; |
290 |
my $from = $params->{from}; |
291 |
return unless $to and $from; |
292 |
|
293 |
my $mail = MIME::Lite->new( |
294 |
From => $from, |
295 |
To => $to, |
296 |
Subject => 'Print notices for ' . $today->output(), |
297 |
Type => 'multipart/mixed', |
298 |
); |
299 |
|
300 |
while ( my ( $type, $filenames ) = each %$files ) { |
301 |
for my $filename ( @$filenames ) { |
302 |
my $mimetype = $type eq 'html' |
303 |
? 'text/html' |
304 |
: $type eq 'csv' |
305 |
? 'text/csv' |
306 |
: $type eq 'ods' |
307 |
? 'application/vnd.oasis.opendocument.spreadsheet' |
308 |
: undef; |
309 |
|
310 |
next unless $mimetype; |
311 |
|
312 |
my $filepath = File::Spec->catdir( $directory, $filename ); |
313 |
|
314 |
next unless $filepath or -f $filepath; |
315 |
|
316 |
$mail->attach( |
317 |
Type => $mimetype, |
318 |
Path => $filepath, |
319 |
Filename => $filename, |
320 |
Encoding => 'base64', |
321 |
); |
322 |
} |
323 |
} |
324 |
|
325 |
$mail->send; |
326 |
} |
327 |
|
266 |
=head1 NAME |
328 |
=head1 NAME |
267 |
|
329 |
|
268 |
gather_print_notices - Print waiting print notices |
330 |
gather_print_notices - Print waiting print notices |
269 |
|
331 |
|
270 |
=head1 SYNOPSIS |
332 |
=head1 SYNOPSIS |
271 |
|
333 |
|
272 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-h|--help] |
334 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help] |
273 |
|
335 |
|
274 |
Will print all waiting print notices to the output_directory. |
336 |
Will print all waiting print notices to the output_directory. |
275 |
|
337 |
|
Lines 314-319
This is the same as the csv parameter but using csv2odf to generate an ods file
Link Here
|
314 |
Filter print messages by letter_code. |
376 |
Filter print messages by letter_code. |
315 |
Several letter_code parameters can be given. |
377 |
Several letter_code parameters can be given. |
316 |
|
378 |
|
|
|
379 |
=item B<-e|--email> |
380 |
|
381 |
E-mail address to send generated files. |
382 |
|
317 |
=item B<-h|--help> |
383 |
=item B<-h|--help> |
318 |
|
384 |
|
319 |
Print a brief help message |
385 |
Print a brief help message |
320 |
- |
|
|