Bug 8278 - Replace YUI autocomplete in UNIMARC 210c plugin
[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 # standard or CPAN modules used
31 use CGI;
32 use Encode;
33
34 # Koha modules used
35 use C4::Context;
36 use C4::Output;
37 use C4::Auth;
38 use C4::Biblio;
39 use C4::ImportBatch;
40 use XML::LibXSLT;
41 use XML::LibXML;
42
43 my $input       = new CGI;
44 my $biblionumber = $input->param('id');
45 $biblionumber   = int($biblionumber);
46 my $importid= $input->param('importid');
47 my $view= $input->param('viewas') || 'marc';
48
49 my $record;
50 if ($importid) {
51     my ($marc) = GetImportRecordMarc($importid);
52     $record = MARC::Record->new_from_usmarc($marc);
53 }
54 else {
55     $record =GetMarcBiblio($biblionumber);
56 }
57
58 if ($view eq 'card' || $view eq 'html') {
59     my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
60     my $xslfile;
61     my $xslfilename;
62     my $htdocs  = C4::Context->config('opachtdocs');
63     my $theme   = C4::Context->preference("opacthemes");
64     my $lang = C4::Templates::_current_language();
65
66     if ($view eq 'card'){
67         $xslfile = "compact.xsl";
68     }
69     else { # must be html
70         $xslfile = C4::Context->preference('marcflavour') . "slim2OPACMARCdetail.xsl";
71     }
72     $xslfilename = "$htdocs/$theme/$lang/xslt/$xslfile";
73     $xslfilename = "$htdocs/$theme/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
74     $xslfilename = "$htdocs/prog/$lang/xslt/$xslfile" unless ( -f $xslfile );
75     $xslfilename = "$htdocs/prog/en/xslt/$xslfile" unless ( $lang ne 'en' && -f $xslfilename );
76
77     my $parser = XML::LibXML->new();
78     my $xslt   = XML::LibXSLT->new();
79     my $source = $parser->parse_string($xmlrecord);
80     my $style_doc = $parser->parse_file($xslfilename);
81     my $stylesheet = $xslt->parse_stylesheet($style_doc);
82     my $results = $stylesheet->transform($source);
83     my $newxmlrecord = $stylesheet->output_string($results);
84     print $input->header(-charset => 'UTF-8'), Encode::encode_utf8($newxmlrecord);
85 }
86 else { #view eq marc
87     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
88         template_name   => "opac-showmarc.tmpl",
89         query           => $input,
90         type            => "opac",
91         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
92         debug           => 1,
93     });
94     $template->param( MARC_FORMATTED => $record->as_formatted );
95     output_html_with_http_headers $input, $cookie, $template->output;
96 }