Bug 11009: Do not display circulation history of anonymous patron
[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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 use strict;
24 use warnings;
25
26 use CGI;
27
28 use C4::Auth;
29 use C4::Output;
30 use C4::Members;
31 use C4::Branch qw(GetBranches);
32 use List::MoreUtils qw/any uniq/;
33 use Koha::DateUtils;
34
35 use C4::Dates qw/format_date/;
36 use C4::Members::Attributes qw(GetBorrowerAttributes);
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.tmpl",
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 if ($input->param('cardnumber')) {
55     $cardnumber = $input->param('cardnumber');
56     $data = GetMember(cardnumber => $cardnumber);
57     $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron
58 }
59 if ($input->param('borrowernumber')) {
60     $borrowernumber = $input->param('borrowernumber');
61     $data = GetMember(borrowernumber => $borrowernumber);
62 }
63
64 my $order = 'date_due desc';
65 my $limit = 0;
66 my $issues = ();
67 # Do not request the old issues of anonymous patron
68 if ( $borrowernumber == C4::Context->preference('AnonymousPatron') ){
69     $template->param( is_anonymous => 1 );
70 } else {
71     $issues = GetAllIssues($borrowernumber,$order,$limit);
72 }
73
74 my $branches = GetBranches();
75 foreach my $issue ( @{$issues} ) {
76     $issue->{issuingbranch} = $branches->{ $issue->{branchcode} }->{branchname};
77 }
78
79 #   barcode export
80 if ( $op eq 'export_barcodes' ) {
81     my $today = C4::Dates->new();
82     $today = $today->output('iso');
83     my @barcodes =
84       map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
85     my $borrowercardnumber =
86       GetMember( borrowernumber => $borrowernumber )->{'cardnumber'};
87     my $delimiter = "\n";
88     binmode( STDOUT, ":encoding(UTF-8)" );
89     print $input->header(
90         -type       => 'application/octet-stream',
91         -charset    => 'utf-8',
92         -attachment => "$today-$borrowercardnumber-checkinexport.txt"
93     );
94     my $content = join $delimiter, uniq(@barcodes);
95     print $content;
96     exit;
97 }
98
99 if ( $data->{'category_type'} eq 'C') {
100     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
101     my $cnt = scalar(@$catcodes);
102     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
103     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
104 }
105
106 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
107 if (! $limit){
108         $limit = 'full';
109 }
110
111
112 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
113 $template->param( picture => 1 ) if $picture;
114
115 if (C4::Context->preference('ExtendedPatronAttributes')) {
116     my $attributes = GetBorrowerAttributes($borrowernumber);
117     $template->param(
118         ExtendedPatronAttributes => 1,
119         extendedattributes => $attributes
120     );
121 }
122
123 $template->param(
124     readingrecordview => 1,
125     title             => $data->{title},
126     initials          => $data->{initials},
127     surname           => $data->{surname},
128     othernames        => $data->{othernames},
129     borrowernumber    => $borrowernumber,
130     firstname         => $data->{firstname},
131     cardnumber        => $data->{cardnumber},
132     categorycode      => $data->{categorycode},
133     category_type     => $data->{category_type},
134     categoryname      => $data->{description},
135     address           => $data->{address},
136     address2          => $data->{address2},
137     city              => $data->{city},
138     state             => $data->{state},
139     zipcode           => $data->{zipcode},
140     country           => $data->{country},
141     phone             => $data->{phone},
142     email             => $data->{email},
143     branchcode        => $data->{branchcode},
144     is_child          => ( $data->{category_type} eq 'C' ),
145     branchname        => $branches->{ $data->{branchcode} }->{branchname},
146     loop_reading      => $issues,
147     activeBorrowerRelationship =>
148       ( C4::Context->preference('borrowerRelationship') ne '' ),
149     RoutingSerials => C4::Context->preference('RoutingSerials'),
150 );
151 output_html_with_http_headers $input, $cookie, $template->output;
152