Bug 31272: Use TT plugins for pickup library and due date in opac-reserve.pl
[koha.git] / tools / showdiffmarc.pl
1 #!/usr/bin/perl
2
3 # Koha library project  www.koha-community.org
4
5 # Copyright 2011 LibĂ©o
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23
24 # standard or CPAN modules used
25 use CGI qw(:standard -utf8);
26
27 # Koha modules used
28 use C4::Context;
29 use C4::Output qw( output_html_with_http_headers );
30 use C4::Auth qw( get_template_and_user );
31 use C4::Auth qw( get_template_and_user );
32 use C4::ImportBatch qw( GetImportBiblios );
33 use C4::AuthoritiesMarc qw( GetAuthority );
34
35 use Koha::Biblios;
36 use Koha::Import::Records;
37
38 # Input params
39 my $input        = CGI->new;
40 my $recordid = $input->param('id');
41 my $importid     = $input->param('importid');
42 my $batchid      = $input->param('batchid');
43 my $type      = $input->param('type');
44
45 if ( not $recordid or not $importid ) {
46     print $input->redirect("/cgi-bin/koha/errors/404.pl");
47     exit;
48 }
49
50 # Init vars
51 my ($record, $recordImportid, $recordTitle, $importTitle, $formatted1, $formatted2, $errorFormatted1, $errorFormatted2);
52
53 # Prepare template
54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55     {
56         template_name   => "tools/showdiffmarc.tt",
57         query           => $input,
58         type            => "intranet",
59         flagsrequired   => { tools => 'manage_staged_marc' },
60     }
61 );
62
63 if ( $type eq 'biblio' ) {
64     my $biblio = Koha::Biblios->find( $recordid );
65     $record = $biblio->metadata->record->({ embed_items => 1 });
66     $recordTitle = $biblio->title;
67 }
68 elsif ( $type eq 'auth' ) {
69     $record = GetAuthority( $recordid );
70     $recordTitle = "Authority number " . $recordid; #FIXME we should get the main heading
71 }
72 if( $record ) {
73     $formatted1 = $record->as_formatted;
74 } else {
75     $errorFormatted1 = 1;
76 }
77
78 if( $importid ) {
79     my $import_record = Koha::Import::Records->find($importid);
80     my $recordImportid = $import_record->get_marc_record({ embed_items => 1 });
81     $formatted2 = $recordImportid->as_formatted;
82     my $biblio = GetImportBiblios($importid);
83     $importTitle = $biblio->[0]->{'title'};
84 } else {
85     $errorFormatted2 = 1;
86 }
87
88 $template->param(
89     SCRIPT_NAME      => '/cgi-bin/koha/tools/showdiffmarc.pl',
90     RECORDID         => $recordid,
91     IMPORTID         => $importid,
92     RECORDTITLE      => $recordTitle,
93     IMPORTTITLE      => $importTitle,
94     MARC_FORMATTED1  => $formatted1,
95     MARC_FORMATTED2  => $formatted2,
96     ERROR_FORMATTED1 => $errorFormatted1,
97     ERROR_FORMATTED2 => $errorFormatted2,
98     batchid          => $batchid
99 );
100
101 output_html_with_http_headers $input, $cookie, $template->output;