Bug 14544: Get rid of C4::VirtualShelves and C4::VirtualShelves::Page
[koha.git] / opac / opac-showmarc.pl
1 #!/usr/bin/perl
2
3 # Copyright 2007 Liblime
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22
23 # standard or CPAN modules used
24 use CGI qw ( -utf8 );
25 use Encode;
26
27 # Koha modules used
28 use C4::Context;
29 use C4::Output;
30 use C4::Auth;
31 use C4::Biblio;
32 use C4::ImportBatch;
33 use C4::XSLT ();
34 use C4::Templates;
35
36 my $input       = new CGI;
37 my $biblionumber = $input->param('id');
38 $biblionumber   = int($biblionumber);
39 my $importid= $input->param('importid');
40 my $view= $input->param('viewas') || 'marc';
41
42 my $record;
43 if ($importid) {
44     my ($marc) = GetImportRecordMarc($importid);
45     $record = MARC::Record->new_from_usmarc($marc);
46 }
47 else {
48     $record =GetMarcBiblio($biblionumber);
49 }
50 if(!ref $record) {
51     print $input->redirect("/cgi-bin/koha/errors/404.pl");
52     exit;
53 }
54
55 if ($view eq 'card' || $view eq 'html') {
56     my $xml = $importid ? $record->as_xml(): GetXmlBiblio($biblionumber);
57     my $xsl =  $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl';
58     my $htdocs = C4::Context->config('opachtdocs');
59     my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input);
60     $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
61     print $input->header(-charset => 'UTF-8'),
62           Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
63 }
64 else { #view eq marc
65     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
66         template_name   => "opac-showmarc.tt",
67         query           => $input,
68         type            => "opac",
69         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
70         debug           => 1,
71     });
72     $template->param( MARC_FORMATTED => $record->as_formatted );
73     output_html_with_http_headers $input, $cookie, $template->output;
74 }