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