Bug 32482: (follow-up) Add markup comments
[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
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use Modern::Perl;
24
25 # standard or CPAN modules used
26 use CGI qw(:standard -utf8);
27 use Encode;
28
29 # Koha modules used
30 use C4::Context;
31 use C4::Output qw( output_html_with_http_headers );
32 use C4::Auth qw( get_template_and_user );
33 use C4::Biblio qw( GetXmlBiblio );
34 use C4::XSLT;
35
36 use Koha::Biblios;
37 use Koha::Import::Records;
38
39 my $input= CGI->new;
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41   {
42     template_name   => "catalogue/showmarc.tt",
43     query           => $input,
44     type            => "intranet",
45     flagsrequired   => { catalogue => 1  },
46   }
47 );
48
49 my $biblionumber= $input->param('id');
50 my $importid= $input->param('importid');
51 my $view= $input->param('viewas')||'';
52
53 my $marcflavour = C4::Context->preference('marcflavour');
54
55 my $record;
56 my $record_type = 'biblio';
57 my $format = $marcflavour eq 'UNIMARC' ? 'UNIMARC' : 'USMARC';
58 if ($importid) {
59     my $import_record = Koha::Import::Records->find($importid);
60     if ($import_record) {
61         if ($marcflavour eq 'UNIMARC' && $import_record->record_type eq 'auth') {
62             $format = 'UNIMARCAUTH';
63         }
64
65         $record = $import_record->get_marc_record();
66     }
67 }
68 else {
69     my $biblio = Koha::Biblios->find($biblionumber);
70     $record = $biblio->metadata->record;
71 }
72 if(!ref $record) {
73     print $input->redirect("/cgi-bin/koha/errors/404.pl");
74     exit;
75 }
76
77 if($view eq 'card' || $view eq 'html') {
78     my $xml = $importid ? $record->as_xml($format): GetXmlBiblio($biblionumber);
79     my $xsl;
80     if ( $view eq 'card' ){
81         $xsl = $marcflavour eq 'UNIMARC' ? 'UNIMARC_compact.xsl' : 'compact.xsl';
82     }
83     else {
84         $xsl = 'plainMARC.xsl';
85     }
86     my $htdocs = C4::Context->config('intrahtdocs');
87     my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'intranet', $input);
88     $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
89     print $input->header(-charset => 'UTF-8'),
90           Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
91 }
92 else {
93     $template->param( MARC_FORMATTED => $record->as_formatted );
94     output_html_with_http_headers $input, $cookie, $template->output;
95 }