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