Merge branch 'master' of git://git.koha-community.org/koha into MSWin32
[wip/koha-chris_n.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 my $attributes = GetBorrowerAttributes($borrowernumber);
100
101 $template->param(
102                                                 readingrecordview => 1,
103                                                 biblionumber => $data->{'biblionumber'},
104                                                 title => $data->{'title'},
105                                                 initials => $data->{'initials'},
106                                                 surname => $data->{'surname'},
107                                                 borrowernumber => $borrowernumber,
108                                                 limit => $limit,
109                                                 firstname => $data->{'firstname'},
110                                                 cardnumber => $data->{'cardnumber'},
111                                             categorycode => $data->{'categorycode'},
112                                             category_type => $data->{'category_type'},
113                                            # category_description => $data->{'description'},
114                                             categoryname        => $data->{'description'},
115                                             address => $data->{'address'},
116                                                 address2 => $data->{'address2'},
117                                             city => $data->{'city'},
118                                             state => $data->{'state'},
119                                                 zipcode => $data->{'zipcode'},
120                                                 country => $data->{'country'},
121                                                 phone => $data->{'phone'},
122                                                 email => $data->{'email'},
123                                                 branchcode => $data->{'branchcode'},
124                                                 is_child        => ($data->{'category_type'} eq 'C'),
125                                                 branchname => GetBranchName($data->{'branchcode'}),
126                                                 showfulllink => (scalar @loop_reading > 50),                                    
127                                                 loop_reading => \@loop_reading,
128                                             extendedattributes => $attributes,
129 );
130 output_html_with_http_headers $input, $cookie, $template->output;
131
132
133