Proposed fix for Bug 5106 - Simplify MARC view choices in the OPAC (Conflict marker...
[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
33 # Koha modules used
34 use C4::Context;
35 use C4::Output;
36 use C4::Auth;
37 use C4::Biblio;
38 use C4::ImportBatch;
39 use XML::LibXSLT;
40 use XML::LibXML;
41
42 my $input       = new CGI;
43 my $biblionumber = $input->param('id');
44 my $importid    = $input->param('importid');
45 my $view                = $input->param('viewas') || 'marc';
46
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
48         template_name   => "opac-showmarc.tmpl",
49         query           => $input,
50         type            => "opac",
51         authnotrequired => 1,
52         debug           => 1,
53 });
54
55 $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, );
56 my ($record, $xmlrecord);
57 if ($importid) {
58         my ($marc,$encoding) = GetImportRecordMarc($importid);
59         $record = MARC::Record->new_from_usmarc($marc) ;
60         if($view eq 'card') {
61                 $xmlrecord = $record->as_xml();
62         } 
63 }
64                 
65 if ($view eq 'card') {
66     $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
67     my $xslfile = C4::Context->config('opachtdocs')."/prog/en/xslt/compact.xsl";
68     my $parser = XML::LibXML->new();
69     my $xslt   = XML::LibXSLT->new();
70     my $source = $parser->parse_string($xmlrecord);
71     my $style_doc = $parser->parse_file($xslfile);
72     my $stylesheet = $xslt->parse_stylesheet($style_doc);
73     my $results = $stylesheet->transform($source);
74     my $newxmlrecord = $stylesheet->output_string($results);
75     #warn $newxmlrecord;
76     print $input->header(), $newxmlrecord;
77     exit;
78 } elsif ($view eq 'html'){
79     $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
80     my $xslfile = C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACMARCdetail.xsl";
81     my $parser = XML::LibXML->new();
82     my $xslt   = XML::LibXSLT->new();
83     my $source = $parser->parse_string($xmlrecord);
84     my $style_doc = $parser->parse_file($xslfile);
85     my $stylesheet = $xslt->parse_stylesheet($style_doc);
86     my $results = $stylesheet->transform($source);
87     my $newxmlrecord = $stylesheet->output_string($results);
88     #warn $newxmlrecord;
89     print $input->header(), $newxmlrecord;
90     exit;
91 } else {
92     $record =GetMarcBiblio($biblionumber) unless $record; 
93     $template->param( MARC_FORMATTED => $record->as_formatted );
94     output_html_with_http_headers $input, $cookie, $template->output;
95 }