From e80c74b3399747a22efbc71508805442c83823bc Mon Sep 17 00:00:00 2001
From: mbeaulieu <mbeaulieu@inlibro.com>
Date: Thu, 7 Aug 2014 13:10:26 -0400
Subject: [PATCH] Bug 11876 - Add a diff view for staged MARC records.

New patch should apply correctly.

	modified:   C4/ImportBatch.pm
	modified:   koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
---
 C4/ImportBatch.pm                                  |   20 ++++
 .../prog/en/modules/tools/manage-marc-import.tt    |  115 ++++++++++++++++++++
 2 files changed, 135 insertions(+)

diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm
index a487cc6..51a0585 100644
--- a/C4/ImportBatch.pm
+++ b/C4/ImportBatch.pm
@@ -58,6 +58,7 @@ BEGIN {
     GetStagedWebserviceBatches
     GetImportBatchRangeDesc
     GetNumberOfNonZ3950ImportBatches
+    GetImportBiblios
     GetImportRecordsRange
 	GetItemNumbersFromImportBatch
     
@@ -1017,6 +1018,25 @@ sub GetNumberOfNonZ3950ImportBatches {
     return $count;
 }
 
+=head2 GetImportBiblios
+
+  my $results = GetImportBiblios($importid);
+
+=cut
+
+sub GetImportBiblios {
+    my ($import_record_id) = @_;
+
+    my $dbh = C4::Context->dbh;
+    my $query = "SELECT * FROM import_biblios WHERE import_record_id = ?";
+    my $sth = $dbh->prepare_cached($query);
+    $sth->execute($import_record_id);
+    my $results = $sth->fetchall_arrayref({});
+    $sth->finish();
+    return $results;
+
+}
+
 =head2 GetImportRecordsRange
 
   my $results = GetImportRecordsRange($batch_id, $offset, $results_per_group);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
index 3d5f01d..f2b3c26 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt
@@ -1,3 +1,30 @@
+[% BLOCK final_match_link %]
+    [% IF ( record.record_type == 'biblio' ) %]
+        <a target="_blank" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.final_match_id %]">[% record.final_match_id %]</a>
+    [% ELSIF ( record.record_type == 'auth' ) %]
+        <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record.final_match_id %]">[% record.final_match_id %]</a>
+    [% END %]
+[% END %]
+[% BLOCK match_link %]
+    [% IF ( record_lis.match_id ) %]
+        <tr>
+            <td />
+            [% IF ( record.record_type == 'biblio' ) %]
+                <td class="highlight" colspan="5">Matches biblio [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record_lis.match_id %]">[% record_lis.match_citation %]</a></td>
+            [% ELSIF ( record.record_type == 'auth' ) %]
+                <td class="highlight" colspan="5">Matches authority [% record_lis.match_id %] (score = [% record_lis.match_score %]): <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% record_lis.match_id %]">[% record_lis.match_citation %]</a> |
+        <a href="/cgi-bin/koha/authorities/merge.pl?mergereference=breeding&authid=[% record_lis.match_id %]&authid=[% record_lis.import_record_id %]">Merge</a>
+                </td>
+            [% END %]
+        </tr>
+    [% ELSIF ( record.record_type == 'auth') %]
+        <tr data-authid="[% record_lis.import_record_id %]">
+            <td />
+            <td class="highlight" colspan="4"><a href="#" class="merge_auth">Search for a record to merge in a new window</a></td>
+        </tr>
+    [% END %]
+[% END %]
+
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records
 [% IF ( import_batch_id ) %]
@@ -454,6 +481,94 @@ Page
     </table>
 [% END %]
 
+[% IF ( record_list ) %]
+  [% IF ( pages ) %]
+<div class="pages">
+Page
+    [% FOREACH page IN pages %]
+      [% IF ( page.current_page ) %]
+      <span class="current">[% page.page_number %]</span>
+      [% ELSE %]
+      <a class="nav" href="[% page.script_name %]?import_batch_id=[% import_batch_id %]&amp;offset=[% page.offset %]">[% page.page_number %]</a>
+      [% END %]
+    [% END %]
+</div>
+  [% END %]
+<table>
+  <tr>
+    <th>#</th>
+    <th>Citation</th>
+    <th>Status</th>
+    <th>Match?</th>
+    <th>Record</th>
+    <th><abbr title="Differences between the original biblio and the imported" lang="en">Diff</abbr></th>
+
+  </tr>
+  [% FOREACH record_lis IN record_list %]
+  [% UNLESS ( loop.odd ) %]<tr data-id="[% record_lis.import_record_id %]" class="highlight">[% ELSE %]<tr data-id="[% record_lis.import_record_id %]">[% END %]
+    <td>[% record_lis.record_sequence %]</td>
+    <td><a class="citation" href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% record_lis.import_record_id %]" rel="gb_page_center[600,500]">[% record_lis.citation %]</a></td>
+    <td>
+        [% IF ( record_lis.status == 'imported' ) %]
+            Imported
+        [% ELSIF ( record_lis.status == 'ignored' ) %]
+            Ignored
+        [% ELSIF ( record_lis.status == 'reverted' ) %]
+            Reverted
+        [% ELSIF ( record_lis.status == 'staged' ) %]
+            Staged
+        [% ELSIF ( record_lis.status == 'error' ) %]
+            Error
+        [% ELSE %]
+          [% record_lis.status %]
+        [% END %]
+    </td>
+    <td>
+        [% IF ( record_lis.overlay_status == 'no_match' ) %]
+            No match
+        [% ELSIF ( record_lis.overlay_status == 'match_applied' ) %]
+            Match applied
+        [% ELSIF ( record_lis.overlay_status == 'auto_match' ) %]
+            Match found
+        [% ELSE %]
+            [% record_lis.overlay_status %]
+        [% END %]
+    </td>
+    <td>[% IF ( record_lis.final_match_id ) %]
+        [% PROCESS final_match_link record=record_lis %]
+        [% END %]
+    </td>
+    [% IF ( record_lis.match_id ) %]
+        <td>
+            <a rel="gb_page_center[960,600]" href="/cgi-bin/koha/catalogue/showdiffmarc.pl?importid=[% record_lis.import_record_id %]&id=[% record_lis.match_id %]">View</a>
+        </td>
+    [% ELSE %]
+        <td>&nbsp;</td>
+    [% END %]
+  </tr>
+    [% PROCESS match_link record=record_lis %]
+  [% END %]
+</table>
+  [% IF ( pages ) %]
+<div class="pages">
+Page
+    [% FOREACH page IN pages %]
+      [% IF ( page.current_page ) %]
+      <span class="current">[% page.page_number %]</span>
+      [% ELSE %]
+      <a class="nav" href="[% page.script_name %]?import_batch_id=[% import_batch_id %]&amp;offset=[% page.offset %]">[% page.page_number %]</a>
+      [% END %]
+    [% END %]
+</div>
+  [% END %]
+[% ELSE %]
+  [% IF ( batch_info ) %]
+    <div class="dialog alert">There are no records in this batch to import.
+    <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a>.</div>
+
+  [% END %]
+[% END %]
+
 </div>
 </div>
 <div class="yui-b">
-- 
1.7.9.5