Bug 12150: Add missing space and correct innerHTML typo
[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;
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
35 my $input       = new CGI;
36 my $biblionumber = $input->param('id');
37 $biblionumber   = int($biblionumber);
38 my $importid= $input->param('importid');
39 my $view= $input->param('viewas') || 'marc';
40
41 my $record;
42 if ($importid) {
43     my ($marc) = GetImportRecordMarc($importid);
44     $record = MARC::Record->new_from_usmarc($marc);
45 }
46 else {
47     $record =GetMarcBiblio($biblionumber);
48 }
49 if(!ref $record) {
50     print $input->redirect("/cgi-bin/koha/errors/404.pl");
51     exit;
52 }
53
54 if ($view eq 'card' || $view eq 'html') {
55     my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
56     my $xslfile;
57     my $xslfilename;
58     my $htdocs  = C4::Context->config('opachtdocs');
59     my $theme   = C4::Context->preference("opacthemes");
60     my $lang = C4::Templates::_current_language();
61
62     if ($view eq 'card'){
63         $xslfile = "compact.xsl";
64     }
65     else { # must be html
66         $xslfile = 'plainMARC.xsl';
67     }
68     $xslfilename = "$htdocs/$theme/$lang/xslt/$xslfile";
69     $xslfilename = "$htdocs/$theme/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
70     $xslfilename = "$htdocs/prog/$lang/xslt/$xslfile" unless ( -f $xslfile );
71     $xslfilename = "$htdocs/prog/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
72
73     my $newxmlrecord = C4::XSLT::engine->transform($xmlrecord, $xslfilename);
74     print $input->header(-charset => 'UTF-8'), Encode::encode_utf8($newxmlrecord);
75 }
76 else { #view eq marc
77     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
78         template_name   => "opac-showmarc.tmpl",
79         query           => $input,
80         type            => "opac",
81         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
82         debug           => 1,
83     });
84     $template->param( MARC_FORMATTED => $record->as_formatted );
85     output_html_with_http_headers $input, $cookie, $template->output;
86 }