Cleanup circ/overdue.pl

This also fixes a deficiency with overdue.tmpl not retaining the
user's selection of sort order when displaying results.
Removed 9 unused variables.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
This commit is contained in:
Joe Atzberger 2009-05-22 13:37:49 -05:00 committed by Henri-Damien LAURENT
parent b57b5ee07b
commit 27acd508dd
2 changed files with 108 additions and 118 deletions

View File

@ -19,6 +19,7 @@
# Suite 330, Boston, MA 02111-1307 USA
use strict;
# use warnings; # FIXME
use C4::Context;
use C4::Output;
use CGI;
@ -28,17 +29,15 @@ use C4::Dates qw/format_date/;
use Date::Calc qw/Today/;
my $input = new CGI;
my $type = $input->param('type');
my $theme = $input->param('theme'); # only used if allowthemeoverride is set
my $order = $input->param('order');
my $order = $input->param( 'order' ) || '';
my $showall = $input->param('showall');
my $bornamefilter = $input->param('borname');
my $borcatfilter = $input->param('borcat');
my $bornamefilter = $input->param( 'borname');
my $borcatfilter = $input->param( 'borcat' );
my $itemtypefilter = $input->param('itemtype');
my $borflagsfilter = $input->param('borflags') || " ";
my $branchfilter = $input->param('branch');
my $op = $input->param('op');
my $borflagsfilter = $input->param('borflags') || "";
my $branchfilter = $input->param( 'branch' );
my $op = $input->param( 'op' ) || '';
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
@ -50,8 +49,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
debug => 1,
}
);
my $dbh = C4::Context->dbh;
my $dbh = C4::Context->dbh;
# download the complete CSV
if ($op eq 'csv') {
@ -70,128 +69,111 @@ $req = $dbh->prepare( "select categorycode, description from categories order by
$req->execute;
my @borcatloop;
while (my ($catcode, $description) =$req->fetchrow) {
my $selected = 1 if $catcode eq $borcatfilter;
my %row =(value => $catcode,
selected => $selected,
catname => $description,
);
push @borcatloop, \%row;
push @borcatloop, {
value => $catcode,
selected => $catcode eq $borcatfilter ? 1 : 0,
catname => $description,
};
}
$req = $dbh->prepare( "select itemtype, description from itemtypes order by description");
$req->execute;
my @itemtypeloop;
while (my ($itemtype, $description) =$req->fetchrow) {
my $selected = 1 if $itemtype eq $itemtypefilter;
my %row =(value => $itemtype,
selected => $selected,
push @itemtypeloop, {
value => $itemtype,
selected => $itemtype eq $itemtypefilter ? 1 : 0,
itemtypename => $description,
);
push @itemtypeloop, \%row;
};
}
my $onlymine=C4::Context->preference('IndependantBranches') &&
C4::Context->userenv &&
C4::Context->userenv->{flags}!=1 &&
C4::Context->userenv->{branch};
my $branches = GetBranches($onlymine);
my @branchloop;
foreach my $thisbranch ( sort keys %$branches ) {
my %row = (
value => $thisbranch,
branchname => $branches->{$thisbranch}->{'branchname'},
selected => ($branches->{$thisbranch}->{'branchcode'} eq $branchfilter)
);
push @branchloop, \%row;
$branchfilter = C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
$template->param(
branchloop => GetBranchesLoop($branchfilter, $onlymine),
branchfilter => $branchfilter,
borcatloop => \@borcatloop,
itemtypeloop => \@itemtypeloop,
borname => $bornamefilter,
order => $order,
showall => $showall,
);
my @sort_roots = qw(borrower title barcode date_due);
push @sort_roots, map {$_ . " desc"} @sort_roots;
my @order_loop = ({selected => $order ? 0 : 1}); # initial blank row
foreach (@sort_roots) {
my $tmpl_name = $_;
$tmpl_name =~ s/\s/_/g;
push @order_loop, {
selected => $order eq $_ ? 1 : 0,
ordervalue => $_,
foo => $tmpl_name,
'order_' . $tmpl_name => 1,
};
}
$branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
$template->param( branchloop => \@branchloop,
branchfilter => $branchfilter);
$template->param(borcatloop=> \@borcatloop,
itemtypeloop => \@itemtypeloop,
branchloop=> \@branchloop,
borname => $bornamefilter,
order => $order,
showall => $showall);
my $duedate;
my $borrowernumber;
my $itemnum;
my $data1;
my $data2;
my $data3;
my $name;
my $phone;
my $email;
my $title;
my $author;
$template->param(ORDER_LOOP => \@order_loop);
my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Today());
$bornamefilter =~s/\*/\%/g;
$bornamefilter =~s/\?/\_/g;
my $strsth="SELECT date_due,concat(surname,' ', firstname) as borrower,
borrowers.phone, borrowers.email,issues.itemnumber, items.barcode, biblio.title, biblio.author,borrowers.borrowernumber,biblio.biblionumber,borrowers.branchcode
my $strsth="SELECT date_due,
concat(surname,' ', firstname) as borrower,
borrowers.phone,
borrowers.email,
issues.itemnumber,
items.barcode,
biblio.title,
biblio.author,
borrowers.borrowernumber,
biblio.biblionumber,
borrowers.branchcode
FROM issues
LEFT JOIN borrowers ON (issues.borrowernumber=borrowers.borrowernumber )
LEFT JOIN items ON (issues.itemnumber=items.itemnumber)
LEFT JOIN borrowers ON (issues.borrowernumber=borrowers.borrowernumber )
LEFT JOIN items ON (issues.itemnumber=items.itemnumber)
LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber )
LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber )
WHERE 1=1 "; # placeholder, since it is possible that none of the additional
# conditions will be selected by user
$strsth.= " && date_due<'".$todaysdate."' " unless ($showall);
$strsth.=" && (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
$strsth.=" && borrowers.categorycode = '".$borcatfilter."' " if($borcatfilter) ;
$strsth.=" && biblioitems.itemtype = '".$itemtypefilter."' " if($itemtypefilter) ;
$strsth.=" && borrowers.flags = '".$borflagsfilter."' " if ($borflagsfilter ne " ") ;
$strsth.=" && borrowers.branchcode = '".$branchfilter."' " if($branchfilter) ;
if ($order eq "borrower"){
$strsth.=" ORDER BY borrower,date_due " ;
} elsif ($order eq "title"){
$strsth.=" ORDER BY title,date_due,borrower ";
} elsif ($order eq "barcode"){
$strsth.=" ORDER BY items.barcode,date_due,borrower ";
}elsif ($order eq "borrower DESC"){
$strsth.=" ORDER BY borrower desc,date_due " ;
} elsif ($order eq "title DESC"){
$strsth.=" ORDER BY title desc,date_due,borrower ";
} elsif ($order eq "barcode DESC"){
$strsth.=" ORDER BY items.barcode desc,date_due,borrower ";
} elsif ($order eq "date_due DESC"){
$strsth.=" ORDER BY date_due DESC,borrower ";
} else {
$strsth.=" ORDER BY date_due,borrower ";
}
$strsth.=" AND date_due < '" . $todaysdate . "' " unless ($showall);
$strsth.=" AND (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
$strsth.=" AND borrowers.categorycode = '" . $borcatfilter . "' " if $borcatfilter;
$strsth.=" AND biblioitems.itemtype = '" . $itemtypefilter . "' " if $itemtypefilter;
$strsth.=" AND borrowers.flags = '" . $borflagsfilter . "' " if $borflagsfilter;
$strsth.=" AND borrowers.branchcode = '" . $branchfilter . "' " if $branchfilter;
$strsth.=" ORDER BY " . (
($order eq "borrower" or $order eq "borrower desc") ? "$order, date_due" :
($order eq "title" or $order eq "title desc") ? "$order, date_due, borrower" :
($order eq "barcode" or $order eq "barcode desc") ? "items.$order, date_due, borrower" :
($order eq "date_due desc") ? "date_due DESC, borrower" :
"date_due, borrower" # default sort order
);
$template->param(sql=>$strsth);
my $sth=$dbh->prepare($strsth);
#warn "overdue.pl : query string ".$strsth;
$sth->execute();
my @overduedata;
while (my $data=$sth->fetchrow_hashref) {
$duedate=$data->{'date_due'};
$duedate = format_date($duedate);
$itemnum=$data->{'itemnumber'};
$name=$data->{'borrower'};
$phone=$data->{'phone'};
$email=$data->{'email'};
$title=$data->{'title'};
$author=$data->{'author'};
push (@overduedata, {
duedate => $duedate,
borrowernumber => $data->{borrowernumber},
barcode => $data->{barcode},
itemnum => $itemnum,
name => $name,
phone => $phone,
email => $email,
biblionumber => $data->{'biblionumber'},
title => $title,
author => $author,
branchcode => $data->{'branchcode'} });
push @overduedata, {
duedate => format_date($data->{date_due}),
borrowernumber => $data->{borrowernumber},
barcode => $data->{barcode},
itemnum => $data->{itemnumber},
name => $data->{borrower},
phone => $data->{phone},
email => $data->{email},
biblionumber => $data->{biblionumber},
title => $data->{title},
author => $data->{author},
branchcode => $data->{branchcode},
};
}
$template->param(

View File

@ -1,6 +1,9 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Circulation &rsaquo; Items Overdue as of <!-- TMPL_VAR NAME="todaysdate" --></title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<style type="text/css">
.sql {display:none;}
</style>
</head>
<body>
<!-- TMPL_INCLUDE NAME="header.inc" -->
@ -16,6 +19,7 @@
<h2>Items Overdue as of <!-- TMPL_VAR NAME="todaysdate" --></h2>
<p><a href="overdue.pl?op=csv&amp;branch=<!-- TMPL_VAR name="branchfilter" -->">Download file of all overdues</a> (for <!-- TMPL_IF name="branchfilter" -->branch <!-- TMPL_VAR name="branchfilter" --><!-- TMPL_ELSE -->all branches<!-- /TMPL_IF -->. Other filters are ignored)</p>
<div class="sql"><pre><!-- TMPL_VAR NAME="sql" ESCAPE="HTML" --></pre></div>
<div class="searchresults">
<table id="overduest">
<thead><tr>
@ -28,12 +32,9 @@
<tbody><!-- TMPL_LOOP NAME="overdueloop" -->
<tr>
<td><!-- TMPL_VAR NAME="duedate" --></td>
<!-- TMPL_IF NAME="email" -->
<td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber"-->"><!-- TMPL_VAR NAME="name" --></a> <a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Overdue: <!-- TMPL_VAR NAME="title" -->">[email]</a> (<!-- TMPL_VAR NAME="phone" -->)</td>
<!-- TMPL_ELSE -->
<td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber"-->"><!-- TMPL_VAR NAME="name" --></a> (<!--TMPL_IF NAME="phone" --><!-- TMPL_VAR NAME="phone" --><!-- TMPL_ELSE -->
<!--TMPL_IF NAME="mobile" --><!-- TMPL_VAR NAME="mobile" --><!-- TMPL_ELSE --><!--TMPL_IF NAME="phonepro" --> <!-- TMPL_VAR NAME="phonepro" --><!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF -->)</td>
<!-- /TMPL_IF -->
<td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber"-->"><!-- TMPL_VAR NAME="name" --></a>
<!-- TMPL_IF NAME="email" -->[<a href="mailto:<!-- TMPL_VAR NAME="email" -->?subject=Overdue: <!-- TMPL_VAR NAME="title" -->">email</a>]<!-- /TMPL_IF -->
(<!--TMPL_IF NAME="phone" --><!-- TMPL_VAR NAME="phone" --><!-- TMPL_ELSIF NAME="mobile" --><!-- TMPL_VAR NAME="mobile" --><!-- TMPL_ELSIF NAME="phonepro" --><!-- TMPL_VAR NAME="phonepro" --><!-- /TMPL_IF -->)</td>
<td><!-- TMPL_VAR name="branchcode" --></td>
<td><!-- TMPL_IF name="BiblioDefaultViewmarc" -->
<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --></a>
@ -62,7 +63,7 @@
</li>
<li><label>Patron flags:</label>
<select name="borflags" size="1" id="borflags">
<option value=" "> </option>
<option value=""></option>
<option value="gonenoaddress">Address in question</option>
<option value="debarred">Debarred</option>
<option value="lost">Lost Card</option>
@ -87,16 +88,23 @@
</li>
<li><label for="order">Sort By:</label> <select name="order" id="order">
<!-- TMPL_IF NAME="order" -->
<option value="">Due Date</option>
<!-- TMPL_ELSE --><option value="" selected="selected">Due Date</option><!-- /TMPL_IF -->
<option value="borrower">Patron</option>
<option value="title">Title</option>
<option value="barcode">Barcode</option>
<option value="date_due desc">Due Date desc</option>
<option value="borrower desc">Patron desc</option>
<option value="title desc">Title desc</option>
<option value="barcode desc">Barcode</option>
<!-- TMPL_LOOP NAME="ORDER_LOOP" -->
<!-- TMPL_IF NAME="selected" -->
<option value="<!-- TMPL_VAR NAME="ordervalue" DEFAULT="" -->" selected="selected">
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="ordervalue" DEFAULT="" -->">
<!-- /TMPL_IF -->[<!-- TMPL_VAR name="foo" -->]
<!-- TMPL_IF NAME="order_date_due" -->Due Date
<!-- TMPL_ELSIF NAME="order_borrower" -->Patron
<!-- TMPL_ELSIF NAME="order_barcode" -->Barcode
<!-- TMPL_ELSIF NAME="order_title" -->Title
<!-- TMPL_ELSIF NAME="order_date_due_desc" -->Due Date desc
<!-- TMPL_ELSIF NAME="order_borrower_desc" -->Patron desc
<!-- TMPL_ELSIF NAME="order_barcode_desc" -->Barcode desc
<!-- TMPL_ELSIF NAME="order_title_desc" -->Title desc
<!-- /TMPL_IF -->
</option>
<!-- /TMPL_LOOP -->
</select></li>
<li class="radio"><label for="showall">Show any items currently issued:</label>
<!-- TMPL_IF NAME="showall" --><input type="checkbox" id="showall" name="showall" value="show" checked="checked" /><!-- TMPL_ELSE --><input type="checkbox" id="showall" name="showall" value="show" /><!-- /TMPL_IF -->