Bug 11316 - plugin icon missing tooltip in addbiblio.pl
[koha.git] / misc / cronjobs / gather_print_notices.pl
blob248716e339bd372e515bab7465b68147f2b89d82
1 #!/usr/bin/perl -w
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 BEGIN {
24 # find Koha's Perl modules
25 # test carefully before changing this
26 use FindBin;
27 eval { require "$FindBin::Bin/../kohalib.pl" };
30 use
31 CGI; # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy
32 use C4::Context;
33 use C4::Dates;
34 use C4::Debug;
35 use C4::Letters;
36 use C4::Templates;
37 use File::Spec;
38 use Getopt::Long;
40 sub usage {
41 print STDERR <<USAGE;
42 Usage: $0 OUTPUT_DIRECTORY
43 Will print all waiting print notices to
44 OUTPUT_DIRECTORY/notices-CURRENT_DATE.html .
46 -s --split Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html
47 USAGE
48 exit $_[0];
51 my ( $stylesheet, $help, $split );
53 GetOptions(
54 'h|help' => \$help,
55 's|split' => \$split,
56 ) || usage(1);
58 usage(0) if ($help);
60 my $output_directory = $ARGV[0];
62 if ( !$output_directory || !-d $output_directory || !-w $output_directory ) {
63 print STDERR
64 "Error: You must specify a valid and writeable directory to dump the print notices in.\n";
65 usage(1);
68 my $today = C4::Dates->new();
69 my @all_messages = @{ GetPrintMessages() };
70 exit unless (@all_messages);
72 ## carriage return replaced by <br/> as output is html
73 foreach my $message (@all_messages) {
74 local $_ = $message->{'content'};
75 s/\n/<br \/>/g;
76 s/\r//g;
77 $message->{'content'} = $_;
80 my $OUTPUT;
82 if ($split) {
83 my %messages_by_branch;
84 foreach my $message (@all_messages) {
85 push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message );
88 foreach my $branchcode ( keys %messages_by_branch ) {
89 my @messages = @{ $messages_by_branch{$branchcode} };
90 my $output_file = File::Spec->catdir( $output_directory,
91 "holdnotices-" . $today->output('iso') . "-$branchcode.html" );
92 open $OUTPUT, '>', $output_file
93 or die "Could not open $output_file: $!";
95 my $template =
96 C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
97 new CGI );
99 $template->param(
100 stylesheet => C4::Context->preference("NoticeCSS"),
101 today => $today->output(),
102 messages => \@messages,
105 print $OUTPUT $template->output;
107 foreach my $message (@messages) {
108 C4::Letters::_set_message_status(
109 { message_id => $message->{'message_id'}, status => 'sent' } );
112 close $OUTPUT;
115 else {
116 my $output_file = File::Spec->catdir( $output_directory,
117 "holdnotices-" . $today->output('iso') . ".html" );
118 open $OUTPUT, '>', $output_file
119 or die "Could not open $output_file: $!";
122 my $template =
123 C4::Templates::gettemplate( 'batch/print-notices.tmpl', 'intranet',
124 new CGI );
126 $template->param(
127 stylesheet => C4::Context->preference("NoticeCSS"),
128 today => $today->output(),
129 messages => \@all_messages,
132 print $OUTPUT $template->output;
134 foreach my $message (@all_messages) {
135 C4::Letters::_set_message_status(
136 { message_id => $message->{'message_id'}, status => 'sent' } );
139 close $OUTPUT;