Bug 11592: Updated License Text and use Modern::Perl
[koha-equinox.git] / opac / opac-showmarc.pl
1 #!/usr/bin/perl
2
3 # Copyright 2007 Liblime
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 # standard or CPAN modules used
23 use CGI qw ( -utf8 );
24 use Encode;
25
26 # Koha modules used
27 use C4::Context;
28 use C4::Output;
29 use C4::Auth;
30 use C4::Biblio;
31 use C4::ImportBatch;
32 use C4::XSLT ();
33 use C4::Templates;
34
35 my $input       = new CGI;
36 my $biblionumber = $input->param('id');
37 $biblionumber   = int($biblionumber);
38 my $importid= $input->param('importid');
39 my $view= $input->param('viewas') || 'marc';
40
41 my $record;
42 if ($importid) {
43     my ($marc) = GetImportRecordMarc($importid);
44     $record = MARC::Record->new_from_usmarc($marc);
45 }
46 else {
47     $record =GetMarcBiblio($biblionumber);
48 }
49 if(!ref $record) {
50     print $input->redirect("/cgi-bin/koha/errors/404.pl");
51     exit;
52 }
53
54 if ($view eq 'card' || $view eq 'html') {
55     my $xml = $importid ? $record->as_xml(): GetXmlBiblio($biblionumber);
56     my $xsl =  $view eq 'card' ? 'compact.xsl' : 'plainMARC.xsl';
57     my $htdocs = C4::Context->config('opachtdocs');
58     my ($theme, $lang) = C4::Templates::themelanguage($htdocs, $xsl, 'opac', $input);
59     $xsl = "$htdocs/$theme/$lang/xslt/$xsl";
60     print $input->header(-charset => 'UTF-8'),
61           Encode::encode_utf8(C4::XSLT::engine->transform($xml, $xsl));
62 }
63 else { #view eq marc
64     my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
65         template_name   => "opac-showmarc.tt",
66         query           => $input,
67         type            => "opac",
68         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69         debug           => 1,
70     });
71     $template->param( MARC_FORMATTED => $record->as_formatted );
72     output_html_with_http_headers $input, $cookie, $template->output;
73 }