Bug 8643: Fix IsMarcStructureInternal tests
[koha.git] / opac / opac-showmarc.pl
blob232eac50a8578434fe76c2c77a82a34d6d2f66ed
1 #!/usr/bin/perl
3 # Copyright 2007 Liblime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 # standard or CPAN modules used
23 use CGI qw ( -utf8 );
24 use Encode;
26 # Koha modules used
27 use C4::Context;
28 use C4::Output;
29 use C4::Auth;
30 use C4::Biblio;
31 use C4::ImportBatch;
32 use C4::XSLT ();
33 use C4::Templates;
34 use Koha::RecordProcessor;
36 my $input = new CGI;
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
38 template_name => "opac-showmarc.tt",
39 query => $input,
40 type => "opac",
41 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
42 debug => 1,
43 });
44 my $biblionumber = $input->param('id');
45 $biblionumber = int($biblionumber);
46 my $importid= $input->param('importid');
47 my $view= $input->param('viewas') || 'marc';
49 my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy' });
51 my $record;
52 if ($importid) {
53 my ($marc) = GetImportRecordMarc($importid);
54 $record = MARC::Record->new_from_usmarc($marc);
56 else {
57 $record = GetMarcBiblio({ biblionumber => $biblionumber });
58 my $framework = GetFrameworkCode($biblionumber);
59 $record_processor->options({
60 interface => 'opac',
61 frameworkcode => $framework
62 });
65 if(!ref $record) {
66 print $input->redirect("/cgi-bin/koha/errors/404.pl");
67 exit;
70 $record_processor->process($record);
72 if ($view eq 'card' || $view eq 'html') {
73 my $xml = $record->as_xml;
74 my $xsl = $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl';
75 my $htdocs = C4::Context->config('opachtdocs');
76 my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input);
77 $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
78 output_html_with_http_headers $input, undef, Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
80 else { #view eq marc
81 $template->param( MARC_FORMATTED => $record->as_formatted );
82 output_html_with_http_headers $input, $cookie, $template->output;