Bug 3857: Add tools menu to left of CSV Profiles page
[koha.git] / circ / pendingreserves.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 # Modification by D.Ulm, actually works (as long as indep. branches not turned on)
22 #               Someone let me know what indep. branches is supposed to do and I'll make that part work too
23 #
24 #               The reserve pull lists *works* as long as not for indepencdant branches, I can fix!
25
26 use strict;
27 use C4::Context;
28 use C4::Output;
29 use CGI;
30 use C4::Auth;
31 use C4::Branch qw/GetBranches/;
32 use C4::Koha qw/GetItemTypes GetKohaAuthorisedValues/;
33 use C4::Dates qw/format_date format_date_in_iso/;
34 use C4::Debug;
35 use C4::Reserves qw/GetPendingReserves/;
36 use Date::Calc qw/Today Add_Delta_YMD/;
37 use JSON;
38
39 my $input       = new CGI;
40 my $order       = $input->param('order');
41 my $startdate   = $input->param('from');
42 my $enddate     = $input->param('to');
43
44
45 my $template_name = $input->param('json') ? "cataloguing/value_builder/ajax.tmpl" : "circ/pendingreserves.tmpl";
46
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48     {
49         template_name   => $template_name,
50         query           => $input,
51         type            => "intranet",
52         authnotrequired => 0,
53         flagsrequired   => { circulate => "circulate_remaining_permissions" },
54         debug           => 1,
55     }
56 );
57
58 if($input->param('json')){
59
60     my $startindex = $input->param('startIndex');
61     my $results    = $input->param('results');
62     my $filters    = {
63         holdingbranches => $input->param('holdingbranches') || "",
64         locations      => $input->param('locations') || "",
65         itemtypes      => $input->param('itemtypes') || "",
66     };
67     my ($count, $reservedata) = C4::Reserves::GetPendingReserves($filters, $startindex, $results);
68
69     my $jsondatas = {
70         recordsReturned => scalar @$reservedata,
71         totalRecords    => $count,
72         startIndex      => "0",
73         sort            => "callnumbers",
74         dir             => "asc",
75         pageSize        => "40",
76         records         => $reservedata,
77     };
78     
79     
80     $template->param(return => to_json($jsondatas));
81 }else{
82     my (@itemtypesloop,@locationloop, @branch_loop);
83     my $itemtypes = GetItemTypes;
84     foreach my $thisitemtype (sort keys %$itemtypes) {
85         push @itemtypesloop, {
86              value       => $thisitemtype,
87              description => $itemtypes->{$thisitemtype}->{'description'},
88          };
89     }
90     my $locs = GetKohaAuthorisedValues( 'items.location' );
91     foreach my $thisloc (sort keys %$locs) {
92         push @locationloop, {
93             value       => $thisloc,
94             description => $locs->{$thisloc},
95         };
96      }
97      my $branches = GetBranches();
98      foreach my $branchcode (sort keys %{$branches}) {
99         push @branch_loop, {
100             value       => $branchcode,
101             description => $branches->{$branchcode}->{branchname},
102         };
103      }
104      
105     $template->param(
106         branches_loop  => \@branch_loop,
107         itemtypes_loop => \@itemtypesloop,
108         locations_loop => \@locationloop,
109         "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
110         DHTMLcalendar_dateformat =>  C4::Dates->DHTMLcalendar(),
111         dateformat    => C4::Context->preference("dateformat"),
112     );
113 }
114 output_html_with_http_headers $input, $cookie, $template->output;