|
Lines 21-34
use strict;
Link Here
|
| 21 |
use warnings; |
21 |
use warnings; |
| 22 |
|
22 |
|
| 23 |
BEGIN { |
23 |
BEGIN { |
| 24 |
|
|
|
| 25 |
# find Koha's Perl modules |
24 |
# find Koha's Perl modules |
| 26 |
# test carefully before changing this |
25 |
# test carefully before changing this |
| 27 |
use FindBin; |
26 |
use FindBin; |
| 28 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
27 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
| 29 |
} |
28 |
} |
| 30 |
|
29 |
|
| 31 |
use CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy |
30 |
use |
|
|
31 |
CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy |
| 32 |
use C4::Context; |
32 |
use C4::Context; |
| 33 |
use C4::Dates; |
33 |
use C4::Dates; |
| 34 |
use C4::Debug; |
34 |
use C4::Debug; |
|
Lines 42-82
sub usage {
Link Here
|
| 42 |
Usage: $0 OUTPUT_DIRECTORY |
42 |
Usage: $0 OUTPUT_DIRECTORY |
| 43 |
Will print all waiting print notices to |
43 |
Will print all waiting print notices to |
| 44 |
OUTPUT_DIRECTORY/notices-CURRENT_DATE.html . |
44 |
OUTPUT_DIRECTORY/notices-CURRENT_DATE.html . |
|
|
45 |
|
| 46 |
-s --split Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html |
| 45 |
USAGE |
47 |
USAGE |
| 46 |
exit $_[0]; |
48 |
exit $_[0]; |
| 47 |
} |
49 |
} |
| 48 |
|
50 |
|
| 49 |
my ( $stylesheet, $help ); |
51 |
my ( $stylesheet, $help, $split ); |
| 50 |
|
52 |
|
| 51 |
GetOptions( |
53 |
GetOptions( |
| 52 |
'h|help' => \$help, |
54 |
'h|help' => \$help, |
| 53 |
) || usage( 1 ); |
55 |
's|split' => \$split, |
|
|
56 |
) || usage(1); |
| 54 |
|
57 |
|
| 55 |
usage( 0 ) if ( $help ); |
58 |
usage(0) if ($help); |
| 56 |
|
59 |
|
| 57 |
my $output_directory = $ARGV[0]; |
60 |
my $output_directory = $ARGV[0]; |
| 58 |
|
61 |
|
| 59 |
if ( !$output_directory || !-d $output_directory ) { |
62 |
if ( !$output_directory || !-d $output_directory ) { |
| 60 |
print STDERR "Error: You must specify a valid directory to dump the print notices in.\n"; |
63 |
print STDERR |
| 61 |
usage( 1 ); |
64 |
"Error: You must specify a valid directory to dump the print notices in.\n"; |
|
|
65 |
usage(1); |
| 66 |
} |
| 67 |
|
| 68 |
my $today = C4::Dates->new(); |
| 69 |
my @all_messages = @{ GetPrintMessages() }; |
| 70 |
exit unless (@all_messages); |
| 71 |
|
| 72 |
if ($split) { |
| 73 |
my %messages_by_branch; |
| 74 |
foreach my $message (@all_messages) { |
| 75 |
push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message ); |
| 76 |
} |
| 77 |
|
| 78 |
foreach my $branchcode ( keys %messages_by_branch ) { |
| 79 |
my @messages = @{ $messages_by_branch{$branchcode} }; |
| 80 |
|
| 81 |
open $OUTPUT, '>', |
| 82 |
File::Spec->catdir( $output_directory, |
| 83 |
"holdnotices-" . $today->output('iso') . "-$branchcode.html" ); |
| 84 |
|
| 85 |
my $template = |
| 86 |
C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', |
| 87 |
new CGI ); |
| 88 |
|
| 89 |
$template->param( |
| 90 |
stylesheet => C4::Context->preference("NoticeCSS"), |
| 91 |
today => $today->output(), |
| 92 |
messages => \@messages, |
| 93 |
); |
| 94 |
|
| 95 |
print $OUTPUT $template->output; |
| 96 |
|
| 97 |
foreach my $message (@messages) { |
| 98 |
C4::Letters::_set_message_status( |
| 99 |
{ message_id => $message->{'message_id'}, status => 'sent' } ); |
| 100 |
} |
| 101 |
|
| 102 |
close $OUTPUT; |
| 103 |
} |
| 62 |
} |
104 |
} |
|
|
105 |
else { |
| 106 |
open $OUTPUT, '>', |
| 107 |
File::Spec->catdir( $output_directory, |
| 108 |
"holdnotices-" . $today->output('iso') . ".html" ); |
| 63 |
|
109 |
|
| 64 |
my $today = C4::Dates->new(); |
110 |
my $template = |
| 65 |
my @messages = @{ GetPrintMessages() }; |
111 |
C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', |
| 66 |
exit unless( @messages ); |
112 |
new CGI ); |
| 67 |
|
113 |
|
| 68 |
open OUTPUT, '>', File::Spec->catdir( $output_directory, "holdnotices-" . $today->output( 'iso' ) . ".html" ); |
114 |
$template->param( |
|
|
115 |
stylesheet => C4::Context->preference("NoticeCSS"), |
| 116 |
today => $today->output(), |
| 117 |
messages => \@all_messages, |
| 118 |
); |
| 69 |
|
119 |
|
| 70 |
my $template = C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet', new CGI ); |
120 |
print $OUTPUT $template->output; |
| 71 |
|
121 |
|
| 72 |
$template->param( |
122 |
foreach my $message (@all_messages) { |
| 73 |
stylesheet => C4::Context->preference("NoticeCSS"), |
123 |
C4::Letters::_set_message_status( |
| 74 |
today => $today->output(), |
124 |
{ message_id => $message->{'message_id'}, status => 'sent' } ); |
| 75 |
messages => \@messages, |
125 |
} |
| 76 |
); |
|
|
| 77 |
|
126 |
|
| 78 |
print OUTPUT $template->output; |
127 |
close $OUTPUT; |
| 79 |
|
128 |
|
| 80 |
foreach my $message ( @messages ) { |
|
|
| 81 |
C4::Letters::_set_message_status( { message_id => $message->{'message_id'}, status => 'sent' } ); |
| 82 |
} |
129 |
} |
| 83 |
- |
|
|