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' ) || '';
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;
borname => $bornamefilter,
order => $order,
showall => $showall,
+ csv_param_string => $input->query_string(),
);
my @sort_roots = qw(borrower title barcode date_due);
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;
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";
+}
<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">
<!-- 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>
</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>