View | Details | Raw Unified | Return to bug 11603
Collapse All | Expand All

(-)a/misc/cronjobs/gather_print_notices.pl (-2 / +68 lines)
Lines 20-25 use Pod::Usage; Link Here
20
use Getopt::Long;
20
use Getopt::Long;
21
use File::Basename qw( dirname );
21
use File::Basename qw( dirname );
22
use Koha::DateUtils;
22
use Koha::DateUtils;
23
use MIME::Lite;
23
24
24
my (
25
my (
25
    $stylesheet,
26
    $stylesheet,
Lines 31-36 my ( Link Here
31
    $delimiter,
32
    $delimiter,
32
    @letter_codes,
33
    @letter_codes,
33
    $send,
34
    $send,
35
    @emails,
34
);
36
);
35
37
36
$send = 1;
38
$send = 1;
Lines 43-48 GetOptions( Link Here
43
    'd|delimiter:s' => \$delimiter,
45
    'd|delimiter:s' => \$delimiter,
44
    'letter_code:s' => \@letter_codes,
46
    'letter_code:s' => \@letter_codes,
45
    'send!'         => \$send,
47
    'send!'         => \$send,
48
    'e|email:s'     => \@emails,
46
) || pod2usage(1);
49
) || pod2usage(1);
47
50
48
pod2usage(0) if $help;
51
pod2usage(0) if $help;
Lines 88-93 my @all_messages = @{ GetPrintMessages() }; Link Here
88
exit unless @all_messages;
91
exit unless @all_messages;
89
92
90
my ( $html_filenames, $csv_filenames, $ods_filenames );
93
my ( $html_filenames, $csv_filenames, $ods_filenames );
94
91
$csv_filenames = print_notices({
95
$csv_filenames = print_notices({
92
    messages => \@all_messages,
96
    messages => \@all_messages,
93
    split => $split,
97
    split => $split,
Lines 119-124 if ( $html ) { Link Here
119
    });
123
    });
120
}
124
}
121
125
126
if ( @emails ) {
127
    my $files = {
128
        html => $html_filenames,
129
        csv  => $csv_filenames,
130
        ods  => $ods_filenames,
131
    };
132
    for my $email ( @emails ) {
133
        send_files({
134
            directory => $output_directory,
135
            files => $files,
136
            to => $email,
137
            from => C4::Context->preference('KohaAdminEmailAddress'), # Should be replaced if bug 8000 is pushed
138
        });
139
    }
140
}
141
122
sub print_notices {
142
sub print_notices {
123
    my ( $params ) = @_;
143
    my ( $params ) = @_;
124
144
Lines 276-288 sub generate_ods { Link Here
276
    $doc->save();
296
    $doc->save();
277
}
297
}
278
298
299
sub send_files {
300
    my ( $params ) = @_;
301
    my $directory = $params->{directory};
302
    my $files = $params->{files};
303
    my $to = $params->{to};
304
    my $from = $params->{from};
305
    return unless $to and $from;
306
307
    my $mail = MIME::Lite->new(
308
        From     => $from,
309
        To       => $to,
310
        Subject  => 'Print notices for ' . $today->output(),
311
        Type     => 'multipart/mixed',
312
    );
313
314
    while ( my ( $type, $filenames ) = each %$files ) {
315
        for my $filename ( @$filenames ) {
316
            my $mimetype = $type eq 'html'
317
                ? 'text/html'
318
                : $type eq 'csv'
319
                    ? 'text/csv'
320
                    : $type eq 'ods'
321
                        ? 'application/vnd.oasis.opendocument.spreadsheet'
322
                        : undef;
323
324
            next unless $mimetype;
325
326
            my $filepath = File::Spec->catdir( $directory, $filename );
327
328
            next unless $filepath or -f $filepath;
329
330
            $mail->attach(
331
              Type     => $mimetype,
332
              Path     => $filepath,
333
              Filename => $filename,
334
              Encoding => 'base64',
335
            );
336
        }
337
    }
338
339
    $mail->send;
340
}
341
279
=head1 NAME
342
=head1 NAME
280
343
281
gather_print_notices - Print waiting print notices
344
gather_print_notices - Print waiting print notices
282
345
283
=head1 SYNOPSIS
346
=head1 SYNOPSIS
284
347
285
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-h|--help]
348
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help]
286
349
287
Will print all waiting print notices to the output_directory.
350
Will print all waiting print notices to the output_directory.
288
351
Lines 333-338 This is the same as the csv parameter but using csv2odf to generate an ods file Link Here
333
Filter print messages by letter_code.
396
Filter print messages by letter_code.
334
Several letter_code parameters can be given.
397
Several letter_code parameters can be given.
335
398
399
=item B<-e|--email>
400
401
E-mail address to send generated files.
402
336
=item B<-h|--help>
403
=item B<-h|--help>
337
404
338
Print a brief help message
405
Print a brief help message
339
- 

Return to bug 11603