Bug 30477: Add new UNIMARC installer translation files
[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 ApplyMarcOverlayRules );
24 use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate );
25 use C4::Output qw( output_html_with_http_headers );
26
27 use Koha::MetadataRecord::Authority;
28 use Koha::Patrons;
29
30 my $query = CGI->new();
31 my $record_id = $query->param('record_id');
32 my $record_type = $query->param('record_type') || 'biblio';
33 my $overlay_context = $query->param('overlay_context');
34 my $mmtid = $query->param('mmtid'); # Marc modification template id
35
36 my $record;
37 if ( $record_type eq 'biblio' ) {
38     $record = GetMarcBiblio({ biblionumber => $record_id });
39 } else {
40     my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id );
41     $record = $authority->record;
42 }
43
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
45     template_name   => "catalogue/showmarc.tt",
46     query           => $query,
47     type            => "intranet",
48 });
49
50
51 if ($mmtid) {
52     ModifyRecordWithTemplate( $mmtid, $record );
53
54     if (   $record_type eq 'biblio'
55         && C4::Context->preference('MARCOverlayRules')
56         && $overlay_context )
57     {
58         my $logged_in_user = Koha::Patrons->find($loggedinuser);
59         $record = ApplyMarcOverlayRules(
60             {
61                 biblionumber    => $record_id,
62                 record          => $record,
63                 overlay_context => {
64                     source       => $overlay_context,
65                     categorycode => $logged_in_user->categorycode,
66                     userid       => $logged_in_user->userid
67                 },
68             }
69         );
70     }
71 }
72
73 $template->param( MARC_FORMATTED => $record->as_formatted );
74 output_html_with_http_headers $query, $cookie, $template->output;