Merge commit 'workbuffer.org-koha/translation' into to-push
[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 with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 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::Circulation;
27 use C4::Dates qw/format_date/;
28 use C4::Members;
29
30 use C4::Output;
31
32 my $query = new CGI;
33 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34     {
35         template_name   => "opac-readingrecord.tmpl",
36         query           => $query,
37         type            => "opac",
38         authnotrequired => 0,
39         flagsrequired   => { borrow => 1 },
40         debug           => 1,
41     }
42 );
43
44 # get borrower information ....
45 my ( $borr ) = GetMemberDetails( $borrowernumber );
46
47 $template->param($borr);
48
49 my $itemtypes = GetItemTypes();
50
51 # get the record
52 my $order  = $query->param('order') || '';
53 if ( $order eq '' ) {
54     $order = "date_due desc";
55     $template->param( orderbydate => 1 );
56 }
57
58 if ( $order eq 'title' ) {
59     $template->param( orderbytitle => 1 );
60 }
61
62 if ( $order eq 'author' ) {
63     $template->param( orderbyauthor => 1 );
64 }
65
66 my $limit = $query->param('limit') || 50;
67 if ( $limit eq 'full' ) {
68     $limit = 0;
69 }
70 else {
71     $limit = 50;
72 }
73
74 my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order, $limit );
75
76 my @bordat;
77 $bordat[0] = $borr;
78 $template->param( BORROWER_INFO => \@bordat );
79
80 my @loop_reading;
81
82 for ( my $i = 0 ; $i < $count ; $i++ ) {
83     my %line;
84         
85         # XISBN Stuff
86         my $isbn = GetNormalizedISBN($issues->[$i]->{'isbn'});
87         $line{normalized_isbn} = $isbn;
88     $line{biblionumber}   = $issues->[$i]->{'biblionumber'};
89     $line{title}          = $issues->[$i]->{'title'};
90     $line{author}         = $issues->[$i]->{'author'};
91     $line{itemcallnumber} = $issues->[$i]->{'itemcallnumber'};
92     $line{date_due}       = format_date( $issues->[$i]->{'date_due'} );
93     $line{returndate}     = format_date( $issues->[$i]->{'returndate'} );
94     $line{volumeddesc}    = $issues->[$i]->{'volumeddesc'};
95     $line{counter}        = $i + 1;
96     if($issues->[$i]->{'itemtype'}) {
97         $line{'itypedescription'} = $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'description'};
98         $line{imageurl}       = getitemtypeimagelocation( 'opac', $itemtypes->{ $issues->[$i]->{'itemtype'}  }->{'imageurl'} );
99     }
100     push( @loop_reading, \%line );
101 }
102
103 if (C4::Context->preference('BakerTaylorEnabled')) {
104         $template->param(
105                 JacketImages=>1,
106                 BakerTaylorEnabled  => 1,
107                 BakerTaylorImageURL => &image_url(),
108                 BakerTaylorLinkURL  => &link_url(),
109                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
110         );
111 }
112
113 BEGIN {
114         if (C4::Context->preference('BakerTaylorEnabled')) {
115                 require C4::External::BakerTaylor;
116                 import C4::External::BakerTaylor qw(&image_url &link_url);
117         }
118 }
119
120 for(qw(AmazonCoverImages GoogleJackets)) {      # BakerTaylorEnabled handled above
121         C4::Context->preference($_) or next;
122         $template->param($_=>1);
123         $template->param(JacketImages=>1);
124 }
125
126 $template->param(
127     count          => $count,
128     READING_RECORD => \@loop_reading,
129     limit          => $limit,
130     showfulllink   => 1,
131         readingrecview => 1
132 );
133
134 output_html_with_http_headers $query, $cookie, $template->output;
135