Bug 12426: Allow resending of messages from the notices tab in the patron account
[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 strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Auth;
25 use C4::Output;
26 use CGI qw ( -utf8 );
27 use C4::Members;
28 use C4::Branch;
29 use C4::Letters;
30 use C4::Members::Attributes qw(GetBorrowerAttributes);
31
32 my $input=new CGI;
33
34
35 my $borrowernumber = $input->param('borrowernumber');
36 #get borrower details
37 my $borrower = GetMember(borrowernumber => $borrowernumber);
38
39 my ($template, $loggedinuser, $cookie)
40 = get_template_and_user({template_name => "members/notices.tt",
41                                 query => $input,
42                                 type => "intranet",
43                                 authnotrequired => 0,
44                                 flagsrequired => {borrowers => 1},
45                                 debug => 1,
46                                 });
47
48 $template->param( $borrower );
49 my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
50 $template->param( picture => 1 ) if $picture;
51
52 # Getting the messages
53 my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
54
55 # Bug 12426 - Allow resending of messages in Notices tab
56 if ($input->param('resendnotice')) {
57     foreach my $message (@$queued_messages){
58         # resendnotice must be in this borrower's queue - we don't want to make it
59         # possible to change any message just by changing resendnotice id.
60         if ($message->{message_id} == $input->param('resendnotice')) {
61             # We also only want to resend messages in failed status
62             last unless $message->{status} eq "failed";
63
64             # Modify the message in $queued_message to have its new pending status
65             $message->{status} = 'pending' if (C4::Letters::ResendMessage($message->{message_id}));
66             last;
67         }
68     }
69 }
70
71 if (C4::Context->preference('ExtendedPatronAttributes')) {
72     my $attributes = GetBorrowerAttributes($borrowernumber);
73     $template->param(
74         ExtendedPatronAttributes => 1,
75         extendedattributes => $attributes
76     );
77 }
78
79 $template->param(%$borrower);
80
81 $template->param(
82     QUEUED_MESSAGES    => $queued_messages,
83     borrowernumber     => $borrowernumber,
84     sentnotices        => 1,
85     branchname         => GetBranchName($borrower->{'branchcode'}),
86     categoryname       => $borrower->{'description'},
87     activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
88     RoutingSerials => C4::Context->preference('RoutingSerials'),
89 );
90 output_html_with_http_headers $input, $cookie, $template->output;
91