[MT2195] Display issuing branch in reading record
[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=$input->param('order') || '';
54 my $order2=$order;
55 if ($order2 eq ''){
56   $order2="date_due desc";
57 }
58 my $limit=$input->param('limit');
59 =======
60 my $borrowernumber = $input->param('borrowernumber');
61 my $limit          = $input->param('limit');
62 my $order          = $input->param('order') || '';
63
64 $order = "issuestimestamp desc" if not any { $order =~ $_ } ('issuestimestamp', 'title', 'author', 'returndate');
65
66 #get borrower details
67 my $data=GetMember('borrowernumber'=>$borrowernumber);
68
69 >>>>>>> (MT #2920) fix reading record scripts:members/readingrec.pl
70
71 if ($limit){
72     if ($limit eq 'full'){
73                 $limit=0;
74     }
75 }
76 else {
77   $limit=50;
78 }
79 my ( $issues ) = GetAllIssues($borrowernumber,$order,$limit);
80
81 my ($template, $loggedinuser, $cookie)
82 = get_template_and_user({template_name => "members/readingrec.tmpl",
83                                 query => $input,
84                                 type => "intranet",
85                                 authnotrequired => 0,
86                                 flagsrequired => {borrowers => 1},
87                                 debug => 1,
88                                 });
89
90 my @loop_reading;
91
92 foreach my $issue (@{$issues}){
93         my %line;
94         $line{issuestimestamp} = format_date($issue->{'issuestimestamp'});
95         $line{biblionumber}    = $issue->{'biblionumber'};
96         $line{title}           = $issue->{'title'};
97         $line{author}          = $issue->{'author'};
98         $line{classification}  = $issue->{'classification'} || $issue->{'itemcallnumber'};
99         $line{date_due}        = format_date($issue->{'date_due'});
100         $line{returndate}      = format_date($issue->{'returndate'});
101         $line{issuedate}       = format_date($issue->{'issuedate'});
102         $line{issuingbranch}   = GetBranchName($issues->[$i]->{'issuingbranch'});
103         $line{renewals}        = $issue->{'renewals'};
104         $line{barcode}         = $issue->{'barcode'};
105         $line{volumeddesc}     = $issue->{'volumeddesc'};
106         push(@loop_reading,\%line);
107 }
108
109 if ( $data->{'category_type'} eq 'C') {
110     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
111     my $cnt = scalar(@$catcodes);
112     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
113     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
114 }
115
116 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
117 if (! $limit){
118         $limit = 'full';
119 }
120
121 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
122 $template->param( picture => 1 ) if $picture;
123
124 $template->param(
125                                                 readingrecordview => 1,
126                                                 biblionumber => $data->{'biblionumber'},
127                                                 title => $data->{'title'},
128                                                 initials => $data->{'initials'},
129                                                 surname => $data->{'surname'},
130                                                 borrowernumber => $borrowernumber,
131                                                 limit => $limit,
132                                                 firstname => $data->{'firstname'},
133                                                 cardnumber => $data->{'cardnumber'},
134                                             categorycode => $data->{'categorycode'},
135                                             category_type => $data->{'category_type'},
136                                            # category_description => $data->{'description'},
137                                             categoryname        => $data->{'description'},
138                                             address => $data->{'address'},
139                                                 address2 => $data->{'address2'},
140                                             city => $data->{'city'},
141                                                 zipcode => $data->{'zipcode'},
142                                                 country => $data->{'country'},
143                                                 phone => $data->{'phone'},
144                                                 email => $data->{'email'},
145                                                 branchcode => $data->{'branchcode'},
146                                                 is_child        => ($data->{'category_type'} eq 'C'),
147                                                 branchname => GetBranchName($data->{'branchcode'}),
148                                                 showfulllink => (scalar @loop_reading > 50),                                    
149                                                 loop_reading => \@loop_reading);
150 output_html_with_http_headers $input, $cookie, $template->output;
151
152
153