use C4::Output;
use CGI;
use C4::Auth;
+use C4::Branch qw/GetBranches/;
+use C4::Koha qw/GetItemTypes GetKohaAuthorisedValues/;
use C4::Dates qw/format_date format_date_in_iso/;
use C4::Debug;
+use C4::Reserves qw/GetPendingReserves/;
use Date::Calc qw/Today Add_Delta_YMD/;
+use JSON;
-my $input = new CGI;
-my $order = $input->param('order');
-my $startdate=$input->param('from');
-my $enddate=$input->param('to');
+my $input = new CGI;
+my $order = $input->param('order');
+my $startdate = $input->param('from');
+my $enddate = $input->param('to');
-my $theme = $input->param('theme'); # only used if allowthemeoverride is set
+
+my $template_name = $input->param('json') ? "cataloguing/value_builder/ajax.tmpl" : "circ/pendingreserves.tmpl";
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
- template_name => "circ/pendingreserves.tmpl",
+ template_name => $template_name,
query => $input,
type => "intranet",
authnotrequired => 0,
}
);
-my $duedate;
-my $borrowernumber;
-my $itemnum;
-my $data1;
-my $data2;
-my $data3;
-my $name;
-my $phone;
-my $email;
-my $biblionumber;
-my $title;
-my $author;
-
-my ( $year, $month, $day ) = Today();
-my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
-my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -1));
-#changed from delivered range of 10 years-yesterday to 2 days ago-today
-# Find two days ago for the default shelf pull start and end dates
-my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -2));
+if($input->param('json')){
-# Predefine the start and end dates if they are not already defined
-$startdate =~ s/^\s+//;
-$startdate =~ s/\s+$//;
-$enddate =~ s/^\s+//;
-$enddate =~ s/\s+$//;
+ my $startindex = $input->param('startIndex');
+ my $results = $input->param('results');
+ my $filters = {
+ holdingbranches => $input->param('holdingbranches') || "",
+ locations => $input->param('locations') || "",
+ itemtypes => $input->param('itemtypes') || "",
+ };
+ my ($count, $reservedata) = C4::Reserves::GetPendingReserves($filters, $startindex, $results);
-# Check if null, should string match, if so set start and end date to yesterday
-if (!defined($startdate) or $startdate eq "") {
- $startdate = format_date($pastdate);
-}
-if (!defined($enddate) or $enddate eq "") {
- $enddate = format_date($todaysdate);
+ my $jsondatas = {
+ recordsReturned => scalar @$reservedata,
+ totalRecords => $count,
+ startIndex => "0",
+ sort => "callnumbers",
+ dir => "asc",
+ pageSize => "40",
+ records => $reservedata,
+ };
+
+
+ $template->param(return => to_json($jsondatas));
+}else{
+ my (@itemtypesloop,@locationloop, @branch_loop);
+ my $itemtypes = GetItemTypes;
+ foreach my $thisitemtype (sort keys %$itemtypes) {
+ push @itemtypesloop, {
+ value => $thisitemtype,
+ description => $itemtypes->{$thisitemtype}->{'description'},
+ };
+ }
+ my $locs = GetKohaAuthorisedValues( 'items.location' );
+ foreach my $thisloc (sort keys %$locs) {
+ push @locationloop, {
+ value => $thisloc,
+ description => $locs->{$thisloc},
+ };
+ }
+ my $branches = GetBranches();
+ foreach my $branchcode (sort keys %{$branches}) {
+ push @branch_loop, {
+ value => $branchcode,
+ description => $branches->{$branchcode}->{branchname},
+ };
+ }
+
+ $template->param(
+ branches_loop => \@branch_loop,
+ itemtypes_loop => \@itemtypesloop,
+ locations_loop => \@locationloop,
+ "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
+ DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
+ dateformat => C4::Context->preference("dateformat"),
+ );
}
-
-my $reservedata = C4::Reserves::GetPendingReserves();
-
-$template->param(
- todaysdate => format_date($todaysdate),
- from => $startdate,
- to => $enddate,
- reserveloop => $reservedata,
- "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
- DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
- dateformat => C4::Context->preference("dateformat"),
-);
-
output_html_with_http_headers $input, $cookie, $template->output;