Fix release notes typo
[koha.git] / opac / opac-readingrecord.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
13 #
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.
17
18
19 use strict;
20 use warnings;
21
22 use CGI;
23
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;
31
32 use C4::Output;
33 use C4::Charset qw(StripNonXmlChars);
34
35 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37     {
38         template_name   => "opac-readingrecord.tmpl",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 0,
42         flagsrequired   => { borrow => 1 },
43         debug           => 1,
44     }
45 );
46
47 # get borrower information ....
48 my ( $borr ) = GetMemberDetails( $borrowernumber );
49
50 $template->param(%{$borr});
51
52 my $itemtypes = GetItemTypes();
53
54 # get the record
55 my $order = $query->param('order') || '';
56 if ( $order eq 'title' ) {
57     $template->param( orderbytitle => 1 );
58 }
59 elsif ( $order eq 'author' ) {
60     $template->param( orderbyauthor => 1 );
61 }
62 else {
63     $order = "date_due desc";
64     $template->param( orderbydate => 1 );
65 }
66
67
68 my $limit = $query->param('limit');
69 $limit //= '';
70 $limit = ( $limit eq 'full' ) ? 0 : 50;
71
72 my $issues = GetAllIssues( $borrowernumber, $order, $limit );
73
74 my $itype_attribute =
75   ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype';
76
77 my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML');
78 foreach my $issue ( @{$issues} ) {
79     $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} );
80     if ( $issue->{$itype_attribute} ) {
81         $issue->{description} =
82           $itemtypes->{ $issue->{$itype_attribute} }->{description};
83         $issue->{imageurl} =
84           getitemtypeimagelocation( 'opac',
85             $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} );
86     }
87     if ( $issue->{marcxml} ) {
88         my $marcxml = StripNonXmlChars( $issue->{marcxml} );
89         my $marc_rec =
90           MARC::Record::new_from_xml( $marcxml, 'utf8',
91             C4::Context->preference('marcflavour') );
92         $issue->{subtitle} =
93           GetRecordValue( 'subtitle', $marc_rec, $issue->{frameworkcode} );
94     }
95     # My Summary HTML
96     if ($opac_summary_html) {
97         my $my_summary_html = $opac_summary_html;
98         $issue->{author}
99           ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g
100           : $my_summary_html =~ s/{AUTHOR}//g;
101         my $title = $issue->{title};
102         $title =~ s/\/+$//;    # remove trailing slash
103         $title =~ s/\s+$//;    # remove trailing space
104         $title
105           ? $my_summary_html =~ s/{TITLE}/$title/g
106           : $my_summary_html =~ s/{TITLE}//g;
107         $issue->{normalized_isbn}
108           ? $my_summary_html =~ s/{ISBN}/$issue->{normalized_isbn}/g
109           : $my_summary_html =~ s/{ISBN}//g;
110         $issue->{biblionumber}
111           ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g
112           : $my_summary_html =~ s/{BIBLIONUMBER}//g;
113         $issue->{MySummaryHTML} = $my_summary_html;
114     }
115 }
116
117 if (C4::Context->preference('BakerTaylorEnabled')) {
118         $template->param(
119                 JacketImages=>1,
120                 BakerTaylorEnabled  => 1,
121                 BakerTaylorImageURL => &image_url(),
122                 BakerTaylorLinkURL  => &link_url(),
123                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
124         );
125 }
126
127 BEGIN {
128         if (C4::Context->preference('BakerTaylorEnabled')) {
129                 require C4::External::BakerTaylor;
130                 import C4::External::BakerTaylor qw(&image_url &link_url);
131         }
132 }
133
134 for(qw(AmazonCoverImages GoogleJackets)) {      # BakerTaylorEnabled handled above
135         C4::Context->preference($_) or next;
136         $template->param($_=>1);
137         $template->param(JacketImages=>1);
138 }
139
140 $template->param(
141     READING_RECORD => $issues,
142     limit          => $limit,
143     showfulllink   => 1,
144     readingrecview => 1,
145     OPACMySummaryHTML => $opac_summary_html ? 1 : 0,
146 );
147
148 output_html_with_http_headers $query, $cookie, $template->output;