Bug 12435 - Update MARC21 frameworks to Update No. 18 (April 2014)
[koha.git] / opac / opac-readingrecord.pl
blob6d9e2fc70e1905d72af1878b77e75e4668844524
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 use strict;
20 use warnings;
22 use CGI;
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;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "opac-readingrecord.tt",
39 query => $query,
40 type => "opac",
41 authnotrequired => 0,
42 flagsrequired => { borrow => 1 },
43 debug => 1,
47 # get borrower information ....
48 my ( $borr ) = GetMemberDetails( $borrowernumber );
50 $template->param(%{$borr});
52 my $itemtypes = GetItemTypes();
54 # get the record
55 my $order = $query->param('order') || '';
56 if ( $order eq 'title' ) {
57 $template->param( orderbytitle => 1 );
59 elsif ( $order eq 'author' ) {
60 $template->param( orderbyauthor => 1 );
62 else {
63 $order = "date_due desc";
64 $template->param( orderbydate => 1 );
68 my $limit = $query->param('limit');
69 $limit = ( $limit eq 'full' ) ? 0 : 50;
71 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
73 my $itype_attribute =
74 ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
76 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
77 foreach my $issue ( @{$issues} ) {
78 $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
79 if ( $issue->{$itype_attribute} ) {
80 $issue->{description} =
81 $itemtypes->{ $issue->{$itype_attribute} }->{description};
82 $issue->{imageurl} =
83 getitemtypeimagelocation( 'opac',
84 $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
86 if ( $issue->{marcxml} ) {
87 my $marcxml = StripNonXmlChars( $issue->{marcxml} );
88 my $marc_rec =
89 MARC::Record::new_from_xml( $marcxml, 'utf8',
90 C4::Context->preference('marcflavour') );
91 $issue->{subtitle} =
92 GetRecordValue( 'subtitle', $marc_rec, $issue->{frameworkcode} );
94 # My Summary HTML
95 if ($opac_summary_html) {
96 my $my_summary_html = $opac_summary_html;
97 $issue->{author}
98 ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g
99 : $my_summary_html =~ s/{AUTHOR}//g;
100 my $title = $issue->{title};
101 $title =~ s/\/+$//; # remove trailing slash
102 $title =~ s/\s+$//; # remove trailing space
103 $title
104 ? $my_summary_html =~ s/{TITLE}/$title/g
105 : $my_summary_html =~ s/{TITLE}//g;
106 $issue->{normalized_isbn}
107 ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g
108 : $my_summary_html =~ s/{ISBN}//g;
109 $issue->{biblionumber}
110 ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g
111 : $my_summary_html =~ s/{BIBLIONUMBER}//g;
112 $issue->{MySummaryHTML} = $my_summary_html;
116 if (C4::Context->preference('BakerTaylorEnabled')) {
117 $template->param(
118 JacketImages=>1,
119 BakerTaylorEnabled => 1,
120 BakerTaylorImageURL => &image_url(),
121 BakerTaylorLinkURL => &link_url(),
122 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
126 BEGIN {
127 if (C4::Context->preference('BakerTaylorEnabled')) {
128 require C4::External::BakerTaylor;
129 import C4::External::BakerTaylor qw(&image_url &link_url);
133 for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above
134 C4::Context->preference($_) or next;
135 $template->param($_=>1);
136 $template->param(JacketImages=>1);
139 $template->param(
140 READING_RECORD => $issues,
141 limit => $limit,
142 showfulllink => 1,
143 readingrecview => 1,
144 OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
147 output_html_with_http_headers $query, $cookie, $template->output;