MT 1587 : CSV export for cart and shelves, with the ability to define different expor...
[koha.git] / opac / opac-downloadcart.pl
index 25fe7ce..fe80f30 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 ($bib_list && $format) {
     my $output;
 
     # retrieve biblios from shelf
+    my $firstpass = 1;
     foreach my $biblio (@bibs) {
 
        my $record = GetMarcBiblio($biblio);
@@ -65,9 +67,16 @@ if ($bib_list && $format) {
            case "iso2709" { $output .= $record->as_usmarc(); }
            case "ris"     { $output .= marc2ris($record); }
            case "bibtex"  { $output .= marc2bibtex($record, $biblio); }
+           # We're in the case of a csv profile (firstpass is used for headers printing) :
+            case /^\d+$/   { $output .= marc2csv($record, $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',
@@ -75,6 +84,7 @@ if ($bib_list && $format) {
     print $output;
 
 } else { 
+    $template->param(csv_profiles => GetCsvProfilesLoop());
     $template->param(bib_list => $bib_list); 
     output_html_with_http_headers $query, $cookie, $template->output;
 }