Bug 7736 [QA Followup] - Fix collation
[koha.git] / members / readingrec.pl
blob79351ff51a86cc6b2d408c34518c36feb1aa6210
1 #!/usr/bin/perl
3 # written 27/01/2000
4 # script to display borrowers reading record
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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.
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.
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>.
23 use strict;
24 use warnings;
26 use CGI qw ( -utf8 );
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;
37 my $input = CGI->new;
39 #get borrower details
40 my $data = undef;
41 my $borrowernumber = undef;
42 my $cardnumber = undef;
44 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
45 query => $input,
46 type => "intranet",
47 authnotrequired => 0,
48 flagsrequired => {borrowers => 1},
49 debug => 1,
50 });
52 my $op = $input->param('op') || '';
53 if ($input->param('cardnumber')) {
54 $cardnumber = $input->param('cardnumber');
55 $data = GetMember(cardnumber => $cardnumber);
56 $borrowernumber = $data->{'borrowernumber'}; # we must define this as it is used to retrieve other data about the patron
58 if ($input->param('borrowernumber')) {
59 $borrowernumber = $input->param('borrowernumber');
60 $data = GetMember(borrowernumber => $borrowernumber);
63 my $order = 'date_due desc';
64 my $limit = 0;
65 my $issues = ();
66 # Do not request the old issues of anonymous patron
67 if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
68 # use of 'eq' in the above comparison is intentional -- the
69 # system preference value could be blank
70 $template->param( is_anonymous => 1 );
71 } else {
72 $issues = GetAllIssues($borrowernumber,$order,$limit);
75 my $branches = GetBranches();
77 # barcode export
78 if ( $op eq 'export_barcodes' ) {
79 if ( $data->{'privacy'} < 2) {
80 my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
81 my @barcodes =
82 map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
83 my $borrowercardnumber =
84 GetMember( borrowernumber => $borrowernumber )->{'cardnumber'};
85 my $delimiter = "\n";
86 binmode( STDOUT, ":encoding(UTF-8)" );
87 print $input->header(
88 -type => 'application/octet-stream',
89 -charset => 'utf-8',
90 -attachment => "$today-$borrowercardnumber-checkinexport.txt"
93 my $content = join $delimiter, uniq(@barcodes);
94 print $content;
95 exit;
99 if ( $data->{'category_type'} eq 'C') {
100 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
101 my $cnt = scalar(@$catcodes);
102 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
103 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
106 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
107 if (! $limit){
108 $limit = 'full';
111 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
112 $template->param( picture => 1 ) if $patron_image;
114 if (C4::Context->preference('ExtendedPatronAttributes')) {
115 my $attributes = GetBorrowerAttributes($borrowernumber);
116 $template->param(
117 ExtendedPatronAttributes => 1,
118 extendedattributes => $attributes
123 $template->param(%$data);
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'),
137 output_html_with_http_headers $input, $cookie, $template->output;