Bug 13757 - DBRev 16.12.00.016
[koha.git] / opac / opac-readingrecord.pl
bloba7b67cefb4bd7e22ca8afca05afbdb41547f7ecd
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 strict;
20 use warnings;
22 use CGI qw ( -utf8 );
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;
32 use C4::Output;
33 use C4::Charset qw(StripNonXmlChars);
35 my $query = new CGI;
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;
43 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
45 template_name => "opac-readingrecord.tt",
46 query => $query,
47 type => "opac",
48 authnotrequired => 0,
49 debug => 1,
53 # get borrower information ....
54 my ( $borr ) = GetMember( borrowernumber => $borrowernumber );
56 $template->param(%{$borr});
58 my $itemtypes = GetItemTypes();
60 # get the record
61 my $order = $query->param('order') || '';
62 if ( $order eq 'title' ) {
63 $template->param( orderbytitle => 1 );
65 elsif ( $order eq 'author' ) {
66 $template->param( orderbyauthor => 1 );
68 else {
69 $order = "date_due desc";
70 $template->param( orderbydate => 1 );
74 my $limit = $query->param('limit');
75 $limit //= '';
76 $limit = ( $limit eq 'full' ) ? 0 : 50;
78 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
80 my $itype_attribute =
81 ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
83 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
84 foreach my $issue ( @{$issues} ) {
85 $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
86 if ( $issue->{$itype_attribute} ) {
87 $issue->{translated_description} =
88 $itemtypes->{ $issue->{$itype_attribute} }->{translated_description};
89 $issue->{imageurl} =
90 getitemtypeimagelocation( 'opac',
91 $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
93 my $marcxml = C4::Biblio::GetXmlBiblio( $issue->{biblionumber} );
94 if ( $marcxml ) {
95 $marcxml = StripNonXmlChars( $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 $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;
125 if (C4::Context->preference('BakerTaylorEnabled')) {
126 $template->param(
127 JacketImages=>1,
128 BakerTaylorEnabled => 1,
129 BakerTaylorImageURL => &image_url(),
130 BakerTaylorLinkURL => &link_url(),
131 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
135 BEGIN {
136 if (C4::Context->preference('BakerTaylorEnabled')) {
137 require C4::External::BakerTaylor;
138 import C4::External::BakerTaylor qw(&image_url &link_url);
142 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
143 C4::Context->preference($_) or next;
144 $template->param($_=>1);
145 $template->param(JacketImages=>1);
148 $template->param(
149 READING_RECORD => $issues,
150 limit => $limit,
151 readingrecview => 1,
152 OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
155 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };