MT2116 : Addons to the CSV Export
[koha.git] / opac / opac-downloadshelf.pl
index b377109..a03a79b 100755 (executable)
@@ -31,6 +31,7 @@ use C4::Output;
 use C4::VirtualShelves;
 use C4::Record;
 use C4::Ris;
+use C4::Csv;
 use utf8;
 use open qw( :std :utf8);
 my $query = new CGI;
@@ -57,6 +58,7 @@ if ($shelfid && $format) {
     my $output;
 
     # retrieve biblios from shelf
+    my $firstpass = 1;
     foreach my $biblio (@$items) {
        my $biblionumber = $biblio->{biblionumber};
 
@@ -66,16 +68,23 @@ if ($shelfid && $format) {
            case "iso2709" { $output .= $record->as_usmarc(); }
            case "ris"     { $output .= marc2ris($record); }
            case "bibtex"  { $output .= marc2bibtex($record, $biblionumber); }
+           # We're in the case of a csv profile (firstpass is used for headers printing) :
+           case /^\d+$/   { $output .= marc2csv($biblionumber, $format, $firstpass); }
        }
+       $firstpass = 0;
     }
 
+    # If it was a CSV export we change the format after the export so the file extension is fine
+    $format = "csv" if ($format =~ m/^\d+$/);
+
     print $query->header(
        -type => 'application/octet-stream',
        -'Content-Transfer-Encoding' => 'binary',
        -attachment=>"shelf.$format");
     print $output;
 
-} else { 
+} else {
+    $template->param(csv_profiles => GetCsvProfilesLoop());
     $template->param(shelfid => $shelfid); 
     output_html_with_http_headers $query, $cookie, $template->output;
 }