Lines 2-8
Link Here
|
2 |
|
2 |
|
3 |
# This file is part of Koha. |
3 |
# This file is part of Koha. |
4 |
# |
4 |
# |
5 |
# Copyright (C) 2013 Amit Gupta (amitddng135@gmail.com) |
5 |
# Copyright (C) 2015 Amit Gupta (amitddng135@gmail.com) |
6 |
# |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
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 |
8 |
# under the terms of the GNU General Public License as published by |
Lines 19-39
Link Here
|
19 |
|
19 |
|
20 |
=head1 NAME |
20 |
=head1 NAME |
21 |
|
21 |
|
22 |
membership_expires.pl - cron script to put membership expiry reminders into message queue |
22 |
membership_expiry.pl - cron script to put membership expiry reminder into message queues |
23 |
|
23 |
|
24 |
=head1 SYNOPSIS |
24 |
=head1 SYNOPSIS |
25 |
|
25 |
|
26 |
./membership_expires.pl -c |
26 |
./membership_expiry.pl -c |
27 |
|
27 |
|
28 |
or, in crontab: |
28 |
or, in crontab: |
29 |
|
29 |
|
30 |
0 1 * * * membership_expires.pl -c |
30 |
0 1 * * * membership_expiry.pl -c |
|
|
31 |
|
32 |
=head1 DESCRIPTION |
33 |
|
34 |
This script sends membership expiry reminder notices to patrons. |
35 |
It queues them in the message queue, which is processed by |
36 |
the process_message_queue.pl cronjob. |
31 |
|
37 |
|
32 |
=cut |
38 |
=cut |
33 |
|
39 |
|
34 |
use strict; |
40 |
|
35 |
use warnings; |
41 |
use Modern::Perl; |
36 |
use Getopt::Long; |
42 |
use Getopt::Long; |
|
|
43 |
use Pod::Usage; |
37 |
use Data::Dumper; |
44 |
use Data::Dumper; |
38 |
BEGIN { |
45 |
BEGIN { |
39 |
# find Koha's Perl modules |
46 |
# find Koha's Perl modules |
Lines 47-64
use C4::Letters;
Link Here
|
47 |
use C4::Dates qw/format_date/; |
54 |
use C4::Dates qw/format_date/; |
48 |
use C4::Log; |
55 |
use C4::Log; |
49 |
|
56 |
|
50 |
cronlogaction(); |
57 |
|
|
|
58 |
=head1 NAME |
59 |
|
60 |
membership_expiry.pl - prepare messages to be sent to membership expiry reminder notices to patrons. |
61 |
|
62 |
=head1 SYNOPSIS |
63 |
|
64 |
membership_expiry.pl [-c] |
65 |
|
66 |
=head1 OPTIONS |
67 |
|
68 |
=over 8 |
69 |
|
70 |
=item B<--help> |
71 |
|
72 |
Print a brief help message and exits. |
73 |
|
74 |
=item B<--man> |
75 |
|
76 |
Prints the manual page and exits. |
77 |
|
78 |
=item B<-v> |
79 |
|
80 |
Verbose. Without this flag set, only fatal errors are reported. |
81 |
|
82 |
=item B<-n> |
83 |
|
84 |
Do not send any email. Membership expire notices that would have been sent to |
85 |
the patrons are printed to standard out. |
86 |
|
87 |
=item B<-c> |
88 |
|
89 |
Confirm flag: Add this option. The script will only print a usage |
90 |
statement otherwise. |
91 |
|
92 |
=back |
93 |
|
94 |
=head1 DESCRIPTION |
95 |
|
96 |
This script is designed to alert send membership expire notices |
97 |
|
98 |
=head2 Configuration |
99 |
|
100 |
This script pays attention to send the membership expire notices |
101 |
The content of the messages is configured in Tools -> Notices and slips. Use the MEMBERSHIP_EXPIRY template |
102 |
|
103 |
=head2 Outgoing emails |
104 |
|
105 |
Typically, messages are prepared for each patron when the memberships are going to expire |
106 |
|
107 |
|
108 |
These emails are staged in the outgoing message queue, as are messages |
109 |
produced by other features of Koha. This message queue must be |
110 |
processed regularly by the |
111 |
F<misc/cronjobs/process_message_queue.pl> program. |
112 |
|
113 |
In the event that the C<-n> flag is passed to this program, no emails |
114 |
are sent. Instead, messages are sent on standard output from this |
115 |
program. |
116 |
|
117 |
=head2 Templates |
118 |
|
119 |
Templates can contain variables enclosed in double angle brackets like |
120 |
E<lt>E<lt>thisE<gt>E<gt>. Those variables will be replaced with values |
121 |
specific to the members there membership expiry date is coming. |
122 |
Available variables are: |
123 |
|
124 |
=over |
125 |
|
126 |
=item E<lt>E<lt>borrowers.*E<gt>E<gt> |
127 |
|
128 |
any field from the borrowers table |
129 |
|
130 |
=item E<lt>E<lt>branches.*E<gt>E<gt> |
131 |
|
132 |
any field from the branches table |
133 |
|
134 |
=back |
135 |
|
136 |
=head1 SEE ALSO |
137 |
|
138 |
The F<misc/cronjobs/membership_expiry.pl> program allows you to send |
139 |
messages to patrons when the membership are going to expires. |
140 |
=cut |
51 |
|
141 |
|
52 |
# These are defaults for command line options. |
142 |
# These are defaults for command line options. |
|
|
143 |
|
53 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
144 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
54 |
my $nomail; # -n: No mail. Will not send any emails. |
145 |
my $nomail; # -n: No mail. Will not send any emails. |
55 |
my $verbose= 0; # -v: verbose |
146 |
my $verbose= 0; # -v: verbose |
56 |
|
147 |
|
57 |
GetOptions( 'c' => \$confirm, |
148 |
my $help = 0; |
|
|
149 |
my $man = 0; |
150 |
|
151 |
GetOptions( |
152 |
'help|?' => \$help, |
153 |
'man' => \$man, |
154 |
'c' => \$confirm, |
58 |
'n' => \$nomail, |
155 |
'n' => \$nomail, |
59 |
'v' => \$verbose, |
156 |
'v' => \$verbose, |
60 |
); |
157 |
) or pod2usage(2); |
61 |
|
158 |
pod2usage(1) if $help; |
|
|
159 |
pod2usage( -verbose => 2 ) if $man;; |
62 |
|
160 |
|
63 |
my $usage = << 'ENDUSAGE'; |
161 |
my $usage = << 'ENDUSAGE'; |
64 |
This script prepares for membership expiry reminders to be sent to |
162 |
This script prepares for membership expiry reminders to be sent to |
Lines 67-73
the process_message_queue.pl cronjob.
Link Here
|
67 |
See the comments in the script for directions on changing the script. |
165 |
See the comments in the script for directions on changing the script. |
68 |
This script has the following parameters : |
166 |
This script has the following parameters : |
69 |
-c Confirm and remove this help & warning |
167 |
-c Confirm and remove this help & warning |
70 |
-n send No mail. Instead, all mail messages are printed on screen. Usefull for testing purposes. |
168 |
-n send No mail. Instead, all mail messages are printed on screen. Useful for testing purposes. |
71 |
-v verbose |
169 |
-v verbose |
72 |
ENDUSAGE |
170 |
ENDUSAGE |
73 |
|
171 |
|
Lines 78-83
unless ($confirm) {
Link Here
|
78 |
exit unless (/^y/i); |
176 |
exit unless (/^y/i); |
79 |
} |
177 |
} |
80 |
|
178 |
|
|
|
179 |
cronlogaction(); |
180 |
|
81 |
my $admin_adress = C4::Context->preference('KohaAdminEmailAddress'); |
181 |
my $admin_adress = C4::Context->preference('KohaAdminEmailAddress'); |
82 |
warn 'getting upcoming membership expires' if $verbose; |
182 |
warn 'getting upcoming membership expires' if $verbose; |
83 |
my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); |
183 |
my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); |
Lines 86-92
warn 'found ' . scalar( @$upcoming_mem_expires ) . ' issues' if $verbose;
Link Here
|
86 |
|
186 |
|
87 |
UPCOMINGMEMEXP: foreach my $recent ( @$upcoming_mem_expires ) { |
187 |
UPCOMINGMEMEXP: foreach my $recent ( @$upcoming_mem_expires ) { |
88 |
my $from_address = $recent->{'branchemail'} || $admin_adress; |
188 |
my $from_address = $recent->{'branchemail'} || $admin_adress; |
89 |
my $letter_type = 'MEMEXP'; |
189 |
my $letter_type = 'MEMBERSHIP_EXPIRY'; |
90 |
my $letter = C4::Letters::getletter( 'members', $letter_type, $recent->{'branchcode'} ); |
190 |
my $letter = C4::Letters::getletter( 'members', $letter_type, $recent->{'branchcode'} ); |
91 |
die "no letter of type '$letter_type' found. Please see sample_notices.sql" unless $letter; |
191 |
die "no letter of type '$letter_type' found. Please see sample_notices.sql" unless $letter; |
92 |
|
192 |
|
Lines 123-131
sub parse_letter {
Link Here
|
123 |
} |
223 |
} |
124 |
my $letter = C4::Letters::GetPreparedLetter ( |
224 |
my $letter = C4::Letters::GetPreparedLetter ( |
125 |
module => 'members', |
225 |
module => 'members', |
126 |
letter_code => 'MEMEXP', |
226 |
letter_code => 'MEMBERSHIP_EXPIRY', |
127 |
branchcode => $params->{'branchcode'}, |
227 |
tables => {'borrowers', $params->{'borrowernumber'}, 'branches', $params->{'branchcode'}}, |
128 |
tables => {'borrowers', $params->{'borrowernumber'},}, |
|
|
129 |
); |
228 |
); |
130 |
} |
229 |
} |
131 |
|
230 |
|
132 |
- |
|
|