3 # Copyright 2009 Jesse Weaver
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 # find Koha's Perl modules
25 # test carefully before changing this
27 eval { require "$FindBin::Bin/../kohalib.pl" };
31 CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
43 Usage: $0 OUTPUT_DIRECTORY
44 Will print all waiting print notices to
45 OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
47 -s --split Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
52 my ( $stylesheet, $help, $split );
61 my $output_directory = $ARGV[0];
63 if ( !$output_directory || !-d $output_directory || !-w $output_directory ) {
65 "Error: You must specify a valid and writeable directory to dump the print notices in.\n";
71 my $today = C4::Dates->new();
72 my @all_messages = @{ GetPrintMessages() };
73 exit unless (@all_messages);
75 ## carriage return replaced by <br/> as output is html
76 foreach my $message (@all_messages) {
77 local $_ = $message->{'content'};
80 $message->{'content'} = $_;
86 my %messages_by_branch;
87 foreach my $message (@all_messages) {
88 push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message );
91 foreach my $branchcode ( keys %messages_by_branch ) {
92 my @messages = @{ $messages_by_branch{$branchcode} };
93 my $output_file = File::Spec->catdir( $output_directory,
94 "holdnotices-" . $today->output('iso') . "-$branchcode.html" );
95 open $OUTPUT, '>', $output_file
96 or die "Could not open $output_file: $!";
99 C4::Templates::gettemplate( 'batch/print-notices.tt', 'intranet',
103 stylesheet => C4::Context->preference("NoticeCSS"),
104 today => $today->output(),
105 messages => \@messages,
108 print $OUTPUT $template->output;
110 foreach my $message (@messages) {
111 C4::Letters::_set_message_status(
112 { message_id => $message->{'message_id'}, status => 'sent' } );
119 my $output_file = File::Spec->catdir( $output_directory,
120 "holdnotices-" . $today->output('iso') . ".html" );
121 open $OUTPUT, '>', $output_file
122 or die "Could not open $output_file: $!";
126 C4::Templates::gettemplate( 'batch/print-notices.tt', 'intranet',
130 stylesheet => C4::Context->preference("NoticeCSS"),
131 today => $today->output(),
132 messages => \@all_messages,
135 print $OUTPUT $template->output;
137 foreach my $message (@all_messages) {
138 C4::Letters::_set_message_status(
139 { message_id => $message->{'message_id'}, status => 'sent' } );