Bug 7330 - System preferences editor generates errors in the log with each search
[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 2 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; FIXME - Bug 2505
25
26 use open OUT=>":encoding(UTF-8)", ':std';
27 # standard or CPAN modules used
28 use CGI qw(:standard);
29 use DBI;
30 use Encode;
31
32 # Koha modules used
33 use C4::Context;
34 use C4::Output;
35 use C4::Auth;
36 use C4::Biblio;
37 use C4::ImportBatch;
38 use XML::LibXSLT;
39 use XML::LibXML;
40
41 my $input       = new CGI;
42 my $biblionumber = $input->param('id');
43 my $importid            =       $input->param('importid');
44 my $view                = $input->param('viewas');
45
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47     {
48         template_name   => "catalogue/showmarc.tmpl",
49         query           => $input,
50         type            => "intranet",
51         authnotrequired => 0,
52         flagsrequired   => { catalogue => 1  },
53         debug           => 1,
54     }
55 );
56
57 $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, );
58 my ($record, $xmlrecord);
59 if($importid) {
60         my ($marc,$encoding) = GetImportRecordMarc($importid);
61                 $record = MARC::Record->new_from_usmarc($marc) ;
62         if($view eq 'card') {
63                 $xmlrecord = $record->as_xml();
64         } 
65 }
66
67 if($view eq 'card') {
68     my $themelang = '/' . C4::Context->preference("opacthemes") .  '/' . C4::Templates::_current_language();
69     $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
70     my $xslfile =
71       C4::Context->config('intrahtdocs') . $themelang . "/xslt/compact.xsl";
72     my $parser       = XML::LibXML->new();
73     my $xslt         = XML::LibXSLT->new();
74     my $source       = $parser->parse_string($xmlrecord);
75     my $style_doc    = $parser->parse_file($xslfile);
76     my $stylesheet   = $xslt->parse_stylesheet($style_doc);
77     my $results      = $stylesheet->transform($source);
78     my $newxmlrecord = $stylesheet->output_string($results);
79     $newxmlrecord = Encode::decode_utf8($newxmlrecord)
80       unless utf8::is_utf8($newxmlrecord)
81     ;    #decode only if not in perl internal format
82     print $input->header( -charset => 'UTF-8' ), $newxmlrecord;
83 }
84 else {
85     $record =GetMarcBiblio($biblionumber) unless $record;
86
87     my $formatted = $record->as_formatted;
88     $template->param( MARC_FORMATTED => $formatted );
89
90     my $output= $template->output;
91     $output=Encode::decode_utf8($output) unless utf8::is_utf8($output);
92     output_html_with_http_headers $input, $cookie, $output;
93 }