Bug 11876 [Follow-up] Add a diff view to staged MARC Records
[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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 use strict;
23 use warnings;
24
25 # standard or CPAN modules used
26 use CGI qw(:standard);
27 use DBI;
28
29 # Koha modules used
30 use C4::Context;
31 use C4::Output;
32 use C4::Auth;
33 use C4::Biblio;
34 use C4::ImportBatch;
35 use XML::LibXSLT;
36 use XML::LibXML;
37
38
39 # Input params
40 my $input        = new CGI;
41 my $biblionumber = $input->param('id');
42 my $importid     = $input->param('importid');
43 my $batchid      = $input->param('batchid');
44
45
46 if ( $biblionumber and $importid ) {
47
48     # Init vars
49     my ($recordBiblionumber, $recordImportid, $biblioTitle, $importTitle, $formatted1, $formatted2,
50         $errorFormatted1, $errorFormatted2);
51
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             authnotrequired => 0,
60             flagsrequired   => { tools => 'manage_staged_marc' },
61             debug           => 1,
62         }
63     );
64
65
66     $recordBiblionumber =GetMarcBiblio($biblionumber);
67     if( $recordBiblionumber ) {
68         $formatted1 = $recordBiblionumber->as_formatted;
69         my $data = GetBiblioData($biblionumber);
70         $biblioTitle = $data->{title};
71     } else {
72         $errorFormatted1 = 1;
73     }
74
75     my ($marc,$encoding) = GetImportRecordMarc($importid);
76     if( $marc ) {
77         $recordImportid = MARC::Record->new_from_usmarc($marc) ;
78         $formatted2 = $recordImportid->as_formatted;
79         my $biblio = GetImportBiblios($importid);
80         $importTitle = $biblio->[0]->{'title'};
81     } else {
82         $errorFormatted2 = 1;
83     }
84
85
86     $template->param(   SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
87                         BIBLIONUMBER => $biblionumber,
88                         IMPORTID => $importid,
89                         BIBLIOTITLE => $biblioTitle,
90                         IMPORTTITLE => $importTitle,
91                         MARC_FORMATTED1 => $formatted1,
92                         MARC_FORMATTED2 => $formatted2,
93                         ERROR_FORMATTED1 => $errorFormatted1,
94                         ERROR_FORMATTED2 => $errorFormatted2,
95                         batchid => $batchid
96                     );
97
98     output_html_with_http_headers $input, $cookie, $template->output;
99 } else {
100     exit;
101 }