Bug #2429, bad HTML from unclosed <head>.
[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 require Exporter;
21 use CGI;
22
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Circulation;
26 use C4::Dates qw/format_date/;
27 use C4::Members;
28
29 use C4::Output;
30
31 my $query = new CGI;
32 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
33     {
34         template_name   => "opac-readingrecord.tmpl",
35         query           => $query,
36         type            => "opac",
37         authnotrequired => 0,
38         flagsrequired   => { borrow => 1 },
39         debug           => 1,
40     }
41 );
42
43 # get borrower information ....
44 my ( $borr ) = GetMemberDetails( $borrowernumber );
45
46 $template->param($borr);
47
48 my $imgdir = getitemtypeimagesrc();
49 my $itemtypes = GetItemTypes();
50
51 # get the record
52 my $order  = $query->param('order');
53 my $order2 = $order;
54 if ( $order2 eq '' ) {
55     $order2 = "date_due desc";
56     $template->param( orderbydate => 1 );
57 }
58
59 if ( $order2 eq 'title' ) {
60     $template->param( orderbytitle => 1 );
61 }
62
63 if ( $order2 eq 'author' ) {
64     $template->param( orderbyauthor => 1 );
65 }
66
67 my $limit = $query->param('limit');
68 if ( $limit eq 'full' ) {
69     $limit = 0;
70 }
71 else {
72     $limit = 50;
73 }
74
75 my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order2, $limit );
76
77 # add the row parity
78 #my $num = 0;
79 #foreach my $row (@$issues) {
80 #    $row->{'even'} = 1 if $num % 2 == 0;
81 #    $row->{'odd'} = 1 if $num % 2 == 1;
82 #    $num++;
83 #}
84
85 my @loop_reading;
86
87 for ( my $i = 0 ; $i < $count ; $i++ ) {
88     my %line;
89     if ( $i % 2 ) {
90         $line{'toggle'} = 1;
91     }
92         
93         # XISBN Stuff
94         my $xisbn=$issues->[$i]->{'isbn'};
95         $xisbn =~ /(\d*[X]*)/;
96         $line{amazonisbn} = $1;         # FIXME: so it is OK if the ISBN = 'XXXXX' ?
97         my ($clean, $amazonisbn);
98         $amazonisbn = $1;
99         # these might be overkill, but they are better than the regexp above.
100         if (
101                 $amazonisbn =~ /\b(\d{13})\b/ or
102                 $amazonisbn =~ /\b(\d{10})\b/ or 
103                 $amazonisbn =~ /\b(\d{9}X)\b/i
104         ) {
105                 $clean = $1;
106                 $line{clean_isbn} = $1;
107         }
108         
109     $line{biblionumber}   = $issues->[$i]->{'biblionumber'};
110     $line{title}          = $issues->[$i]->{'title'};
111     $line{author}         = $issues->[$i]->{'author'};
112     $line{isbn}           = $issues->[$i]->{'isbn'};
113     $line{itemcallnumber} = $issues->[$i]->{'itemcallnumber'};
114     $line{date_due}       = format_date( $issues->[$i]->{'date_due'} );
115     $line{returndate}     = format_date( $issues->[$i]->{'returndate'} );
116     $line{volumeddesc}    = $issues->[$i]->{'volumeddesc'};
117     $line{counter}        = $i + 1;
118     $line{'description'} = $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'description'};
119     $line{imageurl}       = $imgdir."/".$itemtypes->{ $issues->[$i]->{'itemtype'}  }->{'imageurl'}; 
120     push( @loop_reading, \%line );
121 }
122
123 if (C4::Context->preference('BakerTaylorEnabled')) {
124         $template->param(
125                 JacketImages=>1,
126                 BakerTaylorEnabled  => 1,
127                 BakerTaylorImageURL => &image_url(),
128                 BakerTaylorLinkURL  => &link_url(),
129                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
130         );
131 }
132
133 BEGIN {
134         if (C4::Context->preference('BakerTaylorEnabled')) {
135                 require C4::External::BakerTaylor;
136                 import C4::External::BakerTaylor qw(&image_url &link_url);
137         }
138 }
139
140 for(qw(AmazonContent GoogleJackets)) {  # BakerTaylorEnabled handled above
141         C4::Context->preference($_) or next;
142         $template->param($_=>1);
143         $template->param(JacketImages=>1);
144 }
145
146 $template->param(
147     count          => $count,
148     READING_RECORD => \@loop_reading,
149     limit          => $limit,
150     showfulllink   => 1,
151         readingrecview => 1
152 );
153
154 output_html_with_http_headers $query, $cookie, $template->output;
155