ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / opac / opac-downloadcart.pl
index 6c374cd..ec5e2c8 100755 (executable)
@@ -28,11 +28,11 @@ use C4::Items;
 use C4::Output;
 use C4::Record;
 use C4::Ris;
-
 use Koha::CsvProfiles;
+use Koha::RecordProcessor;
 
 use utf8;
-my $query = new CGI;
+my $query = CGI->new();
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
     {
@@ -49,6 +49,13 @@ my $dbh     = C4::Context->dbh;
 
 if ($bib_list && $format) {
 
+    my $borcat = q{};
+    if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
+        # we need to fetch the borrower info here, so we can pass the category
+        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
+        $borcat = $borrower ? $borrower->categorycode : $borcat;
+    }
+
     my @bibs = split( /\//, $bib_list );
 
     my $marcflavour = C4::Context->preference('marcflavour');
@@ -63,9 +70,23 @@ if ($bib_list && $format) {
 
         # Other formats
     } else {
+        my $record_processor = Koha::RecordProcessor->new({
+            filters => 'ViewPolicy'
+        });
         foreach my $biblio (@bibs) {
 
-            my $record = GetMarcBiblio($biblio, 1);
+            my $record = GetMarcBiblio({
+                biblionumber => $biblio,
+                embed_items  => 1,
+                opac         => 1,
+                borcat       => $borcat });
+            my $framework = &GetFrameworkCode( $biblio );
+            $record_processor->options({
+                interface => 'opac',
+                frameworkcode => $framework
+            });
+            $record_processor->process($record);
+
             next unless $record;
 
             if ($format eq 'iso2709') {
@@ -78,7 +99,12 @@ if ($bib_list && $format) {
                 $output .= marc2bibtex($record, $biblio);
             }
             elsif ( $format eq 'isbd' ) {
-                $output   .= GetISBDView($biblio, "opac");
+                my $framework = GetFrameworkCode( $biblio );
+                $output   .= GetISBDView({
+                    'record'    => $record,
+                    'template'  => 'opac',
+                    'framework' => $framework,
+                });
                 $extension = "txt";
                 $type      = "text/plain";
             }
@@ -96,7 +122,7 @@ if ($bib_list && $format) {
     print $output;
 
 } else { 
-    $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]);
+    $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc', used_for => 'export_records' }) ]);
     $template->param(bib_list => $bib_list); 
     output_html_with_http_headers $query, $cookie, $template->output;
 }