Bug 17118: (follow-up 15381) Fix regression when clearing a linked authority
[koha.git] / svc / records / preview
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2013 BibLibre
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 use CGI;
22 use C4::Auth qw( get_template_and_user );
23 use C4::Biblio qw( GetMarcBiblio );
24 use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
25 use C4::Output qw( output_html_with_http_headers );
26 use Koha::MetadataRecord::Authority;
27
28 my $query = CGI->new();
29 my $record_id = $query->param('record_id');
30 my $record_type = $query->param('record_type') || 'biblio';
31 my $mmtid = $query->param('mmtid'); # Marc modification template id
32
33 my $record;
34 if ( $record_type eq 'biblio' ) {
35     $record = GetMarcBiblio( $record_id );
36 } else {
37     my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id );
38     $record = $authority->record;
39 }
40
41 if ( $mmtid ) {
42     ModifyRecordWithTemplate( $mmtid, $record );
43 }
44
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
46     template_name   => "catalogue/showmarc.tt",
47     query           => $query,
48     type            => "intranet",
49     authnotrequired => 1,
50 });
51
52 $template->param( MARC_FORMATTED => $record->as_formatted );
53 output_html_with_http_headers $query, $cookie, $template->output;