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