|
Lines 21-28
use Pod::Usage;
Link Here
|
| 21 |
use Getopt::Long; |
21 |
use Getopt::Long; |
| 22 |
use File::Temp qw( tempdir ); |
22 |
use File::Temp qw( tempdir ); |
| 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 101-127
foreach my $message (@all_messages) {
Link Here
|
| 101 |
$message->{'content'} = $_; |
103 |
$message->{'content'} = $_; |
| 102 |
} |
104 |
} |
| 103 |
|
105 |
|
| 104 |
print_notices({ |
106 |
my ( $html_filenames, $csv_filenames, $ods_filenames ); |
|
|
107 |
$html_filenames = print_notices({ |
| 105 |
messages => \@all_messages, |
108 |
messages => \@all_messages, |
| 106 |
split => $split, |
109 |
split => $split, |
| 107 |
output_directory => $output_directory, |
110 |
output_directory => $output_directory, |
| 108 |
format => 'html', |
111 |
format => 'html', |
| 109 |
}) if $html; |
112 |
}) if $html; |
| 110 |
|
113 |
|
| 111 |
print_notices({ |
114 |
$csv_filenames = print_notices({ |
| 112 |
messages => \@all_messages, |
115 |
messages => \@all_messages, |
| 113 |
split => $split, |
116 |
split => $split, |
| 114 |
output_directory => $output_directory, |
117 |
output_directory => $output_directory, |
| 115 |
format => 'csv', |
118 |
format => 'csv', |
| 116 |
}) if $csv; |
119 |
}) if $csv; |
| 117 |
|
120 |
|
| 118 |
print_notices({ |
121 |
$ods_filenames = print_notices({ |
| 119 |
messages => \@all_messages, |
122 |
messages => \@all_messages, |
| 120 |
split => $split, |
123 |
split => $split, |
| 121 |
output_directory => $output_directory, |
124 |
output_directory => $output_directory, |
| 122 |
format => 'ods', |
125 |
format => 'ods', |
| 123 |
}) if $ods; |
126 |
}) if $ods; |
| 124 |
|
127 |
|
|
|
128 |
if ( @emails ) { |
| 129 |
my $files = { |
| 130 |
html => $html_filenames, |
| 131 |
csv => $csv_filenames, |
| 132 |
ods => $ods_filenames, |
| 133 |
}; |
| 134 |
for my $email ( @emails ) { |
| 135 |
send_files({ |
| 136 |
directory => $output_directory, |
| 137 |
files => $files, |
| 138 |
to => $email, |
| 139 |
from => C4::Context->preference('KohaAdminEmailAddress'), # Should be replaced if bug 8000 is pushed |
| 140 |
}); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 125 |
sub print_notices { |
144 |
sub print_notices { |
| 126 |
my ( $params ) = @_; |
145 |
my ( $params ) = @_; |
| 127 |
|
146 |
|
|
Lines 251-263
sub generate_ods {
Link Here
|
| 251 |
|; |
270 |
|; |
| 252 |
} |
271 |
} |
| 253 |
|
272 |
|
|
|
273 |
sub send_files { |
| 274 |
my ( $params ) = @_; |
| 275 |
my $directory = $params->{directory}; |
| 276 |
my $files = $params->{files}; |
| 277 |
my $to = $params->{to}; |
| 278 |
my $from = $params->{from}; |
| 279 |
return unless $to and $from; |
| 280 |
|
| 281 |
my $mail = MIME::Lite->new( |
| 282 |
From => $from, |
| 283 |
To => $to, |
| 284 |
Subject => 'Print notices for ' . $today->output(), |
| 285 |
Type => 'multipart/mixed', |
| 286 |
); |
| 287 |
|
| 288 |
while ( my ( $type, $filenames ) = each %$files ) { |
| 289 |
for my $filename ( @$filenames ) { |
| 290 |
my $mimetype = $type eq 'html' |
| 291 |
? 'text/html' |
| 292 |
: $type eq 'csv' |
| 293 |
? 'text/csv' |
| 294 |
: $type eq 'ods' |
| 295 |
? 'application/vnd.oasis.opendocument.spreadsheet' |
| 296 |
: undef; |
| 297 |
|
| 298 |
next unless $mimetype; |
| 299 |
|
| 300 |
my $filepath = File::Spec->catdir( $directory, $filename ); |
| 301 |
|
| 302 |
next unless $filepath or -f $filepath; |
| 303 |
|
| 304 |
$mail->attach( |
| 305 |
Type => $mimetype, |
| 306 |
Path => $filepath, |
| 307 |
Filename => $filename, |
| 308 |
Encoding => 'base64', |
| 309 |
); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
$mail->send; |
| 314 |
} |
| 315 |
|
| 254 |
=head1 NAME |
316 |
=head1 NAME |
| 255 |
|
317 |
|
| 256 |
gather_print_notices - Print waiting print notices |
318 |
gather_print_notices - Print waiting print notices |
| 257 |
|
319 |
|
| 258 |
=head1 SYNOPSIS |
320 |
=head1 SYNOPSIS |
| 259 |
|
321 |
|
| 260 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-h|--help] |
322 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help] |
| 261 |
|
323 |
|
| 262 |
Will print all waiting print notices to the output_directory. |
324 |
Will print all waiting print notices to the output_directory. |
| 263 |
|
325 |
|
|
Lines 302-307
This is the same as the csv parameter but using csv2odf to generate an ods file
Link Here
|
| 302 |
Filter print messages by letter_code. |
364 |
Filter print messages by letter_code. |
| 303 |
Several letter_code parameters can be given. |
365 |
Several letter_code parameters can be given. |
| 304 |
|
366 |
|
|
|
367 |
=item B<-e|--email> |
| 368 |
|
| 369 |
E-mail address to send generated files. |
| 370 |
|
| 305 |
=item B<-h|--help> |
371 |
=item B<-h|--help> |
| 306 |
|
372 |
|
| 307 |
Print a brief help message |
373 |
Print a brief help message |
| 308 |
- |
|
|