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