use CGI;
use C4::Auth;
use C4::Dates qw/format_date format_date_in_iso/;
-
-use vars qw($debug);
-
-BEGIN {
- $debug = $ENV{DEBUG} || 0;
-}
+use C4::Debug;
+use Date::Calc qw/Today Add_Delta_YM/;
my $input = new CGI;
my $order = $input->param('order');
my $title;
my $author;
-my @datearr = localtime( time() );
-my
-$todaysdate =
- ( 1900 + $datearr[5] ) . '-'
- . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
- . sprintf( "%0.2d", $datearr[3] );
-
+my ( $year, $month, $day ) = Today();
+my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day);
# Find yesterday for the default shelf pull start and end dates
-# A defualt of the prior years's holds is a reasonable way to pull holds
-my @datearr_yesterday = localtime( time() - 86400*365 );
-my $yesterdaysdate =
- ( 1900 + $datearr_yesterday[5] ) . '-'
- . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-'
- . sprintf( "%0.2d", $datearr_yesterday[3] );
+# A default of the prior years's holds is a reasonable way to pull holds
+my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 0));
# Predefine the start and end dates if they are not already defined
$startdate =~ s/^\s+//;
$enddate =~ s/\s+$//;
# Check if null, should string match, if so set start and end date to yesterday
if (!defined($startdate) or $startdate eq "") {
- $startdate = format_date($yesterdaysdate);
+ $startdate = format_date($datelastyear);
}
if (!defined($enddate) or $enddate eq "") {
$enddate = format_date($todaysdate);
}
-if (!defined($ratio) or $ratio eq "") {
+if (!defined($ratio) or $ratio eq "" or $ratio !~ /^\s*\d+\s*$/ ) {
$ratio = 3;
}
+if ($ratio == 0) {
+ $ratio = 1; # prevent division by zero
+}
my $dbh = C4::Context->dbh;
my ($sqlorderby, $sqldatewhere) = ("","");
$debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
-$sqldatewhere .= " AND reservedate >= " . $dbh->quote(format_date_in_iso($startdate)) if ($startdate) ;
-$sqldatewhere .= " AND reservedate <= " . $dbh->quote(format_date_in_iso($enddate)) if ($enddate) ;
+my @query_params = ();
+if ($startdate) {
+ $sqldatewhere .= " AND reservedate >= ?";
+ push @query_params, format_date_in_iso($startdate);
+}
+if ($enddate) {
+ $sqldatewhere .= " AND reservedate <= ?";
+ push @query_params, format_date_in_iso($enddate);
+}
if ($order eq "biblio") {
- $sqlorderby = " order by biblio.title, holdingbranch, listcall, l_location ";
+ $sqlorderby = " ORDER BY biblio.title, holdingbranch, listcall, l_location ";
} elsif ($order eq "callnumber") {
- $sqlorderby = " order by listcall, holdingbranch, l_location ";
+ $sqlorderby = " ORDER BY listcall, holdingbranch, l_location ";
} elsif ($order eq "itemcount") {
- $sqlorderby = " order by itemcount, reservecount ";
+ $sqlorderby = " ORDER BY itemcount, reservecount ";
} elsif ($order eq "itype") {
- $sqlorderby = " order by l_itype, holdingbranch, listcall ";
+ $sqlorderby = " ORDER BY l_itype, holdingbranch, listcall ";
} elsif ($order eq "location") {
- $sqlorderby = " order by l_location, holdingbranch, listcall ";
+ $sqlorderby = " ORDER BY l_location, holdingbranch, listcall ";
} elsif ($order eq "reservecount") {
- $sqlorderby = " order by reservecount DESC ";
+ $sqlorderby = " ORDER BY reservecount DESC ";
} elsif ($order eq "branch") {
- $sqlorderby = " order by holdingbranch, l_location, listcall ";
+ $sqlorderby = " ORDER BY holdingbranch, l_location, listcall ";
} else {
- $sqlorderby = " order by reservecount DESC ";
+ $sqlorderby = " ORDER BY reservecount DESC ";
}
my $strsth =
"SELECT reservedate,
items.itemcallnumber,
items.itemnumber,
GROUP_CONCAT(DISTINCT items.itemcallnumber
- ORDER BY items.itemnumber SEPARATOR '<br>') as listcall,
+ ORDER BY items.itemnumber SEPARATOR '<br/>') as listcall,
GROUP_CONCAT(DISTINCT holdingbranch
- ORDER BY items.itemnumber SEPARATOR '<br>') as listbranch,
+ ORDER BY items.itemnumber SEPARATOR '<br/>') as listbranch,
GROUP_CONCAT(DISTINCT items.location
- ORDER BY items.itemnumber SEPARATOR '<br>') as l_location,
+ ORDER BY items.itemnumber SEPARATOR '<br/>') as l_location,
GROUP_CONCAT(DISTINCT items.itype
- ORDER BY items.itemnumber SEPARATOR '<br>') as l_itype,
+ ORDER BY items.itemnumber SEPARATOR '<br/>') as l_itype,
notes,
reserves.found,
biblio.title,
if (C4::Context->preference('IndependantBranches')){
$strsth .= " AND items.holdingbranch=? ";
+ push @query_params, C4::Context->userenv->{'branch'};
}
+
$strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
my $sth = $dbh->prepare($strsth);
+$sth->execute(@query_params);
-if (C4::Context->preference('IndependantBranches')){
- $sth->execute(C4::Context->userenv->{'branch'});
-}
-else {
- $sth->execute();
-}
my @reservedata;
while ( my $data = $sth->fetchrow_hashref ) {
my @itemlist;