[Koha-patches] [PATCH] (bug #3779) overdues csv fix
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Mon Nov 9 16:15:04 CET 2009
This fix HTML escape in overdue list.
And fix the csv to be the same as what is shown.
---
circ/overdue.pl | 53 +++++++++++++++-----
.../prog/en/modules/circ/overdue.tmpl | 6 +-
2 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/circ/overdue.pl b/circ/overdue.pl
index 6c2a00a..7ca21e5 100755
--- a/circ/overdue.pl
+++ b/circ/overdue.pl
@@ -27,6 +27,7 @@ use C4::Auth;
use C4::Branch;
use C4::Dates qw/format_date/;
use Date::Calc qw/Today/;
+use Text::CSV_XS;
my $input = new CGI;
my $order = $input->param( 'order' ) || '';
@@ -52,18 +53,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $dbh = C4::Context->dbh;
-# download the complete CSV
-if ($op eq 'csv') {
-warn "BRANCH : $branchfilter";
- my $lib = $branchfilter ? "-library $branchfilter" :'';
- my $csv = `../misc/cronjobs/overdue_notices.pl -csv -n $lib`;
- print $input->header(-type => 'application/vnd.sun.xml.calc',
- -encoding => 'utf-8',
- -attachment=>"overdues.csv",
- -filename=>"overdues.csv" );
- print $csv;
- exit;
-}
my $req;
$req = $dbh->prepare( "select categorycode, description from categories order by description");
$req->execute;
@@ -101,6 +90,7 @@ $template->param(
borname => $bornamefilter,
order => $order,
showall => $showall,
+ csv_param_string => $input->query_string(),
);
my @sort_roots = qw(borrower title barcode date_due);
@@ -141,7 +131,7 @@ LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
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.=" AND date_due < '" . $todaysdate . "' " unless ($showall);
+$strsth.=" AND date_due < NOW() " 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;
@@ -181,4 +171,41 @@ $template->param(
overdueloop => \@overduedata
);
+# download the complete CSV
+if ($op eq 'csv') {
+ binmode(STDOUT, ":utf8");
+ my $csv = build_csv(\@overduedata);
+ print $input->header(-type => 'application/vnd.sun.xml.calc',
+ -encoding => 'utf-8',
+ -attachment=>"overdues.csv",
+ -filename=>"overdues.csv" );
+ print $csv;
+ exit;
+}
+
output_html_with_http_headers $input, $cookie, $template->output;
+
+
+sub build_csv {
+ my $overdues = shift;
+
+ return "" if scalar(@$overdues) == 0;
+
+ my @lines = ();
+
+ # build header ...
+ my @keys = sort keys %{ $overdues->[0] };
+ my $csv = Text::CSV_XS->new({
+ sep_char => C4::Context->preference("delimiter") ?
+ C4::Context->preference("delimiter") : ';' ,
+ });
+ $csv->combine(@keys);
+ push @lines, $csv->string();
+
+ # ... and rest of report
+ foreach my $overdue ( @{ $overdues } ) {
+ push @lines, $csv->string() if $csv->combine(map { $overdue->{$_} } @keys);
+ }
+
+ return join("\n", @lines) . "\n";
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
index 5a6f0fc..fcec17f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tmpl
@@ -18,7 +18,7 @@
<div class="yui-b">
<h2>Items Overdue as of <!-- TMPL_VAR NAME="todaysdate" --></h2>
-<p><a href="overdue.pl?op=csv&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>
+<p><a href="overdue.pl?op=csv<!--TMPL_IF NAME="csv_param_string" -->&<!-- TMPL_VAR name="csv_param_string" escape="HTML" --><!-- /TMPL_IF -->">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">
@@ -41,7 +41,7 @@
<!-- TMPL_ELSIF NAME="BiblioDefaultViewisbd" -->
<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --></a>
<!-- TMPL_ELSE -->
-<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_VAR NAME="subtitle" --></a><!-- /TMPL_IF --> <!-- TMPL_IF NAME="author" -->, by <!-- TMPL_VAR NAME="author" --><!-- /TMPL_IF -->
+<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="title" escape="html" --> <!-- TMPL_VAR ESCAPE="HTML" NAME="subtitle" --></a><!-- /TMPL_IF --> <!-- TMPL_IF NAME="author" -->, by <!-- TMPL_VAR ESCAPE="HTML" NAME="author" --><!-- /TMPL_IF -->
</td>
</tr>
<!-- /TMPL_LOOP --></tbody>
@@ -50,7 +50,7 @@
</div>
</div>
<div class="yui-b">
-<form method="post" action="/cgi-bin/koha/circ/overdue.pl">
+<form method="get" action="/cgi-bin/koha/circ/overdue.pl">
<fieldset class="brief">
<h4>Filter On:</h4>
<ol>
--
1.6.3.3
More information about the Koha-patches
mailing list