Bug 6632 [Signed Off] add html filter to prevent XSS
[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 # standard or CPAN modules used
29 use CGI qw(:standard);
30 use DBI;
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 $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
69
70 my $xslfile = C4::Context->config('intrahtdocs')."/prog/en/xslt/compact.xsl";
71 my $parser = XML::LibXML->new();
72 my $xslt = XML::LibXSLT->new();
73 my $source = $parser->parse_string($xmlrecord);
74 my $style_doc = $parser->parse_file($xslfile);
75 my $stylesheet = $xslt->parse_stylesheet($style_doc);
76 my $results = $stylesheet->transform($source);
77 my $newxmlrecord = $stylesheet->output_string($results);
78 #warn $newxmlrecord;
79 print "Content-type: text/html\n\n";
80 utf8::encode($newxmlrecord);
81 print $newxmlrecord;
82
83 } else {
84
85 $record =GetMarcBiblio($biblionumber) unless $record; 
86
87 my $formatted = $record->as_formatted;
88 $template->param( MARC_FORMATTED => $formatted );
89
90 output_html_with_http_headers $input, $cookie, $template->output;
91 }