[Koha-patches] [PATCH] Bug 6086 - adding a dynamic filter to pending holds
alex.arnaud at biblibre.com
alex.arnaud at biblibre.com
Fri Mar 2 16:21:34 CET 2012
From: Alex Arnaud <alex.arnaud at biblibre.com>
---
circ/pendingreserves.pl | 160 +++-----------
.../prog/en/modules/circ/pendingreserves.tt | 238 ++++++++------------
2 files changed, 130 insertions(+), 268 deletions(-)
diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl
index d723bc2..52a0450 100755
--- a/circ/pendingreserves.pl
+++ b/circ/pendingreserves.pl
@@ -34,11 +34,9 @@ use C4::Debug;
use Date::Calc qw/Today Add_Delta_YMD/;
my $input = new CGI;
-my $order = $input->param('order');
my $startdate=$input->param('from');
my $enddate=$input->param('to');
my $run_report=$input->param('run_report');
-my $report_page=$input->param('report_page');
my $theme = $input->param('theme'); # only used if allowthemeoverride is set
@@ -69,29 +67,28 @@ 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
+# 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));
-# Predefine the start and end dates if they are not already defined
+# Predefine the start and end dates if they are not already defined
$startdate =~ s/^\s+//;
$startdate =~ s/\s+$//;
$enddate =~ s/^\s+//;
$enddate =~ s/\s+$//;
-# Check if null, should string match, if so set start and end date to yesterday
+# 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);
+ $startdate = format_date($pastdate);
}
if (!defined($enddate) or $enddate eq "") {
- $enddate = format_date($todaysdate);
+ $enddate = format_date($todaysdate);
}
my @reservedata;
-my ($prev_results, $next_results, $next_or_previous) = (0,0,0);
if ( $run_report ) {
my $dbh = C4::Context->dbh;
- my ($sqlorderby, $sqldatewhere, $sqllimitoffset) = ("","","");
+ my $sqldatewhere = "";
$debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate);
my @query_params = ();
if ($startdate) {
@@ -103,27 +100,6 @@ if ( $run_report ) {
push @query_params, format_date_in_iso($enddate);
}
- $sqllimitoffset = " LIMIT 251";
- if ($report_page) {
- $sqllimitoffset .= " OFFSET=?";
- push @query_params, ($report_page * 250);
- }
-
- if ($order eq "biblio") {
- $sqlorderby = " ORDER BY biblio.title ";
- } elsif ($order eq "itype") {
- $sqlorderby = " ORDER BY l_itype, location, l_itemcallnumber ";
- } elsif ($order eq "location") {
- $sqlorderby = " ORDER BY location, l_itemcallnumber, holdingbranch ";
- } elsif ($order eq "date") {
- $sqlorderby = " ORDER BY l_reservedate, location, l_itemcallnumber ";
- } elsif ($order eq "library") {
- $sqlorderby = " ORDER BY holdingbranch, l_itemcallnumber, location ";
- } elsif ($order eq "call") {
- $sqlorderby = " ORDER BY l_itemcallnumber, holdingbranch, location ";
- } else {
- $sqlorderby = " ORDER BY biblio.title ";
- }
my $strsth =
"SELECT min(reservedate) as l_reservedate,
reserves.borrowernumber as borrowernumber,
@@ -176,110 +152,44 @@ if ( $run_report ) {
$strsth .= " AND items.holdingbranch=? ";
push @query_params, C4::Context->userenv->{'branch'};
}
- $strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby;
+ $strsth .= " GROUP BY reserves.biblionumber ORDER BY biblio.title ";
my $sth = $dbh->prepare($strsth);
$sth->execute(@query_params);
- my $previous;
- my $this;
while ( my $data = $sth->fetchrow_hashref ) {
- $this=$data->{biblionumber}.":".$data->{borrowernumber};
- my @itemlist;
push(
@reservedata,
{
- reservedate => format_date( $data->{l_reservedate} ),
- priority => $data->{priority},
- name => $data->{l_patron},
- title => $data->{title},
- author => $data->{author},
- borrowernumber => $data->{borrowernumber},
- itemnum => $data->{itemnumber},
- phone => $data->{phone},
- email => $data->{email},
- biblionumber => $data->{biblionumber},
- statusw => ( $data->{found} eq "W" ),
- statusf => ( $data->{found} eq "F" ),
- holdingbranch => $data->{l_holdingbranch},
- branch => $data->{l_branch},
- itemcallnumber => $data->{l_itemcallnumber},
- enumchron => $data->{l_enumchron},
- copyno => $data->{l_copynumber},
- notes => $data->{notes},
- notificationdate => $data->{notificationdate},
- reminderdate => $data->{reminderdate},
- count => $data->{icount},
- rcount => $data->{rcount},
- pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
- itype => $data->{l_itype},
- location => $data->{l_location}
+ reservedate => format_date( $data->{l_reservedate} ),
+ priority => $data->{priority},
+ name => $data->{l_patron},
+ title => $data->{title},
+ author => $data->{author},
+ borrowernumber => $data->{borrowernumber},
+ itemnum => $data->{itemnumber},
+ phone => $data->{phone},
+ email => $data->{email},
+ biblionumber => $data->{biblionumber},
+ statusw => ( $data->{found} eq "W" ),
+ statusf => ( $data->{found} eq "F" ),
+ holdingbranch => $data->{l_holdingbranch},
+ branch => $data->{l_branch},
+ itemcallnumber => $data->{l_itemcallnumber},
+ enumchron => $data->{l_enumchron},
+ copyno => $data->{l_copynumber},
+ notes => $data->{notes},
+ notificationdate => $data->{notificationdate},
+ reminderdate => $data->{reminderdate},
+ count => $data->{icount},
+ rcount => $data->{rcount},
+ pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
+ itype => $data->{l_itype},
+ location => $data->{l_location}
}
);
- $previous=$this;
}
-
$sth->finish;
-
- # Next Page?
- if ($report_page > 0) {
- $prev_results = $report_page - 1;
- }
- if ( scalar(@reservedata) > 250 ) {
- $next_results = $report_page + 1;
- pop(@reservedata); # .. we retrieved 251 results
- }
- if ($prev_results || $next_results) {
- $next_or_previous = 1;
- }
-
- # *** I doubt any of this is needed now with the above fixes *** -d.u.
-
- #$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/;
- #$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/;
- #$sth = $dbh->prepare($strsth);
- #if (C4::Context->preference('IndependantBranches')){
- # $sth->execute(C4::Context->userenv->{'branch'});
- #}
- #else {
- # $sth->execute();
- #}
- #while ( my $data = $sth->fetchrow_hashref ) {
- # $this=$data->{biblionumber}.":".$data->{borrowernumber};
- # my @itemlist;
- # push(
- # @reservedata,
- # {
- # reservedate => format_date( $data->{l_reservedate} ),
- # priority => $data->{priority},
- # name => $data->{l_patron},
- # title => $data->{title},
- # author => $data->{author},
- # borrowernumber => $data->{borrowernumber},
- # itemnum => $data->{itemnumber},
- # phone => $data->{phone},
- # email => $data->{email},
- # biblionumber => $data->{biblionumber},
- # statusw => ( $data->{found} eq "W" ),
- # statusf => ( $data->{found} eq "F" ),
- # holdingbranch => $data->{l_holdingbranch},
- # branch => $data->{l_branch},
- # itemcallnumber => $data->{l_itemcallnumber},
- # notes => $data->{notes},
- # notificationdate => $data->{notificationdate},
- # reminderdate => $data->{reminderdate},
- # count => $data->{icount},
- # rcount => $data->{rcount},
- # pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount},
- # itype => $data->{l_itype},
- # location => $data->{l_location},
- # thisitemonly => 1,
- #
- # }
- # );
- # $previous=$this;
- #}
- #$sth->finish;
}
$template->param(
@@ -287,14 +197,10 @@ $template->param(
from => $startdate,
to => $enddate,
run_report => $run_report,
- report_page => $report_page,
- prev_results => $prev_results,
- next_results => $next_results,
- next_or_previous => $next_or_previous,
reserveloop => \@reservedata,
"BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
- dateformat => C4::Context->preference("dateformat"),
+ dateformat => C4::Context->preference("dateformat"),
);
output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt
index c965e5c..19260a9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt
@@ -7,25 +7,42 @@
<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar.js"></script>
<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-en.js"></script>
<script type="text/javascript" src="[% themelang %]/lib/calendar/calendar-setup.js"></script>
-<!-- End of additions -->
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<!-- Plugin datatables -->
+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
+<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
-$.tablesorter.addParser({
- id: 'articles',
- is: function(s) {return false; },
- format: function(s) { return s.toLowerCase().replace(/^(the|an|a) /,''); },
- type: 'text'
+$(document).ready(function() {
+ var holdst = $("#holdst").dataTable($.extend(true, {}, dataTablesDefaults, {
+ }));
+ holdst.fnAddFilters("filter");
+ function createSelect( data ) {
+ var r='<select style="width:99%"><option value="">None</option>', i, len=data.length;
+ for ( i=0 ; i<len ; i++ ) {
+ r += '<option value="'+data[i]+'">'+data[i]+'</option>';
+ }
+ return r+'</select>';
+ }
+ $("#homebranchfilter").each( function () {
+ $(this).html( createSelect( holdst.fnGetColumnData(4) ) );
+ $('select', this).change( function () {
+ holdst.fnFilter( $(this).val(), 4 );
+ } );
+ } );
+ $("#itypefilter").each( function () {
+ $(this).html( createSelect( holdst.fnGetColumnData(8) ) );
+ $('select', this).change( function () {
+ holdst.fnFilter( $(this).val(), 8 );
+ } );
+ } );
+ $("#locationfilter").each( function () {
+ $(this).html( createSelect( holdst.fnGetColumnData(9) ) );
+ $('select', this).change( function () {
+ holdst.fnFilter( $(this).val(), 9 );
+ } );
+ } );
});
- $(document).ready(function() {
- $("th a").hide();
- $.tablesorter.defaults.widgets = ['zebra'];
- $("#holdst").tablesorter({[% IF ( dateformat == 'metric' ) %]
- dateFormat: 'uk',[% END %]
- sortList: [[3,0]],
- headers: { 0:{sorter:false},1:{sorter:false},3: { sorter: 'articles' },7:{sorter:false}}
- });
- });
//]]>
</script>
</head>
@@ -49,131 +66,70 @@ $.tablesorter.addParser({
<div class="searchresults">
[% IF ( reserveloop ) %]
<table id="holdst">
- <thead>
- <tr>
- <th>
- Pull This Many Items
- </th>
- <th>
- Items Available
- </th>
- <th>
- Patrons with Holds
- </th>
- <th>Title
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=biblio&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- <th>
- Libraries
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=library&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- <th>
- Available Call Numbers
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=call&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- <th>
- Available Copy No
- </th>
- <th>
- Available Enumeration
- </th>
- <th>
- Available Itypes
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=itype&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- <th>
- Available Locations
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=location&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- <th >Earliest Hold Date
- <a href="/cgi-bin/koha/circ/pendingreserves.pl?order=date&from=[% from %]&to=[% to %]">Sort</a>
- </th>
- </tr>
- </thead>
- <tbody>
- [% IF ( next_or_previous ) %]
- <tr>
- <td colspan="3" align="left">
- [% IF ( prev_results ) %]
- <form action="/cgi-bin/koha/circ/pendingreserves.pl" method="POST">
- <input type="hidden" name="from" value="[% from %]">
- <input type="hidden" name="to" value="[% to %]">
- <input type="hidden" name="report_page" value="[% prev_results %]">
- <input type="submit" name="run_report" value="< Prev">
- </form>
- [% END %]
- </td>
- <td colspan="3"></td>
- <td colspan="3" align="right">
- [% IF ( next_results ) %]
- <form action="/cgi-bin/koha/circ/pendingreserves.pl" method="POST">
- <input type="hidden" name="from" value="[% from %]">
- <input type="hidden" name="to" value="[% to %]">
- <input type="hidden" name="report_page" value="[% next_results %]">
- <input type="submit" name="run_report" value="Next >">
- </form>
- [% END %]
- </td>
- </tr>
- [% END %]
- [% FOREACH reserveloo IN reserveloop %]
- <tr>
- [% IF ( reserveloo.borrowernumber ) %]
- <td><p><b>[% reserveloo.pullcount %]</b></p></td>
- <td>[% reserveloo.count %]</td>
- <td>[% reserveloo.rcount %]</td>
- <td>
- <p>
- [% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %]
- [% reserveloo.title |html %] [% reserveloo.subtitle %]
- </a>
- </p>
- </td>
- [% ELSE %]
- <td colspan="3">
-
- </td>
- <td>"</td>
- [% END %]
- <td><p>[% reserveloo.holdingbranch %]</p></td>
- <td><p>[% reserveloo.itemcallnumber %]</p></td>
- <td><p>[% reserveloo.copyno %]</p></td>
- <td><p>[% reserveloo.enumchron %]</p></td>
- <td><p>[% reserveloo.itype %]</p></td>
- <td><p>[% reserveloo.location %]</p></td>
- <td width="15%">
- <p>[% reserveloo.reservedate %]</p>
- <p>in [% reserveloo.branch %]</p>
- [% IF ( reserveloo.statusw ) %]<p>Waiting</p>[% END %][% IF ( reserveloo.statusf ) %]<p>Fullfilled</p>[% END %]
- </td>
- </tr>
- [% END %]
- [% IF ( next_or_previous ) %]
- <tr>
- <td colspan="3" align="left">
- [% IF ( prev_results ) %]
- <form action="/cgi-bin/koha/circ/pendingreserves.pl" method="POST">
- <input type="hidden" name="from" value="[% from %]">
- <input type="hidden" name="to" value="[% to %]">
- <input type="hidden" name="report_page" value="[% prev_results %]">
- <input type="submit" name="run_report" value="< Prev">
- </form>
- [% END %]
- </td>
- <td colspan="3"></td>
- <td colspan="3" align="right">
- [% IF ( next_results ) %]
- <form action="/cgi-bin/koha/circ/pendingreserves.pl" method="POST">
- <input type="hidden" name="from" value="[% from %]">
- <input type="hidden" name="to" value="[% to %]">
- <input type="hidden" name="report_page" value="[% next_results %]">
- <input type="submit" name="run_report" value="Next >">
- </form>
- [% END %]
- </td>
- </tr>
- [% END %]
- </tbody>
+ <thead>
+ <tr>
+ <th>Pull This Many Items</th>
+ <th>Items Available</th>
+ <th>Patrons with Holds</th>
+ <th>Title</th>
+ <th>Libraries</th>
+ <th>Available Call Numbers</th>
+ <th>Available Copy No</th>
+ <th>Available Enumeration</th>
+ <th>Available Itypes</th>
+ <th>Available Locations</th>
+ <th>Earliest Hold Date</th>
+ </tr>
+ </thead>
+ <tbody>
+ [% FOREACH reserveloo IN reserveloop %]
+ <tr>
+ [% IF ( reserveloo.borrowernumber ) %]
+ <td><p><b>[% reserveloo.pullcount %]</b></p></td>
+ <td>[% reserveloo.count %]</td>
+ <td>[% reserveloo.rcount %]</td>
+ <td>
+ <p>
+ [% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %]
+ [% reserveloo.title |html %] [% reserveloo.subtitle %]
+ </a>
+ </p>
+ </td>
+ [% ELSE %]
+ <td>"</td>
+ <td>"</td>
+ <td>"</td>
+ <td>"</td>
+ [% END %]
+ <td>[% reserveloo.holdingbranch %]</td>
+ <td><p>[% reserveloo.itemcallnumber %]</p></td>
+ <td><p>[% reserveloo.copyno %]</p></td>
+ <td><p>[% reserveloo.enumchron %]</p></td>
+ <td>[% reserveloo.itype %]</td>
+ <td>[% reserveloo.location %]</td>
+ <td width="15%">
+ <p>[% reserveloo.reservedate %]</p>
+ <p>in [% reserveloo.branch %]</p>
+ [% IF ( reserveloo.statusw ) %]<p>Waiting</p>[% END %][% IF ( reserveloo.statusf ) %]<p>Fullfilled</p>[% END %]
+ </td>
+ </tr>
+ [% END %]
+ </tbody>
+ <tfoot>
+ <tr>
+ <td><input type="text" class="filter" data-column_num="0" placeholder="Pull This many items" style="width:95%"/></td>
+ <td><input type="text" class="filter" data-column_num="1" placeholder="Items available" style="width:95%"/></td>
+ <td><input type="text" class="filter" data-column_num="2" placeholder="Patron holds" style="width:95%"/></td>
+ <td><input type="text" class="filter" data-column_num="3" placeholder="Title" style="width:95%"/></td>
+ <td id="homebranchfilter"></td>
+ <td><input type="text" class="filter" data-column_num="5" placeholder="Call number" style="width:95%"/></td>
+ <td><input type="text" class="filter" data-column_num="6" placeholder="Available copy" style="width:95%"/></td>
+ <td><input type="text" class="filter" data-column_num="7" placeholder="Available enumeration" style="width:95%"/></td>
+ <td id="itypefilter"></td>
+ <td id="locationfilter"></td>
+ <td></td>
+ </tr>
+ </tfoot>
</table>
[% ELSE %]
<b>No items found.</b>
--
1.7.0.4
More information about the Koha-patches
mailing list