Merge remote-tracking branch 'origin/new/bug_6966'
[koha.git] / opac / opac-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;
29
30 use open OUT=>':utf8', ':std';
31
32 # standard or CPAN modules used
33 use CGI;
34 use Encode;
35
36 # Koha modules used
37 use C4::Context;
38 use C4::Output;
39 use C4::Auth;
40 use C4::Biblio;
41 use C4::ImportBatch;
42 use XML::LibXSLT;
43 use XML::LibXML;
44
45 my $input       = new CGI;
46 my $biblionumber = $input->param('id');
47 my $importid    = $input->param('importid');
48 my $view                = $input->param('viewas') || 'marc';
49
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
51         template_name   => "opac-showmarc.tmpl",
52         query           => $input,
53         type            => "opac",
54         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
55         debug           => 1,
56 });
57
58 $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, );
59 my ($record, $xmlrecord);
60 if ($importid) {
61         my ($marc,$encoding) = GetImportRecordMarc($importid);
62         $record = MARC::Record->new_from_usmarc($marc) ;
63         if($view eq 'card') {
64                 $xmlrecord = $record->as_xml();
65         }
66 }
67
68 if ($view eq 'card' || $view eq 'html') {
69     $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
70     my $xslfile;
71     my $themelang = '/' . C4::Context->preference("opacthemes") .  '/' . C4::Templates::_current_language();
72
73     if ($view eq 'card'){
74         $xslfile = C4::Context->config('opachtdocs').$themelang."/xslt/compact.xsl";
75     }
76     else { # must be html
77         $xslfile = C4::Context->config('opachtdocs').$themelang."/xslt/MARC21slim2OPACMARCdetail.xsl";
78     }
79     my $parser = XML::LibXML->new();
80     my $xslt   = XML::LibXSLT->new();
81     my $source = $parser->parse_string($xmlrecord);
82     my $style_doc = $parser->parse_file($xslfile);
83     my $stylesheet = $xslt->parse_stylesheet($style_doc);
84     my $results = $stylesheet->transform($source);
85     my $newxmlrecord = $stylesheet->output_string($results);
86     $newxmlrecord = Encode::decode_utf8($newxmlrecord) unless utf8::is_utf8($newxmlrecord);
87     print $input->header(-charset => 'UTF-8'), $newxmlrecord;
88 } else {
89     $record =GetMarcBiblio($biblionumber) unless $record; 
90     $template->param( MARC_FORMATTED => $record->as_formatted );
91     output_html_with_http_headers $input, $cookie, $template->output;
92 }