Bug 28784: Remove code related to num_paragraph cookie
[koha-ffzg.git] / opac / opac-showmarc.pl
index 250c519..57c63fe 100755 (executable)
@@ -25,36 +25,50 @@ use Encode;
 
 # Koha modules used
 use C4::Context;
-use C4::Output;
-use C4::Auth;
-use C4::Biblio;
+use C4::Output qw( output_html_with_http_headers );
+use C4::Auth qw( get_template_and_user );
 use C4::ImportBatch;
-use C4::XSLT ();
+use C4::XSLT;
 use C4::Templates;
 use Koha::RecordProcessor;
 
-my $input       = new CGI;
-my $biblionumber = $input->param('id');
-$biblionumber   = int($biblionumber);
-my $importid= $input->param('importid');
-my $view= $input->param('viewas') || 'marc';
+my $input       = CGI->new;
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
+    template_name   => "opac-showmarc.tt",
+    query           => $input,
+    type            => "opac",
+    authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
+});
 
-my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
+my $biblionumber = $input->param('id');
 
-my $record;
-if ($importid) {
-    my ($marc) = GetImportRecordMarc($importid);
-    $record = MARC::Record->new_from_usmarc($marc);
+unless ( $biblionumber ) {
+    print $input->redirect("/cgi-bin/koha/errors/400.pl");
+    exit;
 }
-else {
-    $record = GetMarcBiblio($biblionumber);
-    my $framework = GetFrameworkCode($biblionumber);
-    $record_processor->options({
-        interface => 'opac',
-        frameworkcode => $framework
-    });
+
+my $biblio;
+$biblio = Koha::Biblios->find( $biblionumber, { prefetch => [ 'metadata' ] } );
+
+unless ( $biblio ) {
+    print $input->redirect('/cgi-bin/koha/errors/404.pl');
+    exit;
 }
 
+my $view= $input->param('viewas') || 'marc';
+
+my $record_processor = Koha::RecordProcessor->new(
+    {
+        filters => 'ViewPolicy',
+        options => {
+            interface     => 'opac',
+            frameworkcode => $biblio->frameworkcode
+        }
+    }
+);
+
+my $record = $biblio->metadata->record;
+
 if(!ref $record) {
     print $input->redirect("/cgi-bin/koha/errors/404.pl");
     exit;
@@ -68,17 +82,9 @@ if ($view eq 'card' || $view eq 'html') {
     my $htdocs = C4::Context->config('opachtdocs');
     my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input);
     $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
-    print $input->header(-charset => 'UTF-8'),
-          Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
+    output_html_with_http_headers $input, undef, Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
 }
 else { #view eq marc
-    my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
-        template_name   => "opac-showmarc.tt",
-        query           => $input,
-        type            => "opac",
-        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
-        debug           => 1,
-    });
     $template->param( MARC_FORMATTED => $record->as_formatted );
     output_html_with_http_headers $input, $cookie, $template->output;
 }