(bug #3353) permit librarians to cancel orders
[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
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 $itemtypes = GetItemTypes();
49
50 # get the record
51 my $order  = $query->param('order');
52 my $order2 = $order;
53 if ( $order2 eq '' ) {
54     $order2 = "date_due desc";
55     $template->param( orderbydate => 1 );
56 }
57
58 if ( $order2 eq 'title' ) {
59     $template->param( orderbytitle => 1 );
60 }
61
62 if ( $order2 eq 'author' ) {
63     $template->param( orderbyauthor => 1 );
64 }
65
66 my $limit = $query->param('limit');
67 if ( $limit eq 'full' ) {
68     $limit = 0;
69 }
70 else {
71     $limit = 50;
72 }
73
74 my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order2, $limit );
75
76 # add the row parity
77 #my $num = 0;
78 #foreach my $row (@$issues) {
79 #    $row->{'even'} = 1 if $num % 2 == 0;
80 #    $row->{'odd'} = 1 if $num % 2 == 1;
81 #    $num++;
82 #}
83
84 my @loop_reading;
85
86 for ( my $i = 0 ; $i < $count ; $i++ ) {
87     my %line;
88         
89         # XISBN Stuff
90         my $xisbn=$issues->[$i]->{'isbn'};
91         $xisbn =~ /(\d*[X]*)/;
92         $line{amazonisbn} = $1;         # FIXME: so it is OK if the ISBN = 'XXXXX' ?
93         my ($clean, $amazonisbn);
94         $amazonisbn = $1;
95         # these might be overkill, but they are better than the regexp above.
96         if (
97                 $amazonisbn =~ /\b(\d{13})\b/ or
98                 $amazonisbn =~ /\b(\d{10})\b/ or 
99                 $amazonisbn =~ /\b(\d{9}X)\b/i
100         ) {
101                 $clean = $1;
102                 $line{clean_isbn} = $1;
103         }
104         
105     $line{biblionumber}   = $issues->[$i]->{'biblionumber'};
106     $line{title}          = $issues->[$i]->{'title'};
107     $line{author}         = $issues->[$i]->{'author'};
108     $line{isbn}           = $issues->[$i]->{'isbn'};
109     $line{itemcallnumber} = $issues->[$i]->{'itemcallnumber'};
110     $line{date_due}       = format_date( $issues->[$i]->{'date_due'} );
111     $line{returndate}     = format_date( $issues->[$i]->{'returndate'} );
112     $line{volumeddesc}    = $issues->[$i]->{'volumeddesc'};
113     $line{counter}        = $i + 1;
114     $line{'description'} = $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'description'};
115     $line{imageurl}       = getitemtypeimagelocation( 'opac', $itemtypes->{ $issues->[$i]->{'itemtype'}  }->{'imageurl'} );
116     push( @loop_reading, \%line );
117 }
118
119 if (C4::Context->preference('BakerTaylorEnabled')) {
120         $template->param(
121                 JacketImages=>1,
122                 BakerTaylorEnabled  => 1,
123                 BakerTaylorImageURL => &image_url(),
124                 BakerTaylorLinkURL  => &link_url(),
125                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
126         );
127 }
128
129 BEGIN {
130         if (C4::Context->preference('BakerTaylorEnabled')) {
131                 require C4::External::BakerTaylor;
132                 import C4::External::BakerTaylor qw(&image_url &link_url);
133         }
134 }
135
136 for(qw(AmazonContent GoogleJackets)) {  # BakerTaylorEnabled handled above
137         C4::Context->preference($_) or next;
138         $template->param($_=>1);
139         $template->param(JacketImages=>1);
140 }
141
142 $template->param(
143     count          => $count,
144     READING_RECORD => \@loop_reading,
145     limit          => $limit,
146     showfulllink   => 1,
147         readingrecview => 1
148 );
149
150 output_html_with_http_headers $query, $cookie, $template->output;
151