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