Bug 14242: (QA follow-up) Update hint on suggestion form: 2016 > 2022
[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 Modern::Perl;
24
25 use CGI qw ( -utf8 );
26
27 use C4::Auth qw( get_template_and_user );
28 use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
29 use C4::Members qw( GetAllIssues );
30 use List::MoreUtils qw( uniq );
31 use Koha::DateUtils qw( dt_from_string );
32
33 use Koha::Patrons;
34 use Koha::Patron::Categories;
35
36 my $input = CGI->new;
37
38 my ($template, $loggedinuser, $cookie)= get_template_and_user({template_name => "members/readingrec.tt",
39                                 query => $input,
40                                 type => "intranet",
41                 flagsrequired => {borrowers => 'edit_borrowers'},
42                                 });
43
44 my $op = $input->param('op') || '';
45 my $patron;
46 if ($input->param('cardnumber')) {
47     my $cardnumber = $input->param('cardnumber');
48     $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
49 }
50 if ($input->param('borrowernumber')) {
51     my $borrowernumber = $input->param('borrowernumber');
52     $patron = Koha::Patrons->find( $borrowernumber );
53 }
54
55 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
56 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
57
58 #   barcode export
59 if ( $op eq 'export_barcodes' ) {
60     # FIXME This should be moved out of this script
61     if ( $patron->privacy < 2) {
62         my @barcodes = $patron->old_checkouts->search( {}, { prefetch => 'item' } )
63           ->filter_by_todays_checkins->get_column('item.barcode');
64
65         my $borrowercardnumber = $patron->cardnumber;
66         my $delimiter = "\n";
67         my $today = dt_from_string->ymd;
68         binmode( STDOUT, ":encoding(UTF-8)" );
69         print $input->header(
70             -type       => 'application/octet-stream',
71             -charset    => 'utf-8',
72             -attachment => "$today-$borrowercardnumber-checkinexport.txt"
73         );
74
75         my $content = join $delimiter, uniq(@barcodes);
76         print $content;
77         exit;
78     }
79 }
80
81 my $order = 'date_due desc';
82 my $limit = 0;
83 my $issues = ();
84 # Do not request the old issues of anonymous patron
85 if ( $patron->borrowernumber eq C4::Context->preference('AnonymousPatron') ){
86     # use of 'eq' in the above comparison is intentional -- the
87     # system preference value could be blank
88     $template->param( is_anonymous => 1 );
89 } else {
90     $issues = GetAllIssues($patron->borrowernumber,$order,$limit);
91 }
92
93 if (! $limit){
94         $limit = 'full';
95 }
96
97 $template->param(
98     patron            => $patron,
99     readingrecordview => 1,
100     loop_reading      => $issues,
101 );
102 output_html_with_http_headers $input, $cookie, $template->output;
103