Bug 18789: Update other occurences where is_child should be used
[koha.git] / members / readingrec.pl
1 #!/usr/bin/perl
2
3 # written 27/01/2000
4 # script to display borrowers reading record
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use Modern::Perl;
24
25 use CGI qw ( -utf8 );
26
27 use C4::Auth;
28 use C4::Output;
29 use C4::Members;
30 use List::MoreUtils qw/any uniq/;
31 use Koha::DateUtils;
32 use C4::Members::Attributes qw(GetBorrowerAttributes);
33
34 use Koha::Patrons;
35 use Koha::Patron::Categories;
36
37 my $input = CGI->new;
38
39 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
40                                 query => $input,
41                                 type => "intranet",
42                                 authnotrequired => 0,
43                 flagsrequired => {borrowers => 'edit_borrowers'},
44                                 debug => 1,
45                                 });
46
47 my $op = $input->param('op') || '';
48 my $patron;
49 if ($input->param('cardnumber')) {
50     my $cardnumber = $input->param('cardnumber');
51     $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
52 }
53 if ($input->param('borrowernumber')) {
54     my $borrowernumber = $input->param('borrowernumber');
55     $patron = Koha::Patrons->find( $borrowernumber );
56 }
57
58 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
59 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
60
61 my $order = 'date_due desc';
62 my $limit = 0;
63 my $issues = ();
64 # Do not request the old issues of anonymous patron
65 if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ){
66     # use of 'eq' in the above comparison is intentional -- the
67     # system preference value could be blank
68     $template->param( is_anonymous => 1 );
69 } else {
70     $issues = GetAllIssues($patron->borrowernumber,$order,$limit);
71 }
72
73 #   barcode export
74 if ( $op eq 'export_barcodes' ) {
75     # FIXME This should be moved out of this script
76     if ( $patron->privacy < 2) {
77         my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
78         my @barcodes =
79           map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
80         my $borrowercardnumber = $patron->cardnumber;
81         my $delimiter = "\n";
82         binmode( STDOUT, ":encoding(UTF-8)" );
83         print $input->header(
84             -type       => 'application/octet-stream',
85             -charset    => 'utf-8',
86             -attachment => "$today-$borrowercardnumber-checkinexport.txt"
87         );
88
89         my $content = join $delimiter, uniq(@barcodes);
90         print $content;
91         exit;
92     }
93 }
94
95 if ( $patron->is_child ) {
96     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
97     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
98     $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
99 }
100
101 if (! $limit){
102         $limit = 'full';
103 }
104
105 if (C4::Context->preference('ExtendedPatronAttributes')) {
106     my $attributes = GetBorrowerAttributes($patron->borrowernumber);
107     $template->param(
108         ExtendedPatronAttributes => 1,
109         extendedattributes => $attributes
110     );
111 }
112
113 $template->param(
114     patron            => $patron,
115     readingrecordview => 1,
116     loop_reading      => $issues,
117 );
118 output_html_with_http_headers $input, $cookie, $template->output;
119