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

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

Return to bug 11678