Bug 6540 - Add defaultsql command line option
[koha.git] / catalogue / showmarc.pl
blobbd557e966e7f4e0a4dbd1ca9e0158565f8de6c26
1 #!/usr/bin/perl
3 # Koha library project www.koha-community.org
5 # Licensed under the GPL
7 # Copyright 2007 Liblime
8 # Parts copyright 2010 BibLibre
10 # This file is part of Koha.
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.
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.
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.
25 use strict;
26 #use warnings; FIXME - Bug 2505
28 # standard or CPAN modules used
29 use CGI qw(:standard);
30 use DBI;
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;
41 my $input = new CGI;
42 my $biblionumber = $input->param('id');
43 my $importid = $input->param('importid');
44 my $view = $input->param('viewas');
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48 template_name => "catalogue/showmarc.tmpl",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { catalogue => 1 },
53 debug => 1,
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();
67 if($view eq 'card') {
68 $xmlrecord = GetXmlBiblio($biblionumber) unless $xmlrecord;
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;
83 } else {
85 $record =GetMarcBiblio($biblionumber) unless $record;
87 my $formatted = $record->as_formatted;
88 $template->param( MARC_FORMATTED => $formatted );
90 output_html_with_http_headers $input, $cookie, $template->output;