Bug 14185: Undefined $limit causes warn in opac/opac-readingrecord.pl
[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 strict;
20 use warnings;
21
22 use CGI qw ( -utf8 );
23
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Biblio;
27 use C4::Circulation;
28 use C4::Members;
29 use Koha::DateUtils;
30 use MARC::Record;
31
32 use C4::Output;
33 use C4::Charset qw(StripNonXmlChars);
34
35 my $query = new CGI;
36
37 # if opacreadinghistory is disabled, leave immediately
38 if ( ! C4::Context->preference('opacreadinghistory') ) {
39     print $query->redirect("/cgi-bin/koha/errors/404.pl");
40     exit;
41 }
42
43 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44     {
45         template_name   => "opac-readingrecord.tt",
46         query           => $query,
47         type            => "opac",
48         authnotrequired => 0,
49         flagsrequired   => { borrow => 1 },
50         debug           => 1,
51     }
52 );
53
54 # get borrower information ....
55 my ( $borr ) = GetMemberDetails( $borrowernumber );
56
57 $template->param(%{$borr});
58
59 my $itemtypes = GetItemTypes();
60
61 # get the record
62 my $order = $query->param('order') || '';
63 if ( $order eq 'title' ) {
64     $template->param( orderbytitle => 1 );
65 }
66 elsif ( $order eq 'author' ) {
67     $template->param( orderbyauthor => 1 );
68 }
69 else {
70     $order = "date_due desc";
71     $template->param( orderbydate => 1 );
72 }
73
74
75 my $limit = $query->param('limit');
76 $limit //= '';
77 $limit = ( $limit eq 'full' ) ? 0 : 50;
78
79 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
80
81 my $itype_attribute =
82   ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
83
84 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
85 foreach my $issue ( @{$issues} ) {
86     $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
87     if ( $issue->{$itype_attribute} ) {
88         $issue->{description} =
89           $itemtypes->{ $issue->{$itype_attribute} }->{description};
90         $issue->{imageurl} =
91           getitemtypeimagelocation( 'opac',
92             $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
93     }
94     if ( $issue->{marcxml} ) {
95         my $marcxml = StripNonXmlChars( $issue->{marcxml} );
96         my $marc_rec =
97           MARC::Record::new_from_xml( $marcxml, 'utf8',
98             C4::Context->preference('marcflavour') );
99         $issue->{subtitle} =
100           GetRecordValue( 'subtitle', $marc_rec, $issue->{frameworkcode} );
101     }
102     # My Summary HTML
103     if ($opac_summary_html) {
104         my $my_summary_html = $opac_summary_html;
105         $issue->{author}
106           ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g
107           : $my_summary_html =~ s/{AUTHOR}//g;
108         my $title = $issue->{title};
109         $title =~ s/\/+$//;    # remove trailing slash
110         $title =~ s/\s+$//;    # remove trailing space
111         $title
112           ? $my_summary_html =~ s/{TITLE}/$title/g
113           : $my_summary_html =~ s/{TITLE}//g;
114         $issue->{normalized_isbn}
115           ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g
116           : $my_summary_html =~ s/{ISBN}//g;
117         $issue->{biblionumber}
118           ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g
119           : $my_summary_html =~ s/{BIBLIONUMBER}//g;
120         $issue->{MySummaryHTML} = $my_summary_html;
121     }
122 }
123
124 if (C4::Context->preference('BakerTaylorEnabled')) {
125         $template->param(
126                 JacketImages=>1,
127                 BakerTaylorEnabled  => 1,
128                 BakerTaylorImageURL => &image_url(),
129                 BakerTaylorLinkURL  => &link_url(),
130                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
131         );
132 }
133
134 BEGIN {
135         if (C4::Context->preference('BakerTaylorEnabled')) {
136                 require C4::External::BakerTaylor;
137                 import C4::External::BakerTaylor qw(&image_url &link_url);
138         }
139 }
140
141 for(qw(AmazonCoverImages GoogleJackets)) {      # BakerTaylorEnabled handled above
142         C4::Context->preference($_) or next;
143         $template->param($_=>1);
144         $template->param(JacketImages=>1);
145 }
146
147 $template->param(
148     READING_RECORD => $issues,
149     limit          => $limit,
150     readingrecview => 1,
151     OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
152 );
153
154 output_html_with_http_headers $query, $cookie, $template->output;