Increment version for 3.22.21
[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
36 my $input = CGI->new;
37
38 #get borrower details
39 my $data = undef;
40 my $borrowernumber = undef;
41 my $cardnumber = undef;
42
43 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
44                                 query => $input,
45                                 type => "intranet",
46                                 authnotrequired => 0,
47                                 flagsrequired => {borrowers => 1},
48                                 debug => 1,
49                                 });
50
51 my $op = $input->param('op') || '';
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 = ();
65 # Do not request the old issues of anonymous patron
66 if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
67     # use of 'eq' in the above comparison is intentional -- the
68     # system preference value could be blank
69     $template->param( is_anonymous => 1 );
70 } else {
71     $issues = GetAllIssues($borrowernumber,$order,$limit);
72 }
73
74 my $branches = GetBranches();
75
76 #   barcode export
77 if ( $op eq 'export_barcodes' ) {
78     my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
79     my @barcodes =
80       map { $_->{barcode} } grep { $_->{returndate} =~ m/^$today/o } @{$issues};
81     my $borrowercardnumber =
82       GetMember( borrowernumber => $borrowernumber )->{'cardnumber'};
83     my $delimiter = "\n";
84     binmode( STDOUT, ":encoding(UTF-8)" );
85     print $input->header(
86         -type       => 'application/octet-stream',
87         -charset    => 'utf-8',
88         -attachment => "$today-$borrowercardnumber-checkinexport.txt"
89     );
90     my $content = join $delimiter, uniq(@barcodes);
91     print $content;
92     exit;
93 }
94
95 if ( $data->{'category_type'} eq 'C') {
96     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
97     my $cnt = scalar(@$catcodes);
98     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
99     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
100 }
101
102 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
103 if (! $limit){
104         $limit = 'full';
105 }
106
107
108 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
109 $template->param( picture => 1 ) if $picture;
110
111 if (C4::Context->preference('ExtendedPatronAttributes')) {
112     my $attributes = GetBorrowerAttributes($borrowernumber);
113     $template->param(
114         ExtendedPatronAttributes => 1,
115         extendedattributes => $attributes
116     );
117 }
118
119
120 $template->param(%$data);
121
122 $template->param(
123     readingrecordview => 1,
124     borrowernumber    => $borrowernumber,
125     categoryname      => $data->{description},
126     is_child          => ( $data->{category_type} eq 'C' ),
127     branchname        => $branches->{ $data->{branchcode} }->{branchname},
128     loop_reading      => $issues,
129     RoutingSerials => C4::Context->preference('RoutingSerials'),
130 );
131 output_html_with_http_headers $input, $cookie, $template->output;
132