Lines 1-24
Link Here
|
1 |
#!/usr/bin/perl -w |
1 |
#!/usr/bin/perl -w |
2 |
|
2 |
|
3 |
# Copyright 2009 Jesse Weaver |
3 |
use Modern::Perl; |
4 |
# |
|
|
5 |
# This file is part of Koha. |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
use strict; |
21 |
use warnings; |
22 |
|
4 |
|
23 |
BEGIN { |
5 |
BEGIN { |
24 |
# find Koha's Perl modules |
6 |
# find Koha's Perl modules |
Lines 35-69
use C4::Debug;
Link Here
|
35 |
use C4::Letters; |
17 |
use C4::Letters; |
36 |
use C4::Templates; |
18 |
use C4::Templates; |
37 |
use File::Spec; |
19 |
use File::Spec; |
|
|
20 |
use Pod::Usage; |
38 |
use Getopt::Long; |
21 |
use Getopt::Long; |
39 |
use C4::Log; |
22 |
use C4::Log; |
40 |
|
23 |
|
41 |
sub usage { |
24 |
use Koha::DateUtils; |
42 |
print STDERR <<USAGE; |
|
|
43 |
Usage: $0 OUTPUT_DIRECTORY |
44 |
Will print all waiting print notices to |
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 |
48 |
USAGE |
49 |
exit $_[0]; |
50 |
} |
51 |
|
25 |
|
52 |
my ( $stylesheet, $help, $split ); |
26 |
my ( $stylesheet, $help, $split ); |
53 |
|
27 |
|
54 |
GetOptions( |
28 |
GetOptions( |
55 |
'h|help' => \$help, |
29 |
'h|help' => \$help, |
56 |
's|split' => \$split, |
30 |
's|split' => \$split, |
57 |
) || usage(1); |
31 |
) || pod2usage(1); |
58 |
|
32 |
|
59 |
usage(0) if ($help); |
33 |
pod2usage(0) if $help; |
60 |
|
34 |
|
61 |
my $output_directory = $ARGV[0]; |
35 |
my $output_directory = $ARGV[0]; |
62 |
|
36 |
|
63 |
if ( !$output_directory || !-d $output_directory || !-w $output_directory ) { |
37 |
if ( !$output_directory || !-d $output_directory || !-w $output_directory ) { |
64 |
print STDERR |
38 |
pod2usage({ |
65 |
"Error: You must specify a valid and writeable directory to dump the print notices in.\n"; |
39 |
-exitval => 1, |
66 |
usage(1); |
40 |
-msg => qq{\nError: You must specify a valid and writeable directory to dump the print notices in.\n}, |
|
|
41 |
}); |
67 |
} |
42 |
} |
68 |
|
43 |
|
69 |
cronlogaction(); |
44 |
cronlogaction(); |
Lines 82-99
foreach my $message (@all_messages) {
Link Here
|
82 |
|
57 |
|
83 |
my $OUTPUT; |
58 |
my $OUTPUT; |
84 |
|
59 |
|
85 |
if ($split) { |
60 |
print_notices_html({ messages => \@all_messages, split => $split }); |
86 |
my %messages_by_branch; |
61 |
|
87 |
foreach my $message (@all_messages) { |
62 |
sub print_notices_html { |
88 |
push( @{ $messages_by_branch{ $message->{'branchcode'} } }, $message ); |
63 |
my ( $params ) = @_; |
|
|
64 |
|
65 |
my $messages = $params->{messages}; |
66 |
my $split = $params->{split}; |
67 |
|
68 |
my $messages_by_branch; |
69 |
if ( $split ) { |
70 |
foreach my $message (@$messages) { |
71 |
push( @{ $messages_by_branch->{ $message->{'branchcode'} } }, $message ); |
72 |
} |
73 |
} else { |
74 |
$messages_by_branch->{all_branches} = $messages; |
89 |
} |
75 |
} |
90 |
|
76 |
|
91 |
foreach my $branchcode ( keys %messages_by_branch ) { |
77 |
while ( my ( $branchcode, $branch_messages ) = each %$messages_by_branch ) { |
92 |
my @messages = @{ $messages_by_branch{$branchcode} }; |
78 |
my $filename = $split |
93 |
my $output_file = File::Spec->catdir( $output_directory, |
79 |
? 'holdnotices-' . $today->output('iso') . "-$branchcode.html" |
94 |
"holdnotices-" . $today->output('iso') . "-$branchcode.html" ); |
80 |
: 'holdnotices-' . $today->output('iso') . ".html"; |
95 |
open $OUTPUT, '>', $output_file |
|
|
96 |
or die "Could not open $output_file: $!"; |
97 |
|
81 |
|
98 |
my $template = |
82 |
my $template = |
99 |
C4::Templates::gettemplate( 'batch/print-notices.tt', 'intranet', |
83 |
C4::Templates::gettemplate( 'batch/print-notices.tt', 'intranet', |
Lines 102-144
if ($split) {
Link Here
|
102 |
$template->param( |
86 |
$template->param( |
103 |
stylesheet => C4::Context->preference("NoticeCSS"), |
87 |
stylesheet => C4::Context->preference("NoticeCSS"), |
104 |
today => $today->output(), |
88 |
today => $today->output(), |
105 |
messages => \@messages, |
89 |
messages => $branch_messages, |
106 |
); |
90 |
); |
107 |
|
91 |
|
|
|
92 |
my $output_file = File::Spec->catdir( $output_directory, $filename ) |
93 |
open my $OUTPUT, '>', $output_file |
94 |
or die "Could not open $output_file: $!"; |
108 |
print $OUTPUT $template->output; |
95 |
print $OUTPUT $template->output; |
|
|
96 |
close $OUTPUT; |
109 |
|
97 |
|
110 |
foreach my $message (@messages) { |
98 |
foreach my $message ( @$branch_messages ) { |
111 |
C4::Letters::_set_message_status( |
99 |
C4::Letters::_set_message_status( |
112 |
{ message_id => $message->{'message_id'}, status => 'sent' } ); |
100 |
{ |
|
|
101 |
message_id => $message->{'message_id'}, |
102 |
status => 'sent' |
103 |
} |
104 |
); |
113 |
} |
105 |
} |
114 |
|
|
|
115 |
close $OUTPUT; |
116 |
} |
106 |
} |
117 |
} |
107 |
} |
118 |
else { |
|
|
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: $!"; |
123 |
|
108 |
|
|
|
109 |
=head1 NAME |
124 |
|
110 |
|
125 |
my $template = |
111 |
gather_print_notices - Print waiting print notices |
126 |
C4::Templates::gettemplate( 'batch/print-notices.tt', 'intranet', |
|
|
127 |
new CGI ); |
128 |
|
112 |
|
129 |
$template->param( |
113 |
=head1 SYNOPSIS |
130 |
stylesheet => C4::Context->preference("NoticeCSS"), |
|
|
131 |
today => $today->output(), |
132 |
messages => \@all_messages, |
133 |
); |
134 |
|
114 |
|
135 |
print $OUTPUT $template->output; |
115 |
gather_print_notices output_directory [-s|--split] [-h|--help] |
136 |
|
116 |
|
137 |
foreach my $message (@all_messages) { |
117 |
Will print all waiting print notices to the output_directory. |
138 |
C4::Letters::_set_message_status( |
|
|
139 |
{ message_id => $message->{'message_id'}, status => 'sent' } ); |
140 |
} |
141 |
|
118 |
|
142 |
close $OUTPUT; |
119 |
The generated filename will be holdnotices-TODAY.html or holdnotices-TODAY-BRANCHCODE.html if the --split parameter is given. |
143 |
|
120 |
|
144 |
} |
121 |
=head1 OPTIONS |
|
|
122 |
|
123 |
=over |
124 |
|
125 |
=item B<output_directory> |
126 |
|
127 |
Define the output directory where the files will be generated. |
128 |
|
129 |
=item B<-s|--split> |
130 |
|
131 |
Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.html |
132 |
|
133 |
=item B<-h|--help> |
134 |
|
135 |
Print a brief help message |
136 |
|
137 |
=back |
138 |
|
139 |
=head1 AUTHOR |
140 |
|
141 |
Jesse Weaver <pianohacker@gmail.com> |
142 |
|
143 |
Jonathan Druart <jonathan.druart@biblibre.com> |
144 |
|
145 |
=head1 COPYRIGHT |
146 |
|
147 |
Copyright 2009 Jesse Weaver |
148 |
|
149 |
Copyright 2014 BibLibre |
150 |
|
151 |
=head1 LICENSE |
152 |
This file is part of Koha. |
153 |
|
154 |
Koha is free software; you can redistribute it and/or modify it |
155 |
under the terms of the GNU General Public License as published by |
156 |
the Free Software Foundation; either version 3 of the License, or |
157 |
(at your option) any later version. |
158 |
|
159 |
Koha is distributed in the hope that it will be useful, but |
160 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
161 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
162 |
GNU General Public License for more details. |
163 |
|
164 |
You should have received a copy of the GNU General Public License |
165 |
along with Koha; if not, see <http://www.gnu.org/licenses>. |
166 |
|
167 |
=cut |
145 |
- |
|
|