ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / opac / opac-export.pl
index d5f4c4f..a992d46 100755 (executable)
@@ -35,9 +35,26 @@ my $biblionumber = $query->param("bib")||0;
 $biblionumber = int($biblionumber);
 my $error = q{};
 
+# Determine logged in user's patron category.
+# Blank if not logged in.
+my $userenv = C4::Context->userenv;
+my $borcat = q{};
+if ($userenv) {
+    my $borrowernumber = $userenv->{'number'};
+    if ($borrowernumber) {
+        my $borrower = Koha::Patrons->find( { borrowernumber => $borrowernumber } );
+        $borcat = $borrower ? $borrower->categorycode : $borcat;
+    }
+}
+
 my $include_items = ($format =~ /bibtex/) ? 0 : 1;
-my $marc = GetMarcBiblio($biblionumber, $include_items)
-    if $biblionumber;
+my $marc = $biblionumber
+    ? GetMarcBiblio({
+        biblionumber => $biblionumber,
+        embed_items  => $include_items,
+        opac         => 1,
+        borcat       => $borcat })
+    : undef;
 
 if(!$marc) {
     print $query->redirect("/cgi-bin/koha/errors/404.pl");
@@ -45,8 +62,14 @@ if(!$marc) {
 }
 
 # ASSERT: There is a biblionumber, because GetMarcBiblio returned something.
-
-my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
+my $framework = GetFrameworkCode( $biblionumber );
+my $record_processor = Koha::RecordProcessor->new({
+    filters => 'ViewPolicy',
+    options => {
+        interface => 'opac',
+        frameworkcode => $framework
+    }
+});
 $record_processor->process($marc);
 
 if ($format =~ /endnote/) {
@@ -69,7 +92,7 @@ elsif ($format =~ /bibtex/) {
     $marc = marc2bibtex($marc,$biblionumber);
     $format = 'bibtex';
 }
-elsif ($format =~ /dc$/) {
+elsif ($format =~ /^(dc|oaidc|srwdc|rdfdc)$/i ) {
     # TODO: Dublin Core leaks fields marked hidden by framework.
     $marc = marc2dcxml($marc, undef, $biblionumber, $format);
     $format = "dublin-core.xml";
@@ -90,7 +113,6 @@ elsif ($format =~ /marcstd/) {
     $format = 'marcstd';
 }
 elsif ( $format =~ /isbd/ ) {
-    my $framework = GetFrameworkCode( $biblionumber );
     $marc   = GetISBDView({
         'record'    => $marc,
         'template'  => 'opac',