View | Details | Raw Unified | Return to bug 11876
Collapse All | Expand All

(-)a/catalogue/showdiffmarc.pl (-99 lines)
Lines 1-99 Link Here
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 2 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
44
45
if ( $biblionumber and $importid ) {
46
47
	# Init vars
48
	my ($recordBiblionumber, $recordImportid, $biblioTitle, $importTitle, $formatted1, $formatted2,
49
		$errorFormatted1, $errorFormatted2);
50
51
52
	# Prepare template
53
	my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54
		{
55
		    template_name   => "catalogue/showdiffmarc.tt",
56
		    query           => $input,
57
		    type            => "intranet",
58
		    authnotrequired => 0,
59
		    flagsrequired   => { catalogue => 1  },
60
		    debug           => 1,
61
		}
62
	);
63
64
65
	$recordBiblionumber =GetMarcBiblio($biblionumber);
66
	if( $recordBiblionumber ) {
67
		$formatted1 = $recordBiblionumber->as_formatted;
68
		my $data = GetBiblioData($biblionumber);
69
		$biblioTitle = $data->{title};
70
	} else {
71
		$errorFormatted1 = 1;
72
	}
73
74
	my ($marc,$encoding) = GetImportRecordMarc($importid);
75
	if( $marc ) {
76
		$recordImportid = MARC::Record->new_from_usmarc($marc) ;
77
		$formatted2 = $recordImportid->as_formatted;
78
		my $biblio = GetImportBiblios($importid);
79
		$importTitle = $biblio->[0]->{'title'};
80
	} else {
81
		$errorFormatted2 = 1;
82
	}
83
84
85
	$template->param( 	SCRIPT_NAME => $ENV{'SCRIPT_NAME'},
86
						BIBLIONUMBER => $biblionumber,
87
						IMPORTID => $importid,
88
						BIBLIOTITLE => $biblioTitle,
89
						IMPORTTITLE => $importTitle,
90
						MARC_FORMATTED1 => $formatted1,
91
						MARC_FORMATTED2 => $formatted2,
92
						ERROR_FORMATTED1 => $errorFormatted1,
93
						ERROR_FORMATTED2 => $errorFormatted2
94
					);
95
96
	output_html_with_http_headers $input, $cookie, $template->output;
97
} else {
98
	exit;
99
}
(-)a/koha-tmpl/intranet-tmpl/lib/jsdiff/jsdiff.js (+160 lines)
Line 0 Link Here
1
/*
2
 * Javascript Diff Algorithm
3
 *  By John Resig (http://ejohn.org/)
4
 *  Modified by Chu Alan "sprite"
5
 *
6
 * Released under the MIT license.
7
 *
8
 * More Info:
9
 *  http://ejohn.org/projects/javascript-diff-algorithm/
10
 */
11
12
function escape(s) {
13
    var n = s;
14
    n = n.replace(/&/g, "&");
15
    n = n.replace(/</g, "&lt;");
16
    n = n.replace(/>/g, "&gt;");
17
    n = n.replace(/"/g, "&quot;");
18
19
    return n;
20
}
21
22
function diffString( o, n ) {
23
  o = o.replace(/\s+$/, '');
24
  n = n.replace(/\s+$/, '');
25
26
  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
27
  var str = "";
28
29
  var oSpace = o.match(/\s+/g);
30
  if (oSpace == null) {
31
    oSpace = ["\n"];
32
  } else {
33
    oSpace.push("\n");
34
  }
35
  var nSpace = n.match(/\s+/g);
36
  if (nSpace == null) {
37
    nSpace = ["\n"];
38
  } else {
39
    nSpace.push("\n");
40
  }
41
42
  if (out.n.length == 0) {
43
      for (var i = 0; i < out.o.length; i++) {
44
        str += '<del>' + escape(out.o[i]) + oSpace[i] + "</del>";
45
      }
46
  } else {
47
    if (out.n[0].text == null) {
48
      for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
49
        str += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
50
      }
51
    }
52
53
    for ( var i = 0; i < out.n.length; i++ ) {
54
      if (out.n[i].text == null) {
55
        str += '<ins>' + escape(out.n[i]) + nSpace[i] + "</ins>";
56
      } else {
57
        var pre = "";
58
59
        for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
60
          pre += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
61
        }
62
        str += " " + out.n[i].text + nSpace[i] + pre;
63
      }
64
    }
65
  }
66
67
  return str;
68
}
69
70
function randomColor() {
71
    return "rgb(" + (Math.random() * 100) + "%, " +
72
                    (Math.random() * 100) + "%, " +
73
                    (Math.random() * 100) + "%)";
74
}
75
function diffString2( o, n ) {
76
  o = o.replace(/\s+$/, '');
77
  n = n.replace(/\s+$/, '');
78
79
  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
80
81
  var oSpace = o.match(/\s+/g);
82
  if (oSpace == null) {
83
    oSpace = ["\n"];
84
  } else {
85
    oSpace.push("\n");
86
  }
87
  var nSpace = n.match(/\s+/g);
88
  if (nSpace == null) {
89
    nSpace = ["\n"];
90
  } else {
91
    nSpace.push("\n");
92
  }
93
94
  var os = "";
95
  var colors = new Array();
96
  for (var i = 0; i < out.o.length; i++) {
97
      colors[i] = randomColor();
98
99
      if (out.o[i].text != null) {
100
          os += '<span style="background-color: ' +colors[i]+ '">' +
101
                escape(out.o[i].text) + oSpace[i] + "</span>";
102
      } else {
103
          os += "<del>" + escape(out.o[i]) + oSpace[i] + "</del>";
104
      }
105
  }
106
107
  var ns = "";
108
  for (var i = 0; i < out.n.length; i++) {
109
      if (out.n[i].text != null) {
110
          ns += '<span style="background-color: ' +colors[out.n[i].row]+ '">' +
111
                escape(out.n[i].text) + nSpace[i] + "</span>";
112
      } else {
113
          ns += "<ins>" + escape(out.n[i]) + nSpace[i] + "</ins>";
114
      }
115
  }
116
117
  return { o : os , n : ns };
118
}
119
120
function diff( o, n ) {
121
  var ns = new Object();
122
  var os = new Object();
123
124
  for ( var i = 0; i < n.length; i++ ) {
125
    if ( ns[ n[i] ] == null )
126
      ns[ n[i] ] = { rows: new Array(), o: null };
127
    ns[ n[i] ].rows.push( i );
128
  }
129
130
  for ( var i = 0; i < o.length; i++ ) {
131
    if ( os[ o[i] ] == null )
132
      os[ o[i] ] = { rows: new Array(), n: null };
133
    os[ o[i] ].rows.push( i );
134
  }
135
136
  for ( var i in ns ) {
137
    if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
138
      n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
139
      o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
140
    }
141
  }
142
143
  for ( var i = 0; i < n.length - 1; i++ ) {
144
    if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
145
         n[i+1] == o[ n[i].row + 1 ] ) {
146
      n[i+1] = { text: n[i+1], row: n[i].row + 1 };
147
      o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 };
148
    }
149
  }
150
151
  for ( var i = n.length - 1; i > 0; i-- ) {
152
    if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
153
         n[i-1] == o[ n[i].row - 1 ] ) {
154
      n[i-1] = { text: n[i-1], row: n[i].row - 1 };
155
      o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 };
156
    }
157
  }
158
159
  return { o: o, n: n };
160
}
(-)a/koha-tmpl/intranet-tmpl/lib/jsdiff/jsdiff.min.js (+10 lines)
Line 0 Link Here
1
/*
2
 * Javascript Diff Algorithm
3
 *  By John Resig (http://ejohn.org/)
4
 *  Modified by Chu Alan "sprite"
5
 *
6
 * Released under the MIT license.
7
 *
8
 * More Info:
9
 *  http://ejohn.org/projects/javascript-diff-algorithm/
10
 */function escape(a){var b=a;return b=b.replace(/&/g,"&amp;"),b=b.replace(/</g,"&lt;"),b=b.replace(/>/g,"&gt;"),b=b.replace(/"/g,"&quot;"),b}function diffString(a,b){a=a.replace(/\s+$/,""),b=b.replace(/\s+$/,"");var c=diff(a==""?[]:a.split(/\s+/),b==""?[]:b.split(/\s+/)),d="",e=a.match(/\s+/g);e==null?e=["\n"]:e.push("\n");var f=b.match(/\s+/g);f==null?f=["\n"]:f.push("\n");if(c.n.length==0)for(var g=0;g<c.o.length;g++)d+="<del>"+escape(c.o[g])+e[g]+"</del>";else{if(c.n[0].text==null)for(b=0;b<c.o.length&&c.o[b].text==null;b++)d+="<del>"+escape(c.o[b])+e[b]+"</del>";for(var g=0;g<c.n.length;g++)if(c.n[g].text==null)d+="<ins>"+escape(c.n[g])+f[g]+"</ins>";else{var h="";for(b=c.n[g].row+1;b<c.o.length&&c.o[b].text==null;b++)h+="<del>"+escape(c.o[b])+e[b]+"</del>";d+=" "+c.n[g].text+f[g]+h}}return d}function randomColor(){return"rgb("+Math.random()*100+"%, "+Math.random()*100+"%, "+Math.random()*100+"%)"}function diffString2(a,b){a=a.replace(/\s+$/,""),b=b.replace(/\s+$/,"");var c=diff(a==""?[]:a.split(/\s+/),b==""?[]:b.split(/\s+/)),d=a.match(/\s+/g);d==null?d=["\n"]:d.push("\n");var e=b.match(/\s+/g);e==null?e=["\n"]:e.push("\n");var f="",g=new Array;for(var h=0;h<c.o.length;h++)g[h]=randomColor(),c.o[h].text!=null?f+='<span style="background-color: '+g[h]+'">'+escape(c.o[h].text)+d[h]+"</span>":f+="<del>"+escape(c.o[h])+d[h]+"</del>";var i="";for(var h=0;h<c.n.length;h++)c.n[h].text!=null?i+='<span style="background-color: '+g[c.n[h].row]+'">'+escape(c.n[h].text)+e[h]+"</span>":i+="<ins>"+escape(c.n[h])+e[h]+"</ins>";return{o:f,n:i}}function diff(a,b){var c=new Object,d=new Object;for(var e=0;e<b.length;e++)c[b[e]]==null&&(c[b[e]]={rows:new Array,o:null}),c[b[e]].rows.push(e);for(var e=0;e<a.length;e++)d[a[e]]==null&&(d[a[e]]={rows:new Array,n:null}),d[a[e]].rows.push(e);for(var e in c)c[e].rows.length==1&&typeof d[e]!="undefined"&&d[e].rows.length==1&&(b[c[e].rows[0]]={text:b[c[e].rows[0]],row:d[e].rows[0]},a[d[e].rows[0]]={text:a[d[e].rows[0]],row:c[e].rows[0]});for(var e=0;e<b.length-1;e++)b[e].text!=null&&b[e+1].text==null&&b[e].row+1<a.length&&a[b[e].row+1].text==null&&b[e+1]==a[b[e].row+1]&&(b[e+1]={text:b[e+1],row:b[e].row+1},a[b[e].row+1]={text:a[b[e].row+1],row:e+1});for(var e=b.length-1;e>0;e--)b[e].text!=null&&b[e-1].text==null&&b[e].row>0&&a[b[e].row-1].text==null&&b[e-1]==a[b[e].row-1]&&(b[e-1]={text:b[e-1],row:b[e].row-1},a[b[e].row-1]={text:a[b[e].row-1],row:e-1});return{o:a,n:b}};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (+3 lines)
Lines 607-612 Link Here
607
            <h2>jQuery Colvis plugin</h2>
607
            <h2>jQuery Colvis plugin</h2>
608
            <p>The <a href="http://datatables.net/extensions/colvis/">controls for column visiblity in DataTables</a>
608
            <p>The <a href="http://datatables.net/extensions/colvis/">controls for column visiblity in DataTables</a>
609
                by Allan Jardine is licensed under the BSD 3 and GPL v2 license.</p>
609
                by Allan Jardine is licensed under the BSD 3 and GPL v2 license.</p>
610
611
            <h2>Javascript Diff Algorithm</h2>
612
            <p>The <a href="http://ejohn.org/projects/javascript-diff-algorithm/">Javascript Diff Algorithm</a> plugin by John Resig is licensed under the <a href="http://opensource.org/licenses/mit-license.php">MIT License</a>.</p>
610
        </div>
613
        </div>
611
614
612
        <div id="translations">
615
        <div id="translations">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/showdiffmarc.tt (-50 lines)
Lines 1-50 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha -- Cataloging: MARC Import</title>
3
4
<style>
5
div#main {
6
	width: 100%;
7
	margin: 10px auto;
8
}
9
10
div.col1,
11
div.col2 {
12
	float: left;
13
	width: 46%;
14
	margin-left: 3%;
15
16
}
17
18
pre {
19
	padding: 10px;
20
	overflow: scroll;
21
}
22
</style>
23
24
[% INCLUDE 'doc-head-close.inc' %]
25
26
</head>
27
<body>
28
29
<div id="main">
30
	<div class="col1">
31
		<h2>Original</h2>
32
		[% IF ( ERROR_FORMATTED1 ) %]
33
			<p>The biblionumber <em>[% BIBLIONUMBER %]</em> doesn't match to any record.</p>
34
		[% ELSE %]
35
			<h1>[% BIBLIOTITLE %]</h1>
36
			<pre>[% MARC_FORMATTED1 %]</pre>
37
		[% END %]
38
	</div>
39
	<div class="col2">
40
		<h2>Imported</h2>
41
		[% IF ( ERROR_FORMATTED2 ) %]
42
			<p>The importid <em>[% IMPORTID %]</em> doesn't match to any record.</p>
43
		[% ELSE %]
44
			<h1>[% IMPORTTITLE %]</h1>
45
			<pre>[% MARC_FORMATTED2 %] </pre>
46
		[% END %]
47
	</div>
48
</div>
49
50
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/showdiffmarc.tt (+55 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Manage staged MARC records &rsaquo; Compare matched records</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" src="[% interface %]/lib/jsdiff/jsdiff.min.js"></script>
5
<script type="text/javascript">
6
    $(document).ready(function(){
7
      var diff1 = $("#col1 pre").text();
8
      var diff2 = $("#col2 pre").text();
9
      var diffs = diffString(diff1,diff2);
10
      $("#col1 pre,#col2 pre").html(diffs);
11
    });
12
</script>
13
<style type="text/css">
14
    ins { background-color: #e6ffe6; }
15
    del { background-color: #ffe6e6; }
16
    #col1 ins, #col2 del { display: none; }
17
    pre { padding: 10px; overflow: scroll; }
18
</style>
19
</head>
20
<body id="tools_compare-marc-import" class="tools">
21
22
[% INCLUDE 'header.inc' %]
23
24
<div id="breadcrumbs">
25
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/tools/manage-marc-import.pl">Manage staged MARC records</a> &rsaquo; <a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% batchid %]">Batch [% batchid %]</a> &rsaquo; Compare matched records
26
</div>
27
28
<div id="doc3">
29
    <div class="yui-g">
30
        <div id="col1" class="yui-u first">
31
            <h1>Original</h1>
32
            [% IF ( ERROR_FORMATTED1 ) %]
33
                <div class="dialog alert">
34
                    <p>The biblionumber <em>[% BIBLIONUMBER %]</em> doesn't match any existing record.</p>
35
                </div>
36
            [% ELSE %]
37
                <h2>[% BIBLIOTITLE %]</h2>
38
                <pre>[% MARC_FORMATTED1 %]</pre>
39
            [% END %]
40
        </div>
41
        <div id="col2" class="yui-u">
42
            <h1>Imported</h1>
43
            [% IF ( ERROR_FORMATTED2 ) %]
44
                <div class="dialog alert">
45
                    <p>The import id number <em>[% IMPORTID %]</em> doesn't match any existing record.</p>
46
                </div>
47
            [% ELSE %]
48
                <h2>[% IMPORTTITLE %]</h2>
49
                <pre>[% MARC_FORMATTED2 %] </pre>
50
            [% END %]
51
        </div>
52
    </div>
53
54
<p><a href="/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=[% batchid %]">Return to staged MARC batch [% batchid %]</a></p>
55
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/tools/batch_records_ajax.pl (-1 / +1 lines)
Lines 107-113 foreach my $record (@$records) { Link Here
107
          || q{},
107
          || q{},
108
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
108
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
109
        match_id => $match_id,
109
        match_id => $match_id,
110
        diff_url => $match_id ? "/cgi-bin/koha/catalogue/showdiffmarc.pl?importid=$record->{import_record_id}&id=$match_id" : undef
110
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id" : undef
111
      };
111
      };
112
}
112
}
113
113
(-)a/tools/showdiffmarc.pl (-1 / +101 lines)
Line 0 Link Here
0
- 
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
}

Return to bug 11876