Bug 30477: Add new UNIMARC installer translation files
[koha.git] / members / notices.pl
1 #!/usr/bin/perl
2
3 # Displays sent notices for a given borrower
4
5 # Copyright (c) 2009 BibLibre
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
25 use CGI qw ( -utf8 );
26 use C4::Members;
27 use C4::Letters qw( GetPreparedLetter EnqueueLetter );
28 use Koha::Patrons;
29 use Koha::Patron::Categories;
30
31 my $input=CGI->new;
32
33
34 my $borrowernumber = $input->param('borrowernumber');
35 my $patron = Koha::Patrons->find( $borrowernumber );
36 unless ( $patron ) {
37     print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
38     exit;
39 }
40 my $borrower = $patron->unblessed;
41
42 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/notices.tt",
43                                 query => $input,
44                                 type => "intranet",
45                 flagsrequired => {borrowers => 'edit_borrowers'},
46                                 });
47
48 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
49 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
50
51 # Allow resending of messages in Notices tab
52 my $op = $input->param('op') || q{};
53 if ( $op eq 'resend_notice' ) {
54     my $message_id = $input->param('message_id');
55     my $message = C4::Letters::GetMessage( $message_id );
56     if ( $message->{borrowernumber} = $borrowernumber ) {
57         C4::Letters::ResendMessage( $message_id );
58         # redirect to self to avoid form submission on refresh
59         print $input->redirect("/cgi-bin/koha/members/notices.pl?borrowernumber=$borrowernumber");
60     }
61 }
62
63 if ( $op eq 'send_welcome' ) {
64     my $emailaddr = $patron->notice_email_address;
65
66     # if we manage to find a valid email address, send notice
67     if ($emailaddr) {
68         eval {
69             my $letter = GetPreparedLetter(
70                 module      => 'members',
71                 letter_code => 'WELCOME',
72                 branchcode  => $patron->branchcode,,
73                 lang        => $patron->lang || 'default',
74                 tables      => {
75                     'branches'  => $patron->branchcode,
76                     'borrowers' => $patron->borrowernumber,
77                 },
78                 want_librarian => 1,
79             ) or return;
80
81             my $message_id = EnqueueLetter(
82                 {
83                     letter                 => $letter,
84                     borrowernumber         => $patron->id,
85                     to_address             => $emailaddr,
86                     message_transport_type => 'email'
87                 }
88             );
89         };
90     }
91
92     # redirect to self to avoid form submission on refresh
93     print $input->redirect("/cgi-bin/koha/members/notices.pl?borrowernumber=$borrowernumber");
94 }
95
96 # Getting the messages
97 my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
98
99 $template->param(
100     patron             => $patron,
101     QUEUED_MESSAGES    => $queued_messages,
102     borrowernumber     => $borrowernumber,
103     sentnotices        => 1,
104 );
105 output_html_with_http_headers $input, $cookie, $template->output;
106