Bug 12265: [QA Follow-up] Replace DBIx search by find
[koha.git] / catalogue / showmarc.pl
1 #!/usr/bin/perl
2
3 # Koha library project  www.koha-community.org
4
5 # Copyright 2007 Liblime
6 # Parts copyright 2010 BibLibre
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 3 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 use strict;
24 use warnings;
25
26 # standard or CPAN modules used
27 use CGI qw(:standard);
28 use DBI;
29 use Encode;
30
31 # Koha modules used
32 use C4::Context;
33 use C4::Output;
34 use C4::Auth;
35 use C4::Biblio;
36 use C4::ImportBatch;
37 use C4::XSLT ();
38
39 my $input= new CGI;
40 my $biblionumber= $input->param('id');
41 my $importid= $input->param('importid');
42 my $view= $input->param('viewas')||'';
43
44 my $record;
45 if ($importid) {
46     my ($marc) = GetImportRecordMarc($importid);
47     $record = MARC::Record->new_from_usmarc($marc);
48 }
49 else {
50     $record =GetMarcBiblio($biblionumber);
51 }
52 if(!ref $record) {
53     print $input->redirect("/cgi-bin/koha/errors/404.pl");
54     exit;
55 }
56
57 if($view eq 'card') {
58     my $themelang =  '/' . C4::Languages::getlanguage($input);
59     my $xmlrecord= $importid? $record->as_xml(): GetXmlBiblio($biblionumber);
60     my $xslfile =
61       C4::Context->config('intrahtdocs') . '/prog' . $themelang . "/xslt/compact.xsl";
62     if ( ! -f $xslfile && $themelang ne '/en' ) {
63         $xslfile=~s#$themelang#/en#;
64     }
65     my $newxmlrecord = C4::XSLT::engine->transform($xmlrecord, $xslfile);
66     print $input->header(-charset => 'UTF-8'), Encode::encode_utf8($newxmlrecord);
67 }
68 else {
69     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
70       {
71         template_name   => "catalogue/showmarc.tmpl",
72         query           => $input,
73         type            => "intranet",
74         authnotrequired => 0,
75         flagsrequired   => { catalogue => 1  },
76         debug           => 1,
77       }
78     );
79     $template->param( MARC_FORMATTED => $record->as_formatted );
80     output_html_with_http_headers $input, $cookie, $template->output;
81 }