Bug 20321: Remove get_biblionumber_from_isbn
[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 Modern::Perl;
24
25 # standard or CPAN modules used
26 use CGI qw(:standard -utf8);
27 use DBI;
28 use Encode;
29
30 # Koha modules used
31 use C4::Context;
32 use C4::Output;
33 use C4::Auth;
34 use C4::Biblio;
35 use C4::ImportBatch;
36 use C4::XSLT ();
37
38 my $input= new CGI;
39 my $biblionumber= $input->param('id');
40 my $importid= $input->param('importid');
41 my $view= $input->param('viewas')||'';
42
43 my $record;
44 if ($importid) {
45     $record = C4::ImportBatch::GetRecordFromImportBiblio( $importid, 'embed_items' );
46 }
47 else {
48     $record =GetMarcBiblio({ biblionumber => $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;
58     if ( $view eq 'card' ){
59         $xsl = C4::Context->preference('marcflavour') eq 'UNIMARC'
60               ? 'UNIMARC_compact.xsl' : 'compact.xsl';
61     }
62     else {
63         $xsl = 'plainMARC.xsl';
64     }
65     my $htdocs = C4::Context->config('intrahtdocs');
66     my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'intranet', $input);
67     $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
68     print $input->header(-charset => 'UTF-8'),
69           Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
70 }
71 else {
72     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
73       {
74         template_name   => "catalogue/showmarc.tt",
75         query           => $input,
76         type            => "intranet",
77         authnotrequired => 0,
78         flagsrequired   => { catalogue => 1  },
79         debug           => 1,
80       }
81     );
82     $template->param( MARC_FORMATTED => $record->as_formatted );
83     output_html_with_http_headers $input, $cookie, $template->output;
84 }