Bug 20805: Update child to adult patron process broken on several patron-related...
[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;
24 use C4::Output;
25 use CGI qw ( -utf8 );
26 use C4::Members;
27 use C4::Letters;
28 use C4::Members::Attributes qw(GetBorrowerAttributes);
29 use Koha::Patrons;
30 use Koha::Patron::Categories;
31
32 my $input=new CGI;
33
34
35 my $borrowernumber = $input->param('borrowernumber');
36 my $patron = Koha::Patrons->find( $borrowernumber );
37 unless ( $patron ) {
38     print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
39     exit;
40 }
41 my $borrower = $patron->unblessed;
42
43 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/notices.tt",
44                                 query => $input,
45                                 type => "intranet",
46                                 authnotrequired => 0,
47                 flagsrequired => {borrowers => 'edit_borrowers'},
48                                 debug => 1,
49                                 });
50
51 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
52 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
53
54 if ( $patron->is_child ) {
55     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
56     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
57     $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
58 }
59
60 # Allow resending of messages in Notices tab
61 my $op = $input->param('op') || q{};
62 if ( $op eq 'resend_notice' ) {
63     my $message_id = $input->param('message_id');
64     my $message = C4::Letters::GetMessage( $message_id );
65     if ( $message->{borrowernumber} = $borrowernumber ) {
66         C4::Letters::ResendMessage( $message_id );
67         # redirect to self to avoid form submission on refresh
68         print $input->redirect("/cgi-bin/koha/members/notices.pl?borrowernumber=$borrowernumber");
69     }
70 }
71
72 # Getting the messages
73 my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
74
75 if (C4::Context->preference('ExtendedPatronAttributes')) {
76     my $attributes = GetBorrowerAttributes($borrowernumber);
77     $template->param(
78         ExtendedPatronAttributes => 1,
79         extendedattributes => $attributes
80     );
81 }
82
83 $template->param(
84     patron             => $patron,
85     QUEUED_MESSAGES    => $queued_messages,
86     borrowernumber     => $borrowernumber,
87     sentnotices        => 1,
88 );
89 output_html_with_http_headers $input, $cookie, $template->output;
90