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

(-)a/cataloguing/merge.pl (-164 / +144 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl 
1
#!/usr/bin/perl
2
3
2
4
# Copyright 2009 BibLibre
3
# Copyright 2009 BibLibre
5
# Parts Copyright Catalyst IT 2011
4
# Parts Copyright Catalyst IT 2011
Lines 19-26 Link Here
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
20
22
use strict;
21
use Modern::Perl;
23
#use warnings; FIXME - Bug 2505
22
24
use CGI;
23
use CGI;
25
use C4::Output;
24
use C4::Output;
26
use C4::Auth;
25
use C4::Auth;
Lines 38-44 my @errors; Link Here
38
37
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {
39
    {
41
        template_name   => "cataloguing/merge.tmpl",
40
        template_name   => "cataloguing/merge.tt",
42
        query           => $input,
41
        query           => $input,
43
        type            => "intranet",
42
        type            => "intranet",
44
        authnotrequired => 0,
43
        authnotrequired => 0,
Lines 55-206 if ($merge) { Link Here
55
    my $sth;
54
    my $sth;
56
55
57
    # Creating a new record from the html code
56
    # Creating a new record from the html code
58
    my $record       = TransformHtmlToMarc( $input );
57
    my $record = TransformHtmlToMarc( $input );
59
    my $tobiblio     =  $input->param('biblio1');
58
    my $ref_biblionumber = $input->param('ref_biblionumber');
60
    my $frombiblio   =  $input->param('biblio2');
59
    my @biblionumbers = $input->param('biblionumber');
60
    @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers;
61
61
62
    # Rewriting the leader
62
    # Rewriting the leader
63
    $record->leader(GetMarcBiblio($tobiblio)->leader());
63
    $record->leader(GetMarcBiblio($ref_biblionumber)->leader());
64
64
65
    my $frameworkcode = $input->param('frameworkcode');
65
    my $frameworkcode = $input->param('frameworkcode');
66
    my @notmoveditems;
66
    my @notmoveditems;
67
67
68
    # Modifying the reference record
68
    # Modifying the reference record
69
    ModBiblio($record, $tobiblio, $frameworkcode);
69
    ModBiblio($record, $ref_biblionumber, $frameworkcode);
70
70
71
    # Moving items from the other record to the reference record
71
    # Moving items from the other record to the reference record
72
    my $itemnumbers = get_itemnumbers_of($frombiblio);
72
    foreach my $biblionumber (@biblionumbers) {
73
    foreach my $itloop ($itemnumbers->{$frombiblio}) {
73
        my $itemnumbers = get_itemnumbers_of($biblionumber);
74
	foreach my $itemnumber (@$itloop) {
74
        foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
75
	    my $res = MoveItemFromBiblio($itemnumber, $frombiblio, $tobiblio);
75
            my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber);
76
	    if (not defined $res) {
76
            if (not defined $res) {
77
		push @notmoveditems, $itemnumber;
77
                push @notmoveditems, $itemnumber;
78
	    }
78
            }
79
	}
79
        }
80
    }
80
    }
81
    # If some items could not be moved :
81
    # If some items could not be moved :
82
    if (scalar(@notmoveditems) > 0) {
82
    if (scalar(@notmoveditems) > 0) {
83
		my $itemlist = join(' ',@notmoveditems);
83
        my $itemlist = join(' ',@notmoveditems);
84
		push @errors, "The following items could not be moved from the old record to the new one: $itemlist";
84
        push @errors, "The following items could not be moved from the old record to the new one: $itemlist";
85
    }
85
    }
86
86
87
    # Moving subscriptions from the other record to the reference record
87
    foreach my $biblionumber (@biblionumbers) {
88
    my $subcount = CountSubscriptionFromBiblionumber($frombiblio);
88
        # Moving subscriptions from the other record to the reference record
89
    if ($subcount > 0) {
89
        my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
90
	$sth = $dbh->prepare("UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?");
90
        if ($subcount > 0) {
91
	$sth->execute($tobiblio, $frombiblio);
91
            $sth = $dbh->prepare("
92
92
                UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
93
	$sth = $dbh->prepare("UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?");
93
            ");
94
	$sth->execute($tobiblio, $frombiblio);
94
            $sth->execute($ref_biblionumber, $biblionumber);
95
95
96
    }
96
            $sth = $dbh->prepare("
97
                UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
98
            ");
99
            $sth->execute($ref_biblionumber, $biblionumber);
100
        }
97
101
98
    # Moving serials
102
        # Moving serials
99
    $sth = $dbh->prepare("UPDATE serial SET biblionumber = ? WHERE biblionumber = ?");
103
        $sth = $dbh->prepare("UPDATE serial SET biblionumber = ? WHERE biblionumber = ?");
100
    $sth->execute($tobiblio, $frombiblio);
104
        $sth->execute($ref_biblionumber, $biblionumber);
101
105
102
    # TODO : Moving reserves
106
        # TODO : Moving reserves
103
107
104
    # Deleting the other record
108
        # Deleting the other record
105
    if (scalar(@errors) == 0) {
109
        if (scalar(@errors) == 0) {
106
	# Move holds
110
            # Move holds
107
	MergeHolds($dbh,$tobiblio,$frombiblio);
111
            MergeHolds($dbh, $ref_biblionumber, $biblionumber);
108
	my $error = DelBiblio($frombiblio);
112
            my $error = DelBiblio($biblionumber);
109
	push @errors, $error if ($error); 
113
            push @errors, $error if ($error);
114
        }
110
    }
115
    }
111
116
112
    # Parameters
117
    # Parameters
113
    $template->param(
118
    $template->param(
114
	result => 1,
119
        result => 1,
115
	biblio1 => $input->param('biblio1')
120
        ref_biblionumber => $input->param('ref_biblionumber')
116
    );
121
    );
117
122
118
#-------------------------
123
#-------------------------
119
# Show records to merge
124
# Show records to merge
120
#-------------------------
125
#-------------------------
121
} else {
126
} else {
122
    my $mergereference = $input->param('mergereference');
127
    my $ref_biblionumber = $input->param('ref_biblionumber');
123
    my $biblionumber = $input->param('biblionumber');
128
124
129
    if ($ref_biblionumber) {
125
    if (scalar(@biblionumber) != 2) {
130
        my $framework = $input->param('frameworkcode');
126
        push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged.";
131
        $framework //= GetFrameworkCode($ref_biblionumber);
127
    }
132
128
    else {
133
        # Getting MARC Structure
129
        my $data1 = GetBiblioData($biblionumber[0]);
134
        my $tagslib = GetMarcStructure(1, $framework);
130
        my $record1 = GetMarcBiblio($biblionumber[0]);
135
131
136
        # Creating a loop for display
132
        my $data2 = GetBiblioData($biblionumber[1]);
137
        my @records;
133
        my $record2 = GetMarcBiblio($biblionumber[1]);
138
        foreach (@biblionumber) {
134
139
            my $marcrecord = GetMarcBiblio($_);
135
        # Checks if both records use the same framework
140
            my $frameworkcode = GetFrameworkCode($_);
136
        my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]);
141
            my $record = {
137
        my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]);
142
                biblionumber => $_,
138
143
                record => $marcrecord,
139
144
                frameworkcode => $frameworkcode,
140
        my $subtitle1 = GetRecordValue('subtitle', $record1, $frameworkcode1);
145
                display => _createMarcHash($marcrecord, $tagslib),
141
        my $subtitle2 = GetRecordValue('subtitle', $record2, $frameworkcode1);
146
            };
142
147
            if ($ref_biblionumber and $ref_biblionumber == $_) {
143
        if ($mergereference) {
148
                $record->{reference} = 1;
144
149
                $template->param(ref_record => $record);
145
            my $framework;
150
                unshift @records, $record;
146
            if ($frameworkcode1 ne $frameworkcode2) {
147
                $framework = $input->param('frameworkcode')
148
                  or push @errors, "Famework not selected.";
149
            } else {
151
            } else {
150
                $framework = $frameworkcode1;
152
                push @records, $record;
151
            }
153
            }
152
153
            # Getting MARC Structure
154
            my $tagslib = GetMarcStructure(1, $framework);
155
156
            my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
157
158
            # Creating a loop for display
159
            my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib);
160
            my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib);
161
162
            # Parameters
163
            $template->param(
164
                biblio1 => $mergereference,
165
                biblio2 => $notreference,
166
                mergereference => $mergereference,
167
                record1 => @record1,
168
                record2 => @record2,
169
                framework => $framework,
170
            );
171
        }
154
        }
172
        else {
173
155
156
        # Parameters
157
        $template->param(
158
            ref_biblionumber => $ref_biblionumber,
159
            records => \@records,
160
            framework => $framework,
161
        );
162
    }
163
    else {
164
        my @records;
165
        foreach (@biblionumber) {
166
            my $frameworkcode = GetFrameworkCode($_);
167
            my $record = {
168
                biblionumber => $_,
169
                data => GetBiblioData($_),
170
                frameworkcode => $frameworkcode,
171
            };
172
            push @records, $record;
173
        }
174
        # Ask the user to choose which record will be the kept
174
        # Ask the user to choose which record will be the kept
175
            $template->param(
175
        $template->param(
176
                choosereference => 1,
176
            choosereference => 1,
177
                biblio1 => $biblionumber[0],
177
            records => \@records,
178
                biblio2 => $biblionumber[1],
178
        );
179
                title1 => $data1->{'title'},
179
180
                subtitle1 => $subtitle1,
180
        my $frameworks = getframeworks;
181
                title2 => $data2->{'title'},
181
        my @frameworkselect;
182
                subtitle2 => $subtitle2
182
        foreach my $thisframeworkcode ( keys %$frameworks ) {
183
            my %row = (
184
                value         => $thisframeworkcode,
185
                frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
183
            );
186
            );
184
            if ($frameworkcode1 ne $frameworkcode2) {
187
            push @frameworkselect, \%row;
185
                my $frameworks = getframeworks;
186
                my @frameworkselect;
187
                foreach my $thisframeworkcode ( keys %$frameworks ) {
188
                    my %row = (
189
                        value         => $thisframeworkcode,
190
                        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
191
                    );
192
                    if ($frameworkcode1 eq $thisframeworkcode){
193
                        $row{'selected'} = 1;
194
                        }
195
                    push @frameworkselect, \%row;
196
                }
197
                $template->param(
198
                    frameworkselect => \@frameworkselect,
199
                    frameworkcode1 => $frameworkcode1,
200
                    frameworkcode2 => $frameworkcode2,
201
                );
202
            }
203
        }
188
        }
189
        $template->param(
190
            frameworkselect => \@frameworkselect,
191
        );
204
    }
192
    }
205
}
193
}
206
194
Lines 221-277 exit; Link Here
221
# Functions
209
# Functions
222
# ------------------------
210
# ------------------------
223
sub _createMarcHash {
211
sub _createMarcHash {
224
     my $record = shift;
212
    my $record = shift;
225
    my $tagslib = shift;
213
    my $tagslib = shift;
214
    my $hash = {};
226
    my @array;
215
    my @array;
227
    my @fields = $record->fields();
216
    my @fields = $record->fields();
228
217
229
230
    foreach my $field (@fields) {
218
    foreach my $field (@fields) {
231
	my $fieldtag = $field->tag();
219
        my $fieldtag = $field->tag();
232
	if ($fieldtag < 10) {
220
        if ($fieldtag < 10) {
233
	    if ($tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
221
            if ($tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
234
		push @array, { 
222
                push @{ $hash->{fields} }, {
235
			field => [ 
223
                    tag => $fieldtag,
236
				    {
224
                    key => createKey(),
237
					tag => $fieldtag, 
225
                    value => $field->data(),
238
					key => createKey(), 
226
                };
239
					value => $field->data(),
227
            }
240
				    }
228
        } else {
241
				]
229
            if ($fieldtag ne '995' and defined $tagslib->{$fieldtag}) {
242
			    };    
230
                my @subfields = $field->subfields();
243
	    }
231
                my @subfield_array;
244
	} else {
232
                foreach my $subfield (@subfields) {
245
	    my @subfields = $field->subfields();
233
                    if (defined $tagslib->{$fieldtag}->{@$subfield[0]}->{tab}
246
	    my @subfield_array;
234
                    and $tagslib->{$fieldtag}->{@$subfield[0]} ne ''
247
	    foreach my $subfield (@subfields) {
235
                    and $tagslib->{$fieldtag}->{@$subfield[0]}->{tab} >= 0) {
248
		if ($tagslib->{$fieldtag}->{@$subfield[0]}->{'tab'} >= 0) {
236
                        push @subfield_array, {
249
		    push @subfield_array, {  
237
                            subtag => @$subfield[0],
250
                                        subtag => @$subfield[0],
238
                            subkey => createKey(),
251
					subkey => createKey(), 
239
                            value => @$subfield[1],
252
                                        value => @$subfield[1],
240
                        };
253
                                      };
241
                    }
254
		}
242
                }
255
243
256
	    }
244
                if (defined $tagslib->{$fieldtag} and $fieldtag ne '995') {
257
245
                    push @{ $hash->{fields} }, {
258
	    if ($tagslib->{$fieldtag}->{'tab'} >= 0 && $fieldtag ne '995') {
246
                        tag => $fieldtag,
259
		push @array, {
247
                        key => createKey(),
260
			field => [  
248
                        indicator1 => $field->indicator(1),
261
				    {
249
                        indicator2 => $field->indicator(2),
262
					tag => $fieldtag, 
250
                        subfield   => [@subfield_array],
263
					key => createKey(), 
251
                    };
264
					indicator1 => $field->indicator(1), 
252
                }
265
					indicator2 => $field->indicator(2), 
253
            }
266
					subfield   => [@subfield_array], 
254
        }
267
				    }
268
				]
269
			    }; 	
270
	    }
271
272
	}
273
    }
255
    }
274
    return [@array];
256
    return $hash;
275
257
276
}
258
}
277
259
Lines 285-289 sub createKey { Link Here
285
    return int(rand(1000000));
267
    return int(rand(1000000));
286
}
268
}
287
269
288
289
    
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-269 / +250 lines)
Lines 12-20 div#result { margin-top: 1em; } Link Here
12
12
13
    // When submiting the form
13
    // When submiting the form
14
    function mergeformsubmit() {
14
    function mergeformsubmit() {
15
	    $("ul#ulrecord1").remove();
15
        $("#tabs").remove();
16
	    $("ul#ulrecord2").remove();
16
    }
17
}
18
17
19
18
20
$(document).ready(function(){
19
$(document).ready(function(){
Lines 24-169 $(document).ready(function(){ Link Here
24
    // Getting marc structure via ajax
23
    // Getting marc structure via ajax
25
    tagslib = [];
24
    tagslib = [];
26
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
25
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
27
	tagslib = json;
26
        tagslib = json;
28
    });
27
    });
29
28
30
29
31
    // Toggle a field / subfield
30
    // Toggle a field / subfield
32
    function toggleField(pField) {
31
    function toggleField(pField) {
33
32
34
	// Getting the key of the clicked checkbox
33
        // Getting the key of the clicked checkbox
35
	var ckid   = $(pField).attr("id");
34
        var ckid   = $(pField).attr("id");
36
	var tab    = ckid.split('_');
35
        var tab    = ckid.split('_');
37
	var source = tab[1]; // From which record the click came from
36
        var source = tab[1]; // From which record the click came from
38
	var key    = tab[2];
37
        var key    = tab[2];
39
	var type   = $(pField).attr("class");
38
        var type   = $(pField).attr("class");
40
39
41
	// Getting field/subfield
40
        // Getting field/subfield
42
	var field;
41
        var field;
43
	var subfield;
42
        var subfield;
44
	if (type == "subfieldpick") {
43
        if (type == "subfieldpick") {
45
44
            field = $(pField).parent().parent().parent().find("span.field").text();
46
		    field = $(pField).parent().parent().parent().find("span.field").text();
45
            subfield = $(pField).parent().find("span.subfield").text();
47
		    subfield = $(pField).parent().find("span.subfield").text();
46
        } else {
48
	} else {
47
            field = $(pField).parent().find("span.field").text();
49
48
        }
50
		    field = $(pField).parent().find("span.field").text();
49
51
	}
50
        // If the field has just been checked
52
51
        if (pField.checked) {
53
	// If the field has just been checked
52
            // We check for repeatability
54
	if (pField.checked) {
53
            var canbeadded = true;
55
54
            if (type == "subfieldpick") {
56
	    // We check for repeatability
55
                var repeatable = 1;
57
	    var canbeadded = true;
56
                var alreadyexists = 0;
58
	    if (type == "subfieldpick") {
57
                if (tagslib[field] && tagslib[field][subfield]) {
59
		var repeatable = 1;
58
                    // Note : we can't use the dot notation here (tagslib.021)
60
		var alreadyexists = 0;
59
                    // because the key is a number 
61
		if (tagslib[field] && tagslib[field][subfield]) {
60
                    repeatable = tagslib[field][subfield].repeatable;
62
		    repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number 
61
                    // TODO : Checking for subfields
63
		    // TODO : Checking for subfields
62
                }
64
		}
63
            } else {
65
	    } else {
64
                if (tagslib[field]) {
66
		if (tagslib[field]) {
65
                    repeatable = tagslib[field].repeatable;
67
		    repeatable = tagslib[field].repeatable;
66
                    alreadyexists = $("#resultul span.field:contains(" + field + ")");
68
		    alreadyexists = $("#resultul span.field:contains(" + field + ")");
67
                    if (repeatable == 0 && alreadyexists.length != 0) {
69
		    if (repeatable == 0 && alreadyexists.length != 0) {
68
                        canbeadded = false;
70
			canbeadded = false;
69
                    }
71
		    }
70
                }
72
		}
71
            }
73
	    }
72
            // If the field is not repeatable, we check if it already exists in the result table
74
	    // If the field is not repeatable, we check if it already exists in the result table
73
            if (canbeadded == false) {
75
	    if (canbeadded == false) {
74
                alert(_('The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it.'));
76
		alert(_('The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it.'));
75
                pField.checked = 0;
77
		pField.checked = 0;
76
            } else {
78
	    } else {
77
                // Cloning the field or subfield we picked
79
78
                var clone = $(pField).parent().clone();
80
		// Cloning the field or subfield we picked
79
81
		var clone = $(pField).parent().clone();
80
                // Removing the checkboxes from it
82
81
                $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
83
		// Removing the checkboxes from it
82
                    $(this).remove();
84
		$(clone).find("input.subfieldpick, input.fieldpick").each(function() {
83
                });
85
		    $(this).remove();
84
86
		});
85
                // If we are a subfield
87
86
                if (type == "subfieldpick") {
88
87
                    // then we need to find who is our parent field...
89
		// If we are a subfield
88
                    fieldkey = $(pField).parent().parent().parent().attr("id");
90
		if (type == "subfieldpick") {
89
91
		    // then we need to find who is our parent field...
90
                    // Find where to add the subfield
92
		    fieldkey = $(pField).parent().parent().parent().attr("id");
91
93
92
                    // First, check if the field is not already in the destination record
94
		    // Find where to add the subfield
93
                    if ($("#resultul li#" + fieldkey).length > 0) { 
95
94
                    // If so, we add our field to it
96
		    // First, check if the field is not already in the destination record
95
                    $("#resultul li#" + fieldkey + " ul").append(clone);
97
		    if ($("#resultul li#" + fieldkey).length > 0) { 
96
                    } else {
98
			// If so, we add our field to it
97
                        // If not, we add the subfield to the first matching field
99
			$("#resultul li#" + fieldkey + " ul").append(clone);
98
                        var where = 0;
100
		    } else {
99
                        $("#resultul li span.field").each(function() {
101
			// If not, we add the subfield to the first matching field
100
                            if (where == 0 && $(this).text() == field) {
102
			var where = 0;
101
                            where = this;
103
			$("#resultul li span.field").each(function() {
102
                            }
104
			    if (where == 0 && $(this).text() == field) {
103
                        });
105
				where = this;
104
106
			    }
105
                        // If there is no matching field in the destination record
107
			});
106
                        if (where == 0) {
108
107
                            // TODO:
109
			// If there is no matching field in the destination record
108
                            // We select the whole field and removing non-selected subfields, instead of...
110
			if (where == 0) {
109
111
110
                            // Alerting the user
112
			    // TODO: 
111
                            alert(_('This subfield cannot be added: there is no ' + field + ' field in the destination record.'));
113
			    // We select the whole field and removing non-selected subfields, instead of...
112
                            pField.checked = false;
114
113
115
			    // Alerting the user 
114
                        } else {
116
			    alert(_('This subfield cannot be added: there is no ' + field + ' field in the destination record.'));
115
                            $(where).nextAll("ul").append(clone);
117
			    pField.checked = false;
116
                        }
118
117
                    }
119
			} else {
118
                } else {
120
			    $(where).nextAll("ul").append(clone);
119
                    // If we are a field
121
			}
120
                    var where = 0;
122
121
                    // Find where to add the field
123
		    }
122
                    $("#resultul li span.field").each(function() {
124
123
                        if (where == 0 && $(this).text() > field) {
125
		    
124
                            where = this;
126
		    
125
                        }
127
		} else {
126
                    });
128
		    // If we are a field
127
                    $(where).parent().before(clone);
129
		    var where = 0;
128
                }
130
		    // Find where to add the field
129
            }
131
		    $("#resultul li span.field").each(function() {
130
        } else {
132
			if (where == 0 && $(this).text() > field) {
131
            // Else, we remove it from the results tab
133
			    where = this;
132
            $("ul#resultul li#k" + key).remove();
134
			}
133
        }
135
		    });
134
    }
136
137
		    $(where).parent().before(clone);
138
		}
139
	    }
140
	} else {
141
142
	    // Else, we remove it from the results tab
143
	    $("ul#resultul li#k" + key).remove();
144
	}
145
}
146
135
147
136
148
    // When a field is checked / unchecked 
137
    // When a field is checked / unchecked 
149
    $('input.fieldpick').click(function() {
138
    $('input.fieldpick').click(function() {
150
	toggleField(this);
139
        toggleField(this);
151
	// (un)check all subfields
140
        // (un)check all subfields
152
	var ischecked = this.checked;
141
        var ischecked = this.checked;
153
	$(this).parent().find("input.subfieldpick").each(function() {
142
        $(this).parent().find("input.subfieldpick").each(function() {
154
	    this.checked = ischecked;
143
            this.checked = ischecked;
155
	});
144
        });
156
    });
145
    });
157
146
158
    // When a field or subfield is checked / unchecked
147
    // When a field or subfield is checked / unchecked
159
    $("input.subfieldpick").click(function() {
148
    $("input.subfieldpick").click(function() {
160
	toggleField(this);
149
        toggleField(this);
161
    });
150
    });
162
151
163
});
152
});
164
153
165
function changeFramework(fw) {
154
function changeFramework(fw) {
166
    $("#Frameworks").val(fw);
155
    $("#frameworkcode").val(fw);
167
}
156
}
168
157
169
//]]>
158
//]]>
Lines 182-195 function changeFramework(fw) { Link Here
182
171
183
<h1>Merging records</h1>
172
<h1>Merging records</h1>
184
[% IF ( result ) %]
173
[% IF ( result ) %]
185
    [% IF ( errors ) %]
174
    [% IF ( errors.size ) %]
186
	[% FOREACH error IN errors %]
175
        [% FOREACH error IN errors %]
187
	    <div class="dialog alert">[% error.error %].<br />Therefore, the record to be merged has not been deleted.</div>
176
            <div class="dialog alert">[% error.error %].<br />Therefore, the record to be merged has not been deleted.</div>
188
	[% END %]
177
        [% END %]
189
178
190
	[% ELSE %]
179
    [% ELSE %]
191
	<script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script>	
180
        <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% ref_biblionumber %]"</script>
192
	<p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
181
        <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% ref_biblionumber %]">Click here to see the merged record.</a></p>
193
	[% END %]
182
	[% END %]
194
183
195
[% ELSE %]
184
[% ELSE %]
Lines 198-228 function changeFramework(fw) { Link Here
198
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
187
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
199
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
188
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
200
    <fieldset class="rows">
189
    <fieldset class="rows">
201
	<legend>Merge reference</legend>
190
    <legend>Merge reference</legend>
202
	<ol>
191
    <ol>
203
	<li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" onclick="changeFramework('[% frameworkcode1 %]')" /><label for="mergereference1">[% title1 %] [% FOREACH subtitl1 IN subtitle1 %] [% subtitl1.subfield %][% END %] (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% biblio1 %]" title="MARC" rel="gb_page_center[600,500]">[% biblio1 %]</a>)</label></li>
192
        [% FOREACH record IN records %]
204
	<li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" onclick="changeFramework('[% frameworkcode2 %]')" /><label for="mergereference2">[% title2 %] [% FOREACH subtitl2 IN subtitle2 %] [% subtitl2.subfield %][% END %] (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% biblio2 %]" title="MARC" rel="gb_page_center[600,500]">[% biblio2 %]</a>)</label></li>
193
            <li class="radio">
205
194
                [% IF loop.first %]
206
    [% IF frameworkselect %]
195
                    <input type="radio" value="[% record.biblionumber %]" checked="checked" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
207
          <li><label for="frameworkcode">Using framework:</label>
196
                [% ELSE %]
208
                      <select name="frameworkcode" id="frameworkcode">
197
                    <input type="radio" value="[% record.biblionumber %]" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
209
                                      <option value="Default">Default</option>
198
                [% END %]
210
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
199
                <label for="ref_biblionumber[% record.biblionumber %]">
211
                                          [% IF ( frameworkcodeloo.selected ) %]
200
                    [% record.data.title %]
212
                                              <option value="[% frameworkcodeloo.value %]" selected="selected">
201
                    [% FOREACH subtitle IN record.subtitles %]
213
                                          [% ELSE %]
202
                        [% subtitle.subfield %]
214
                                              <option value="[% frameworkcodeloo.value %]">
203
                    [% END %]
215
                                          [% END %]
204
                    (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">[% record.biblionumber %]</a>)
216
                                           [% frameworkcodeloo.frameworktext %]
205
                </label>
217
                                           </option>
206
            </li>
218
                                      [% END %]
207
        [% END %]
219
                      </select></li>
208
209
        [% IF frameworkselect.size %]
210
            <li>
211
                <label for="frameworkcode">Using framework:</label>
212
                <select name="frameworkcode" id="frameworkcode">
213
                    <option value="">Default</option>
214
                    [% FOREACH frameworkcode IN frameworkselect %]
215
                        [% IF ( frameworkcode.selected ) %]
216
                            <option value="[% frameworkcode.value %]" selected="selected">
217
                        [% ELSE %]
218
                            <option value="[% frameworkcode.value %]">
219
                        [% END %]
220
                            [% frameworkcode.frameworktext %]
221
                        </option>
222
                    [% END %]
223
                </select>
224
            </li>
225
        [% END %]
226
    </ol>
227
228
    [% FOREACH record IN records %]
229
        <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
220
    [% END %]
230
    [% END %]
221
</ol>
231
    <fieldset class="action">
222
232
        <input type="submit" value="Next" />
223
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
233
    </fieldset>
224
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
225
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
226
    </fieldset>
234
    </fieldset>
227
</form>
235
</form>
228
[% ELSE %]
236
[% ELSE %]
Lines 238-369 function changeFramework(fw) { Link Here
238
<div id="tabs" class="toptabs">
246
<div id="tabs" class="toptabs">
239
<h2>Source records</h2>
247
<h2>Source records</h2>
240
    <ul>
248
    <ul>
241
	<li><a href="#tabrecord1">[% biblio1 %]</a></li>
249
        [% FOREACH record IN records %]
242
	<li><a href="#tabrecord2">[% biblio2 %]</a></li>
250
            <li>
251
                <a href="#tabrecord[% record.biblionumber %]">
252
                    [% record.biblionumber %]
253
                    [% IF record.reference %](ref)[% END %]
254
                </a>
255
            </li>
256
        [% END %]
243
    </ul>
257
    </ul>
244
    <div id="tabrecord1">
258
    [% IF ( records.size ) %]
245
	[% IF ( record1 ) %]
259
        [% FOREACH record IN records %]
246
260
            <div id="tabrecord[% record.biblionumber %]">
247
	    <div class="record">
261
                <div class="record">
248
		<ul id="ulrecord1">
262
                    <ul id="ulrecord[% record.biblionumber %]">
249
		[% FOREACH record IN record1 %]
263
                        [% FOREACH field IN record.display.fields %]
250
			[% FOREACH fiel IN record.field %]
264
                            <li id="k[% field.key %]">
251
			<li id="k[% fiel.key %]">
265
                                [% IF (record.reference) %]
252
			    <input type="checkbox" checked="checked" class="fieldpick" id="rec_1_[% fiel.key %]" /> 
266
                                    <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
253
			    <span class="field">[% fiel.tag %]</span>
267
                                [% ELSE %]
254
268
                                    <input type="checkbox" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
255
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
269
                                [% END %]
256
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
270
                                <span class="field">[% field.tag %]</span>
257
			    [% IF ( fiel.value ) %] / [% fiel.value %]
271
258
				<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
272
                                <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
259
				<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
273
                                <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
260
			    [% END %]
274
                                [% IF ( field.value ) %]
261
275
                                    / [% field.value %]
262
			    [% IF ( fiel.subfield ) %]
276
                                    <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
263
				<ul>
277
                                    <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value %]" />
264
				    [% FOREACH subfiel IN fiel.subfield %]
278
                                [% END %]
265
					<li id="k[% subfiel.subkey %]">
279
266
					    <input type="checkbox" checked="checked" class="subfieldpick" id="rec_1_[% subfiel.subkey %]" /> 
280
                                [% IF ( field.subfield.size ) %]
267
					    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
281
                                    <ul>
268
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
282
                                        [% FOREACH subfield IN field.subfield %]
269
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
283
                                            <li id="k[% subfield.subkey %]">
270
					</li>
284
                                                [% IF (record.reference) %]
271
				    [% END %]
285
                                                    <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
272
				</ul>
286
                                                [% ELSE %]
273
			    [% END %]
287
                                                    <input type="checkbox" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
274
		    [% END %]
288
                                                [% END %]
275
		    </li>
289
                                                <span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]
276
		[% END %]
290
                                                <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
277
		</ul>
291
                                                <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% subfield.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
278
	    </div><!-- /div.record -->
292
                                            </li>
279
[% END %]
293
                                        [% END %]
280
    </div><!-- /div#tabrecord1 -->
294
                                    </ul>
281
    <div id="tabrecord2">
295
                                [% END %]
282
	[% IF ( record2 ) %]
296
                            </li>
283
297
                        [% END %]
284
	   <div class="record">
298
                    </ul>
285
		<ul id="ulrecord2">
299
                </div><!-- /div.record -->
286
		[% FOREACH record IN record2 %]
300
            </div><!-- /div#tabrecordXXX -->
287
		    [% FOREACH fiel IN record.field %]
301
        [% END %]
288
		    <li id="k[% fiel.key %]">
302
    [% END %]
289
			<input type="checkbox" class="fieldpick" id="rec_2_[% fiel.key %]" /> 
290
			<span class="field">[% fiel.tag %]</span>
291
292
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
293
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
294
			[% IF ( fiel.value ) %] / [% fiel.value %]
295
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
296
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
297
			[% END %]
298
299
			[% IF ( fiel.subfield ) %]
300
			    <ul>
301
				[% FOREACH subfiel IN fiel.subfield %]
302
				    <li id="k[% subfiel.subkey %]">
303
					<input type="checkbox" class="subfieldpick" id="rec_2_[% subfiel.subkey %]" />
304
					<span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
305
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
306
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
307
				    </li>
308
				[% END %]
309
			    </ul>
310
			[% END %]
311
		    [% END %]
312
		    </li>
313
		[% END %]
314
		</ul>
315
	    </div>
316
	    <!-- /div.record -->
317
318
319
320
321
	[% END %]
322
    </div><!-- /div#tabrecord2 -->
323
</div> <!-- // #tabs -->
303
</div> <!-- // #tabs -->
324
</div>
304
</div>
325
<div class="yui-u">
305
<div class="yui-u">
326
<div id="result">
306
<div id="result">
327
    <h2>Destination record</h2>
307
    <h2>Destination record</h2>
328
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
308
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
329
	    <ul id="resultul">
309
        <ul id="resultul">
330
	[% FOREACH record IN record1 %]
310
            [% FOREACH field IN ref_record.display.fields %]<li id="k[% field.key %]"><span class="field">[% field.tag %]</span>  
331
		    [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]"><span class="field">[% fiel.tag %]</span>  
311
            <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
332
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
312
            <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
333
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
313
            [% IF ( field.value ) %] /
334
		    [% IF ( fiel.value ) %] /
314
            [% field.value %]
335
			[% fiel.value %]
315
            <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
336
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
316
            <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value |html%]" />
337
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
317
            [% END %]
338
		    [% END %]
318
339
			
319
            [% IF ( field.subfield ) %]
340
		    [% IF ( fiel.subfield ) %]
320
            <ul>
341
			<ul>
321
                [% FOREACH subfield IN field.subfield %]
342
			    [% FOREACH subfiel IN fiel.subfield %]
322
                <li id="k[% subfield.subkey %]">
343
				<li id="k[% subfiel.subkey %]">
323
                    <span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]
344
				    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
324
                    <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
345
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
325
                    <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
346
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
326
                </li>
347
				</li>
327
                [% END %]
348
			    [% END %]
328
            </ul>
349
			</ul>
329
            [% END %]
350
		    [% END %]
330
351
331
            [% END %]
352
		    [% END %]
332
            </li>
353
		    </li>
333
354
		[% END %]
334
        </ul>
355
356
	    </ul>
357
</div>
335
</div>
358
</div> <!-- // #result -->
336
</div> <!-- // #result -->
359
</div> <!-- .yui-u -->
337
</div> <!-- .yui-u -->
360
338
361
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
339
<input type="hidden" name="ref_biblionumber" value="[% ref_biblionumber %]" />
362
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
340
[% FOREACH record IN records %]
363
<input type="hidden" name="mergereference" value="[% mergereference %]" />
341
    <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
342
[% END %]
364
<input type="hidden" name="frameworkcode" value="[% framework %]" />
343
<input type="hidden" name="frameworkcode" value="[% framework %]" />
365
344
366
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
345
<fieldset class="action">
346
    <input type="submit" name="merge" value="Merge" />
347
</fieldset>
367
</div>
348
</div>
368
</form>
349
</form>
369
[% END %]
350
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-9 / +9 lines)
Lines 34-47 $(document).ready(function(){ Link Here
34
     * This function checks if the adequate number of records are checked for merging
34
     * This function checks if the adequate number of records are checked for merging
35
     */
35
     */
36
    function MergeItems() {
36
    function MergeItems() {
37
	var checkboxes = $("input:checkbox:checked");
37
        var checkboxes = $("input:checkbox:checked");
38
        var nbCheckbox = checkboxes.length;
38
        if (checkboxes.length > 0) {
39
	if (nbCheckbox != 2) {
39
            var url = '/cgi-bin/koha/cataloguing/merge.pl?biblionumber=' + checkboxes[0].value;
40
	    alert(_('Two records must be selected for merging.'));
40
            for(var i = 1; i < checkboxes.length; i++) {
41
	} else {
41
                url += '&amp;biblionumber=' + checkboxes[i].value;
42
	    location.href='/cgi-bin/koha/cataloguing/merge.pl?biblionumber=' + checkboxes[0].value + '&amp;biblionumber=' + checkboxes[1].value;
42
            }
43
	}
43
            location.href = url;
44
	return false;
44
        }
45
        return false;
45
    }
46
    }
46
47
47
    /**
48
    /**
48
- 

Return to bug 8064