Bug 36532: Protect opac-dismiss-message.pl from malicious usages
[koha.git] / opac / opac-readingrecord.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19 use Modern::Perl;
20
21 use CGI qw ( -utf8 );
22
23 use C4::Auth qw( get_template_and_user );
24 use C4::Biblio;
25 use C4::External::BakerTaylor qw( image_url link_url );
26 use MARC::Record;
27
28 use C4::Output qw( output_html_with_http_headers );
29 use Koha::Patrons;
30
31 use Koha::ItemTypes;
32
33 my $query = CGI->new;
34
35 # if opacreadinghistory is disabled, leave immediately
36 if ( ! C4::Context->preference('opacreadinghistory') ) {
37     print $query->redirect("/cgi-bin/koha/errors/404.pl");
38     exit;
39 }
40
41 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
42     {
43         template_name   => "opac-readingrecord.tt",
44         query           => $query,
45         type            => "opac",
46     }
47 );
48
49 my $patron = Koha::Patrons->find( $borrowernumber );
50 my @itemtypes = Koha::ItemTypes->search_with_localization->as_list;
51 my %item_types = map {
52     $_->itemtype => $_
53 } @itemtypes;
54 $template->param(item_types => \%item_types);
55
56 # get the record
57 my $order = $query->param('order') || '';
58 if ( $order eq 'title' ) {
59     $template->param( orderbytitle => 1 );
60 }
61 elsif ( $order eq 'author' ) {
62     $template->param( orderbyauthor => 1 );
63 }
64 else {
65     $order = "date_due desc";
66     $template->param( orderbydate => 1 );
67 }
68
69
70 my $limit = $query->param('limit');
71 $limit //= '';
72 $limit = ( $limit eq 'full' ) ? 0 : 50;
73
74 my $checkouts = [
75     $patron->checkouts(
76         {},
77         {
78             order_by => $order,
79             prefetch => { item => { biblio => 'biblioitems' } },
80             ( $limit ? ( limit => $limit ) : () ),
81         }
82     )->as_list
83 ];
84 $limit -= scalar(@$checkouts) if $limit;
85 my $old_checkouts = [
86     $patron->old_checkouts(
87         {},
88         {
89             order_by => $order,
90             prefetch => { item => { biblio => 'biblioitems' } },
91             ( $limit ? ( limit => $limit ) : () ),
92         }
93     )->as_list
94 ];
95
96 if (C4::Context->preference('BakerTaylorEnabled')) {
97         $template->param(
98                 JacketImages=>1,
99                 BakerTaylorEnabled  => 1,
100                 BakerTaylorImageURL => &image_url(),
101                 BakerTaylorLinkURL  => &link_url(),
102                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
103         );
104 }
105
106 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
107         C4::Context->preference($_) or next;
108         $template->param($_=>1);
109         $template->param(JacketImages=>1);
110 }
111
112 my $saving_display = C4::Context->preference('OPACShowSavings');
113 if ( $saving_display =~ /checkouthistory/ ) {
114     $template->param( savings => $patron->get_savings );
115 }
116
117 $template->param(
118     checkouts => $checkouts,
119     old_checkouts => $old_checkouts,
120     limit          => $limit,
121     readingrecview => 1,
122 );
123
124 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };