Merge remote-tracking branch 'origin/new/bug_5327'
[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;
32 use List::MoreUtils qw/any/;
33
34 use C4::Dates qw/format_date/;
35 use C4::Members::Attributes qw(GetBorrowerAttributes);
36
37 my $input = CGI->new;
38
39 #get borrower details
40 my $data = undef;
41 my $borrowernumber = undef;
42 my $cardnumber = undef;
43
44 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tmpl",
45                                 query => $input,
46                                 type => "intranet",
47                                 authnotrequired => 0,
48                                 flagsrequired => {borrowers => 1},
49                                 debug => 1,
50                                 });
51
52 if ($input->param('cardnumber')) {
53     $cardnumber = $input->param('cardnumber');
54     $data = GetMember(cardnumber => $cardnumber);
55     $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron
56 }
57 if ($input->param('borrowernumber')) {
58     $borrowernumber = $input->param('borrowernumber');
59     $data = GetMember(borrowernumber => $borrowernumber);
60 }
61
62 my $order = 'date_due desc';
63 my $limit = 0;
64 my ( $issues ) = GetAllIssues($borrowernumber,$order,$limit);
65
66 my @loop_reading;
67
68 foreach my $issue (@{$issues}){
69         my %line;
70         $line{issuestimestamp} = format_date($issue->{'issuestimestamp'});
71         $line{biblionumber}    = $issue->{'biblionumber'};
72         $line{title}           = $issue->{'title'};
73         $line{author}          = $issue->{'author'};
74         $line{classification}  = $issue->{'classification'} || $issue->{'itemcallnumber'};
75         $line{date_due}        = format_date($issue->{'date_due'});
76         $line{returndate}      = format_date($issue->{'returndate'});
77         $line{issuedate}       = format_date($issue->{'issuedate'});
78         $line{issuingbranch}   = GetBranchName($issue->{'branchcode'});
79         $line{renewals}        = $issue->{'renewals'};
80         $line{barcode}         = $issue->{'barcode'};
81         $line{volumeddesc}     = $issue->{'volumeddesc'};
82         push(@loop_reading,\%line);
83 }
84
85 if ( $data->{'category_type'} eq 'C') {
86     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
87     my $cnt = scalar(@$catcodes);
88     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
89     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
90 }
91
92 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
93 if (! $limit){
94         $limit = 'full';
95 }
96
97 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
98 $template->param( picture => 1 ) if $picture;
99
100 if (C4::Context->preference('ExtendedPatronAttributes')) {
101     my $attributes = GetBorrowerAttributes($borrowernumber);
102     $template->param(
103         ExtendedPatronAttributes => 1,
104         extendedattributes => $attributes
105     );
106 }
107
108 $template->param(
109                                                 readingrecordview => 1,
110                                                 biblionumber => $data->{'biblionumber'},
111                                                 title => $data->{'title'},
112                                                 initials => $data->{'initials'},
113                                                 surname => $data->{'surname'},
114                                                 othernames => $data->{'othernames'},
115                                                 borrowernumber => $borrowernumber,
116                                                 limit => $limit,
117                                                 firstname => $data->{'firstname'},
118                                                 cardnumber => $data->{'cardnumber'},
119                                             categorycode => $data->{'categorycode'},
120                                             category_type => $data->{'category_type'},
121                                            # category_description => $data->{'description'},
122                                             categoryname        => $data->{'description'},
123                                             address => $data->{'address'},
124                                                 address2 => $data->{'address2'},
125                                             city => $data->{'city'},
126                                             state => $data->{'state'},
127                                                 zipcode => $data->{'zipcode'},
128                                                 country => $data->{'country'},
129                                                 phone => $data->{'phone'},
130                                                 email => $data->{'email'},
131                                                 branchcode => $data->{'branchcode'},
132                                                 is_child        => ($data->{'category_type'} eq 'C'),
133                                                 branchname => GetBranchName($data->{'branchcode'}),
134                                                 showfulllink => (scalar @loop_reading > 50),                                    
135                                                 loop_reading => \@loop_reading,
136                                                 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
137 );
138 output_html_with_http_headers $input, $cookie, $template->output;
139
140
141