Bug 15407: Koha::Patron::Categories - replace GetborCatFromCatType
[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
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
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 use C4::Members::Attributes qw(GetBorrowerAttributes);
35 use Koha::Patron::Images;
36
37 use Koha::Patron::Categories;
38
39 my $input = CGI->new;
40
41 #get borrower details
42 my $data = undef;
43 my $borrowernumber = undef;
44 my $cardnumber = undef;
45
46 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
47                                 query => $input,
48                                 type => "intranet",
49                                 authnotrequired => 0,
50                                 flagsrequired => {borrowers => 1},
51                                 debug => 1,
52                                 });
53
54 my $op = $input->param('op') || '';
55 if ($input->param('cardnumber')) {
56     $cardnumber = $input->param('cardnumber');
57     $data = GetMember(cardnumber => $cardnumber);
58     $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron
59 }
60 if ($input->param('borrowernumber')) {
61     $borrowernumber = $input->param('borrowernumber');
62     $data = GetMember(borrowernumber => $borrowernumber);
63 }
64
65 my $order = 'date_due desc';
66 my $limit = 0;
67 my $issues = ();
68 # Do not request the old issues of anonymous patron
69 if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
70     # use of 'eq' in the above comparison is intentional -- the
71     # system preference value could be blank
72     $template->param( is_anonymous => 1 );
73 } else {
74     $issues = GetAllIssues($borrowernumber,$order,$limit);
75 }
76
77 my $branches = GetBranches();
78
79 #   barcode export
80 if ( $op eq 'export_barcodes' ) {
81     if ( $data->{'privacy'} < 2) {
82         my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
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
95         my $content = join $delimiter, uniq(@barcodes);
96         print $content;
97         exit;
98     }
99 }
100
101 if ( $data->{'category_type'} eq 'C') {
102     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
103     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
104     $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
105 }
106
107 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
108 if (! $limit){
109         $limit = 'full';
110 }
111
112 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
113 $template->param( picture => 1 ) if $patron_image;
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(%$data);
124
125 $template->param(
126     readingrecordview => 1,
127     borrowernumber    => $borrowernumber,
128     privacy           => $data->{'privacy'},
129     categoryname      => $data->{description},
130     is_child          => ( $data->{category_type} eq 'C' ),
131     branchname        => $branches->{ $data->{branchcode} }->{branchname},
132     loop_reading      => $issues,
133     activeBorrowerRelationship =>
134       ( C4::Context->preference('borrowerRelationship') ne '' ),
135     RoutingSerials => C4::Context->preference('RoutingSerials'),
136 );
137 output_html_with_http_headers $input, $cookie, $template->output;
138