Bug 12497: Fix search history non-accessible when OPAC was private
[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 strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
27
28 use C4::Auth;
29 use C4::Output;
30 use C4::Members;
31 use List::MoreUtils qw/any uniq/;
32 use Koha::DateUtils;
33 use C4::Members::Attributes qw(GetBorrowerAttributes);
34
35 use Koha::Patrons;
36 use Koha::Patron::Categories;
37
38 my $input = CGI->new;
39
40 #get borrower details
41 my $data = undef;
42 my $borrowernumber = undef;
43 my $cardnumber = undef;
44
45 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
46                                 query => $input,
47                                 type => "intranet",
48                                 authnotrequired => 0,
49                                 flagsrequired => {borrowers => 1},
50                                 debug => 1,
51                                 });
52
53 my $op = $input->param('op') || '';
54 my $patron;
55 if ($input->param('cardnumber')) {
56     $cardnumber = $input->param('cardnumber');
57     $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
58 }
59 if ($input->param('borrowernumber')) {
60     $borrowernumber = $input->param('borrowernumber');
61     $patron = Koha::Patrons->find( $borrowernumber );
62 }
63
64 unless ( $patron ) {
65     print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
66     exit;
67 }
68 $data = $patron->unblessed;
69 $borrowernumber = $patron->borrowernumber;
70
71 my $order = 'date_due desc';
72 my $limit = 0;
73 my $issues = ();
74 # Do not request the old issues of anonymous patron
75 if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
76     # use of 'eq' in the above comparison is intentional -- the
77     # system preference value could be blank
78     $template->param( is_anonymous => 1 );
79 } else {
80     $issues = GetAllIssues($borrowernumber,$order,$limit);
81 }
82
83 #   barcode export
84 if ( $op eq 'export_barcodes' ) {
85     if ( $data->{'privacy'} < 2) {
86         my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
87         my @barcodes =
88           map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
89         my $borrowercardnumber = $data->{cardnumber};
90         my $delimiter = "\n";
91         binmode( STDOUT, ":encoding(UTF-8)" );
92         print $input->header(
93             -type       => 'application/octet-stream',
94             -charset    => 'utf-8',
95             -attachment => "$today-$borrowercardnumber-checkinexport.txt"
96         );
97
98         my $content = join $delimiter, uniq(@barcodes);
99         print $content;
100         exit;
101     }
102 }
103
104 if ( $data->{'category_type'} eq 'C') {
105     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
106     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
107     $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
108 }
109
110 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
111 if (! $limit){
112         $limit = 'full';
113 }
114
115 $template->param( picture => 1 ) if $patron->image;
116
117 if (C4::Context->preference('ExtendedPatronAttributes')) {
118     my $attributes = GetBorrowerAttributes($borrowernumber);
119     $template->param(
120         ExtendedPatronAttributes => 1,
121         extendedattributes => $attributes
122     );
123 }
124
125 $template->param(%$data);
126
127 $template->param(
128     readingrecordview => 1,
129     borrowernumber    => $borrowernumber,
130     privacy           => $data->{'privacy'},
131     categoryname      => $data->{description},
132     is_child          => ( $data->{category_type} eq 'C' ),
133     loop_reading      => $issues,
134     RoutingSerials => C4::Context->preference('RoutingSerials'),
135 );
136 output_html_with_http_headers $input, $cookie, $template->output;
137