Bug 24064: DUEDGST typoed as DUEGST
[koha.git] / opac / opac-readingrecord.pl
blob8a561a5ede0a3321f6868ed134ca3991fdd242aa
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
19 use Modern::Perl;
21 use CGI qw ( -utf8 );
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Biblio;
26 use C4::Circulation;
27 use C4::Members;
28 use Koha::DateUtils;
29 use MARC::Record;
31 use C4::Output;
32 use C4::Charset qw(StripNonXmlChars);
33 use Koha::Patrons;
35 use Koha::ItemTypes;
36 use Koha::Ratings;
38 my $query = new CGI;
40 # if opacreadinghistory is disabled, leave immediately
41 if ( ! C4::Context->preference('opacreadinghistory') ) {
42 print $query->redirect("/cgi-bin/koha/errors/404.pl");
43 exit;
46 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
48 template_name => "opac-readingrecord.tt",
49 query => $query,
50 type => "opac",
51 authnotrequired => 0,
52 debug => 1,
56 my $borr = Koha::Patrons->find( $borrowernumber )->unblessed;
58 $template->param(%{$borr});
60 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
62 # get the record
63 my $order = $query->param('order') || '';
64 if ( $order eq 'title' ) {
65 $template->param( orderbytitle => 1 );
67 elsif ( $order eq 'author' ) {
68 $template->param( orderbyauthor => 1 );
70 else {
71 $order = "date_due desc";
72 $template->param( orderbydate => 1 );
76 my $limit = $query->param('limit');
77 $limit //= '';
78 $limit = ( $limit eq 'full' ) ? 0 : 50;
80 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
82 my $itype_attribute =
83 ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
85 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
86 foreach my $issue ( @{$issues} ) {
87 $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
88 if ( $issue->{$itype_attribute} ) {
89 $issue->{translated_description} =
90 $itemtypes->{ $issue->{$itype_attribute} }->{translated_description};
91 $issue->{imageurl} =
92 getitemtypeimagelocation( 'opac',
93 $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
95 my $marcxml = C4::Biblio::GetXmlBiblio( $issue->{biblionumber} );
96 if ( $marcxml ) {
97 $marcxml = StripNonXmlChars( $marcxml );
98 my $marc_rec =
99 MARC::Record::new_from_xml( $marcxml, 'utf8',
100 C4::Context->preference('marcflavour') );
101 $issue->{normalized_upc} = GetNormalizedUPC( $marc_rec, C4::Context->preference('marcflavour') );
103 # My Summary HTML
104 if ($opac_summary_html) {
105 my $my_summary_html = $opac_summary_html;
106 $issue->{author}
107 ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g
108 : $my_summary_html =~ s/{AUTHOR}//g;
109 my $title = $issue->{title};
110 $title =~ s/\/+$//; # remove trailing slash
111 $title =~ s/\s+$//; # remove trailing space
112 $title
113 ? $my_summary_html =~ s/{TITLE}/$title/g
114 : $my_summary_html =~ s/{TITLE}//g;
115 $issue->{normalized_isbn}
116 ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g
117 : $my_summary_html =~ s/{ISBN}//g;
118 $issue->{biblionumber}
119 ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g
120 : $my_summary_html =~ s/{BIBLIONUMBER}//g;
121 $issue->{MySummaryHTML} = $my_summary_html;
123 # Star ratings
124 if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
125 my $ratings = Koha::Ratings->search({ biblionumber => $issue->{biblionumber} });
126 $issue->{ratings} = $ratings;
127 $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
131 if (C4::Context->preference('BakerTaylorEnabled')) {
132 $template->param(
133 JacketImages=>1,
134 BakerTaylorEnabled => 1,
135 BakerTaylorImageURL => &image_url(),
136 BakerTaylorLinkURL => &link_url(),
137 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
141 BEGIN {
142 if (C4::Context->preference('BakerTaylorEnabled')) {
143 require C4::External::BakerTaylor;
144 import C4::External::BakerTaylor qw(&image_url &link_url);
148 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
149 C4::Context->preference($_) or next;
150 $template->param($_=>1);
151 $template->param(JacketImages=>1);
154 $template->param(
155 READING_RECORD => $issues,
156 limit => $limit,
157 readingrecview => 1,
158 OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
161 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };