Bug 18925: (RM follow-up) Remove schema files for deletedtables
[koha.git] / opac / opac-readingrecord.pl
blob49348adf457c68929d08912abaf20b4a0570b1ba
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;
37 my $query = new CGI;
39 # if opacreadinghistory is disabled, leave immediately
40 if ( ! C4::Context->preference('opacreadinghistory') ) {
41 print $query->redirect("/cgi-bin/koha/errors/404.pl");
42 exit;
45 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
47 template_name => "opac-readingrecord.tt",
48 query => $query,
49 type => "opac",
50 authnotrequired => 0,
51 debug => 1,
55 my $borr = Koha::Patrons->find( $borrowernumber )->unblessed;
57 $template->param(%{$borr});
59 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
61 # get the record
62 my $order = $query->param('order') || '';
63 if ( $order eq 'title' ) {
64 $template->param( orderbytitle => 1 );
66 elsif ( $order eq 'author' ) {
67 $template->param( orderbyauthor => 1 );
69 else {
70 $order = "date_due desc";
71 $template->param( orderbydate => 1 );
75 my $limit = $query->param('limit');
76 $limit //= '';
77 $limit = ( $limit eq 'full' ) ? 0 : 50;
79 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
81 my $itype_attribute =
82 ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
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->{translated_description} =
89 $itemtypes->{ $issue->{$itype_attribute} }->{translated_description};
90 $issue->{imageurl} =
91 getitemtypeimagelocation( 'opac',
92 $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
94 my $marcxml = C4::Biblio::GetXmlBiblio( $issue->{biblionumber} );
95 if ( $marcxml ) {
96 $marcxml = StripNonXmlChars( $marcxml );
97 my $marc_rec =
98 MARC::Record::new_from_xml( $marcxml, 'utf8',
99 C4::Context->preference('marcflavour') );
100 $issue->{subtitle} =
101 GetRecordValue( 'subtitle', $marc_rec, $issue->{frameworkcode} );
102 $issue->{normalized_upc} = GetNormalizedUPC( $marc_rec, C4::Context->preference('marcflavour') );
104 # My Summary HTML
105 if ($opac_summary_html) {
106 my $my_summary_html = $opac_summary_html;
107 $issue->{author}
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
113 $title
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;
126 if (C4::Context->preference('BakerTaylorEnabled')) {
127 $template->param(
128 JacketImages=>1,
129 BakerTaylorEnabled => 1,
130 BakerTaylorImageURL => &image_url(),
131 BakerTaylorLinkURL => &link_url(),
132 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
136 BEGIN {
137 if (C4::Context->preference('BakerTaylorEnabled')) {
138 require C4::External::BakerTaylor;
139 import C4::External::BakerTaylor qw(&image_url &link_url);
143 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
144 C4::Context->preference($_) or next;
145 $template->param($_=>1);
146 $template->param(JacketImages=>1);
149 $template->param(
150 READING_RECORD => $issues,
151 limit => $limit,
152 readingrecview => 1,
153 OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
156 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };