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>.
28 use C4::External::BakerTaylor qw( image_url link_url );
33 use C4::Charset qw(StripNonXmlChars);
41 # if opacreadinghistory is disabled, leave immediately
42 if ( ! C4::Context->preference('opacreadinghistory') ) {
43 print $query->redirect("/cgi-bin/koha/errors/404.pl");
47 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49 template_name => "opac-readingrecord.tt",
57 my $borr = Koha::Patrons->find( $borrowernumber )->unblessed;
59 $template->param(%{$borr});
61 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
64 my $order = $query->param('order') || '';
65 if ( $order eq 'title' ) {
66 $template->param( orderbytitle => 1 );
68 elsif ( $order eq 'author' ) {
69 $template->param( orderbyauthor => 1 );
72 $order = "date_due desc";
73 $template->param( orderbydate => 1 );
77 my $limit = $query->param('limit');
79 $limit = ( $limit eq 'full' ) ? 0 : 50;
81 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
84 ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
86 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
87 foreach my $issue ( @{$issues} ) {
88 $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
89 if ( $issue->{$itype_attribute} ) {
90 $issue->{translated_description} =
91 $itemtypes->{ $issue->{$itype_attribute} }->{translated_description};
93 getitemtypeimagelocation( 'opac',
94 $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
96 my $marcxml = C4::Biblio::GetXmlBiblio( $issue->{biblionumber} );
98 $marcxml = StripNonXmlChars( $marcxml );
100 MARC::Record::new_from_xml( $marcxml, 'UTF-8',
101 C4::Context->preference('marcflavour') );
102 $issue->{normalized_upc} = GetNormalizedUPC( $marc_rec, C4::Context->preference('marcflavour') );
105 if ($opac_summary_html) {
106 my $my_summary_html = $opac_summary_html;
108 ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g
109 : $my_summary_html =~ s/{AUTHOR}//g;
110 my $title = $issue->{title};
111 $title =~ s/\/+$//; # remove trailing slash
112 $title =~ s/\s+$//; # remove trailing space
114 ? $my_summary_html =~ s/{TITLE}/$title/g
115 : $my_summary_html =~ s/{TITLE}//g;
116 $issue->{normalized_isbn}
117 ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g
118 : $my_summary_html =~ s/{ISBN}//g;
119 $issue->{biblionumber}
120 ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g
121 : $my_summary_html =~ s/{BIBLIONUMBER}//g;
122 $issue->{MySummaryHTML} = $my_summary_html;
125 if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
126 my $ratings = Koha::Ratings->search({ biblionumber => $issue->{biblionumber} });
127 $issue->{ratings} = $ratings;
128 $issue->{my_rating} = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
132 if (C4::Context->preference('BakerTaylorEnabled')) {
135 BakerTaylorEnabled => 1,
136 BakerTaylorImageURL => &image_url(),
137 BakerTaylorLinkURL => &link_url(),
138 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
142 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
143 C4::Context->preference($_) or next;
144 $template->param($_=>1);
145 $template->param(JacketImages=>1);
149 READING_RECORD => $issues,
152 OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
155 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };