Merge remote-tracking branch 'kc/new/bug_5616' into kcmaster
[koha.git] / catalogue / showmarc.pl
1 #!/usr/bin/perl
2
3 # Koha library project  www.koha-community.org
4
5 # Licensed under the GPL
6
7 # Copyright 2007 Liblime
8 # Parts copyright 2010 BibLibre
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 use strict;
26 #use warnings; FIXME - Bug 2505
27
28 use open OUT=>':utf8', ':std';
29
30 # standard or CPAN modules used
31 use CGI qw(:standard);
32 use DBI;
33 use Encode;
34
35 # Koha modules used
36 use C4::Context;
37 use C4::Output;
38 use C4::Auth;
39 use C4::Biblio;
40 use C4::ImportBatch;
41 use XML::LibXSLT;
42 use XML::LibXML;
43
44 my $input       = new CGI;
45 my $biblionumber = $input->param('id');
46 my $importid            =       $input->param('importid');
47 my $view                = $input->param('viewas');
48
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50     {
51         template_name   => "catalogue/showmarc.tmpl",
52         query           => $input,
53         type            => "intranet",
54         authnotrequired => 0,
55         flagsrequired   => { catalogue => 1  },
56         debug           => 1,
57     }
58 );
59
60 $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, );
61 my ($record, $xmlrecord);
62 if($importid) {
63         my ($marc,$encoding) = GetImportRecordMarc($importid);
64                 $record = MARC::Record->new_from_usmarc($marc) ;
65         if($view eq 'card') {
66                 $xmlrecord = $record->as_xml();
67         } 
68 }
69                 
70 if($view eq 'card') {
71 $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
72
73 my $xslfile = C4::Context->config('intrahtdocs')."/prog/en/xslt/compact.xsl";
74 my $parser = XML::LibXML->new();
75 my $xslt = XML::LibXSLT->new();
76 my $source = $parser->parse_string($xmlrecord);
77 my $style_doc = $parser->parse_file($xslfile);
78 my $stylesheet = $xslt->parse_stylesheet($style_doc);
79 my $results = $stylesheet->transform($source);
80 my $newxmlrecord = $stylesheet->output_string($results);
81 $newxmlrecord=Encode::decode_utf8($newxmlrecord) unless utf8::is_utf8($newxmlrecord); #decode only if not in perl internal format
82 print $input->header(-charset => 'UTF-8'), $newxmlrecord;
83
84 } else {
85
86 $record =GetMarcBiblio($biblionumber) unless $record; 
87
88 my $formatted = $record->as_formatted;
89 $template->param( MARC_FORMATTED => $formatted );
90
91 my $output= $template->output;
92 $output=Encode::decode_utf8($output) unless utf8::is_utf8($output);
93 output_html_with_http_headers $input, $cookie, $output;
94 }