From 6b010cb1b5edc56f4b8d465c674d6db8e524858d Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 9 Nov 2009 16:13:11 +0100 Subject: [PATCH] (bug #3779) overdues csv fix 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 6c2a00a57c..7ca21e5fa2 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 5a6f0fcf16..fcec17f8e8 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 @@

Items Overdue as of

-

">Download file of all overdues (for branch all branches. Other filters are ignored)

+

&">Download file of all overdues (for branch all branches. Other filters are ignored)

@@ -41,7 +41,7 @@ "> -"> , by +"> , by @@ -50,7 +50,7 @@
-
+

Filter On:

    -- 2.39.5