Bug 5830 Using XSLT on OPAC Lists page
[koha.git] / reports / reservereport.pl
blob67f384cc12efd99db3aa288cc979cb9aafb3bc03
1 #!/usr/bin/perl
3 #written 26/4/2000
4 #script to display reports
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 # script now takes a branchcode arg
24 # eg: http://koha.rangitikei.katipo.co.nz/cgi-bin/koha/reports/reservereport.pl?branch=BL
26 use strict;
27 #use warnings; FIXME - Bug 2505
28 use C4::Stats;
29 use C4::Dates qw/format_date/;
30 use CGI;
31 use C4::Output;
32 use C4::Branch; # GetBranches
33 use C4::Auth;
34 use C4::Koha;
35 use C4::Items;
38 my $input = new CGI;
39 my $time = $input->param('time');
40 my $branch = $input->param('branch');
41 my $sort = $input->param('sort');
43 if (!$branch) {
44 $branch = "ALL";
47 my $branches=GetBranches();
49 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
51 template_name => "reports/reservereport.tmpl",
52 query => $input,
53 type => "intranet",
54 authnotrequired => 0,
55 flagsrequired => { reports => '*' },
56 debug => 1,
60 # building up branches dropdown box
62 my %branchall;
63 my $branchcount=0;
64 my @branchloop;
66 foreach my $br (keys %$branches) {
67 $branchcount++;
68 my %branch1;
69 $branch1{name}=$branches->{$br}->{'branchname'};
70 $branch1{value}=$br;
71 push(@branchloop,\%branch1);
74 my ( $count, $data ) = unfilledreserves($branch);
76 my @dataloop;
77 my $toggle;
78 for ( my $i = 0 ; $i < $count ; $i++ ) {
79 my %line;
80 $toggle = $i%2 ? 0 : 1;
81 $line{'borrowernumber'} = $data->[$i]->{'borrowernumber'};
82 $line{'surname'} = $data->[$i]->{'surname'};
83 $line{'firstname'} = $data->[$i]->{'firstname'};
84 $line{'sortdate'} = $data->[$i]->{'reservedate'};
85 $line{'reservedate'} = format_date($data->[$i]->{'reservedate'});
86 $line{'biblionumber'} = $data->[$i]->{'biblionumber'};
87 $line{'title'} = $data->[$i]->{'title'};
88 $line{'classification'} = $data->[$i]->{'classification'};
89 $line{'dewey'} = $data->[$i]->{'dewey'};
90 $line{'status'} = $data->[$i]->{'found'};
91 $line{'branchcode'} = $data->[$i]->{'branchcode'};
92 $line{'toggle'} = $toggle;
93 if ( $line{'status'} ne 'W' ) {
95 # its not waiting, we need to find if its on issue, or on the shelf
96 # FIXME still need to shift the text to the template so its translateable
97 if ( $data->[$i]) {
98 # find if its on issue
99 my @items = GetItemsInfo($line{'biblionumber'}, 'intra' );
100 my $onissue = 0;
101 foreach my $item (@items) {
102 if ( $item->{'datedue'} eq 'Reserved' ) {
103 $onissue = 0;
104 if ($item->{'branchname'} eq ''){
105 $line{'status'}='In Transit';
107 else {
108 $line{'status'} = "On shelf at $item->{'branchname'}";
113 else {
114 $onissue = 1;
117 if ($onissue) {
118 $line{'status'} = 'On Issue';
121 else {
122 $line{'status'}="Waiting for pickup";
126 push( @dataloop, \%line );
129 if ($sort eq 'name'){
130 @dataloop = sort {$a->{'surname'} cmp $b->{'surname'}} @dataloop;
132 elsif ($sort eq 'date'){
133 @dataloop = sort {$a->{'sortdate'} cmp $b->{'sortdate'}} @dataloop;
135 elsif ($sort eq 'title'){
136 @dataloop = sort {$a->{'title'} cmp $b->{'title'}} @dataloop;
138 else {
139 @dataloop = sort {$a->{'status'} cmp $b->{'status'}} @dataloop;
143 $template->param(
144 count => $count,
145 dataloop => \@dataloop,
146 branchcode => $branch,
147 branchloop => \@branchloop
151 output_html_with_http_headers $input, $cookie, $template->output;