minor bugfixing for reservations
[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 # $Id$
19
20 use strict;
21 require Exporter;
22 use CGI;
23
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Circulation;
27 use C4::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, $flags ) = GetMemberDetails( $borrowernumber );
46
47 $template->param($borr);
48
49 # get the record
50 my $order  = $query->param('order');
51 my $order2 = $order;
52 if ( $order2 eq '' ) {
53     $order2 = "date_due desc";
54     $template->param( orderbydate => 1 );
55 }
56
57 if ( $order2 eq 'title' ) {
58     $template->param( orderbytitle => 1 );
59 }
60
61 if ( $order2 eq 'author' ) {
62     $template->param( orderbyauthor => 1 );
63 }
64
65 my $limit = $query->param('limit');
66 if ( $limit eq 'full' ) {
67     $limit = 0;
68 }
69 else {
70     $limit = 50;
71 }
72 my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order2, $limit );
73
74 # add the row parity
75 #my $num = 0;
76 #foreach my $row (@$issues) {
77 #    $row->{'even'} = 1 if $num % 2 == 0;
78 #    $row->{'odd'} = 1 if $num % 2 == 1;
79 #    $num++;
80 #}
81
82 my @loop_reading;
83
84 for ( my $i = 0 ; $i < $count ; $i++ ) {
85     my %line;
86     if ( $i % 2 ) {
87         $line{'toggle'} = 1;
88     }
89     $line{biblionumber}   = $issues->[$i]->{'biblionumber'};
90     $line{title}          = $issues->[$i]->{'title'};
91     $line{author}         = $issues->[$i]->{'author'};
92     $line{classification} = $issues->[$i]->{'classification'};
93     $line{date_due}       = format_date( $issues->[$i]->{'date_due'} );
94     $line{returndate}     = format_date( $issues->[$i]->{'returndate'} );
95     $line{volumeddesc}    = $issues->[$i]->{'volumeddesc'};
96     $line{counter}        = $i + 1;
97     push( @loop_reading, \%line );
98 }
99
100 $template->param(
101     count          => $count,
102     READING_RECORD => \@loop_reading,
103     limit          => $limit,
104     showfulllink   => ( $count > 50 ),
105 );
106
107 output_html_with_http_headers $query, $cookie, $template->output;
108