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

(-)a/C4/ImportBatch.pm (-1 / +1 lines)
Lines 1125-1131 sub GetImportRecordsRange { Link Here
1125
1125
1126
    $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title';
1126
    $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title';
1127
1127
1128
    my $query = "SELECT title, author, isbn, issn, authorized_heading, import_records.import_record_id,
1128
    my $query = "SELECT title, author, isbn, issn, authorized_heading, import_records.import_record_id, import_records.import_batch_id,
1129
                                           record_sequence, status, overlay_status,
1129
                                           record_sequence, status, overlay_status,
1130
                                           matched_biblionumber, matched_authid, record_type
1130
                                           matched_biblionumber, matched_authid, record_type
1131
                                    FROM   import_records
1131
                                    FROM   import_records
(-)a/cataloguing/merge.pl (-82 / +193 lines)
Lines 29-40 use C4::Serials; Link Here
29
use C4::Koha;
29
use C4::Koha;
30
use C4::Reserves qw/MergeHolds/;
30
use C4::Reserves qw/MergeHolds/;
31
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
31
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
32
32
use C4::ImportBatch;
33
use Koha::BiblioFrameworks;
33
use Koha::BiblioFrameworks;
34
use Koha::MetadataRecord;
34
use Koha::MetadataRecord;
35
35
36
my $input = new CGI;
36
my $input = new CGI;
37
my @biblionumbers = $input->multi_param('biblionumber');
37
my @record_paths = $input->multi_param('record');
38
my $merge = $input->param('merge');
38
my $merge = $input->param('merge');
39
39
40
my @errors;
40
my @errors;
Lines 49-65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
49
    }
49
    }
50
);
50
);
51
51
52
my $sources = {
53
    catalog => {
54
        delete => \&_delete_catalog,
55
        fetch => \&_fetch_catalog,
56
        get_link => \&_get_link_catalog,
57
        get_preview_link => \&_get_preview_link_catalog,
58
        merge_other => \&_merge_other_catalog,
59
        update => \&_update_catalog,
60
    },
61
    batch => {
62
        fetch => \&_fetch_import_batch,
63
        get_link => \&_get_preview_link_import_batch,
64
        get_preview_link => \&_get_preview_link_import_batch,
65
        update => \&_update_import_batch,
66
    },
67
};
68
69
sub split_record_path {
70
    my ($source, $num) = split /\//, shift, 2;
71
    $source =~ s/-.*//;
72
73
    return ( $source, $num );
74
}
75
52
#------------------------
76
#------------------------
53
# Merging
77
# Merging
54
#------------------------
78
#------------------------
55
if ($merge) {
79
if ($merge) {
56
80
57
    my $dbh = C4::Context->dbh;
58
59
    # Creating a new record from the html code
81
    # Creating a new record from the html code
60
    my $record       = TransformHtmlToMarc( $input, 1 );
82
    my $record       = TransformHtmlToMarc( $input );
61
    my $ref_biblionumber = $input->param('ref_biblionumber');
83
    my $ref_record_path = $input->param('ref_record');
62
    @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers;
84
85
    my ( $ref_record_source, $ref_record_num ) = split_record_path $ref_record_path;
86
    my @other_record_paths = map +[ split_record_path $_ ], grep { $_ ne $ref_record_path } @record_paths;
63
87
64
    # prepare report
88
    # prepare report
65
    my @report_records;
89
    my @report_records;
Lines 77-122 if ($merge) { Link Here
77
    }
101
    }
78
102
79
    # Rewriting the leader
103
    # Rewriting the leader
80
    $record->leader(GetMarcBiblio($ref_biblionumber)->leader());
104
    my $orig_ref_record = $sources->{$ref_record_source}->{fetch}($ref_record_num);
105
    $record->leader( $orig_ref_record->leader() );
81
106
82
    my $frameworkcode = $input->param('frameworkcode');
107
    my $frameworkcode = $input->param('frameworkcode');
83
    my @notmoveditems;
108
    my @notmoveditems;
84
109
85
    # Modifying the reference record
110
    # Modifying the reference record
86
    ModBiblio($record, $ref_biblionumber, $frameworkcode);
111
    $sources->{$ref_record_source}->{update}( $record, $ref_record_num, $frameworkcode );
87
112
88
    # Moving items from the other record to the reference record
113
    # Are all the records from the same source?
89
    foreach my $biblionumber (@biblionumbers) {
114
    my $all_records_same_source = 1;
90
        my $itemnumbers = get_itemnumbers_of($biblionumber);
115
91
        foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
116
    # Merging in information from other records
92
        my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber);
117
    foreach my $record_path (@other_record_paths) {
93
        if (not defined $res) {
118
        my ( $record_source, $record_num ) = @$record_path;
94
            push @notmoveditems, $itemnumber;
119
120
        if ( $record_source eq $ref_record_source ) {
121
            # We only want to merge in information from the other records if they're the same kind.
122
            #
123
            # We can't merge serials from an import bib to a catalog bib, for instance.
124
            my @record_errors = $sources->{$record_source}->{merge_other}( $record_num, $ref_record_num );
125
126
            if ( @record_errors ) {
127
                push @errors, @record_errors;
128
            } else {
129
                push @errors, $sources->{$record_source}->{delete}( $record_num );
130
            }
131
        } else {
132
            $all_records_same_source = 0;
95
        }
133
        }
96
    }
134
    }
97
    }
98
    # If some items could not be moved :
99
    if (scalar(@notmoveditems) > 0) {
100
        my $itemlist = join(' ',@notmoveditems);
101
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
102
    }
103
104
    my $sth_subscription = $dbh->prepare("
105
        UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
106
    ");
107
    my $sth_subscriptionhistory = $dbh->prepare("
108
        UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
109
    ");
110
    my $sth_serial = $dbh->prepare("
111
        UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
112
    ");
113
135
114
    my $report_header = {};
136
    my $report_header = {};
115
    foreach my $biblionumber ($ref_biblionumber, @biblionumbers) {
137
    foreach my $record_path ( [ $ref_record_source, $ref_record_num ], @other_record_paths ) {
138
        my ( $record_source, $record_num ) = @$record_path;
139
116
        # build report
140
        # build report
117
        my $marcrecord = GetMarcBiblio($biblionumber);
141
        my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
118
        my %report_record = (
142
        my %report_record = (
119
            biblionumber => $biblionumber,
143
            record_num => $record_num,
120
            fields => {},
144
            fields => {},
121
        );
145
        );
122
        foreach my $field (@report_fields) {
146
        foreach my $field (@report_fields) {
Lines 145-197 if ($merge) { Link Here
145
        push @report_records, \%report_record;
169
        push @report_records, \%report_record;
146
    }
170
    }
147
171
148
    foreach my $biblionumber (@biblionumbers) {
149
        # Moving subscriptions from the other record to the reference record
150
        my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
151
        if ($subcount > 0) {
152
            $sth_subscription->execute($ref_biblionumber, $biblionumber);
153
            $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber);
154
        }
155
156
    # Moving serials
157
        $sth_serial->execute($ref_biblionumber, $biblionumber);
158
159
    # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
160
    my @allorders = GetOrdersByBiblionumber($biblionumber);
161
    my @tobiblioitem = GetBiblioItemByBiblioNumber ($ref_biblionumber);
162
    my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber };
163
    foreach my $myorder (@allorders) {
164
        $myorder->{'biblionumber'} = $ref_biblionumber;
165
        ModOrder ($myorder);
166
    # TODO : add error control (in ModOrder?)
167
    }
168
169
    # Deleting the other records
170
    if (scalar(@errors) == 0) {
171
        # Move holds
172
        MergeHolds($dbh, $ref_biblionumber, $biblionumber);
173
        my $error = DelBiblio($biblionumber);
174
        push @errors, $error if ($error);
175
    }
176
}
177
178
    # Parameters
172
    # Parameters
179
    $template->param(
173
    $template->param(
174
        all_records_same_source => $all_records_same_source,
180
        result => 1,
175
        result => 1,
181
        report_records => \@report_records,
176
        report_records => \@report_records,
182
        report_header => $report_header,
177
        report_header => $report_header,
183
        ref_biblionumber => scalar $input->param('ref_biblionumber')
178
        ref_record_path => scalar $input->param('ref_record'),
179
        ref_record_id => "$ref_record_source-$ref_record_num",
180
        ref_record_link => $sources->{$ref_record_source}->{get_link}($ref_record_num),
184
    );
181
    );
185
182
186
#-------------------------
183
#-------------------------
187
# Show records to merge
184
# Show records to merge
188
#-------------------------
185
#-------------------------
189
} else {
186
} else {
190
    my $ref_biblionumber = $input->param('ref_biblionumber');
187
    my $ref_record_path = $input->param('ref_record');
188
189
    if ($ref_record_path) {
190
        my ( $ref_record_source, $ref_record_num ) = split_record_path $ref_record_path;
191
191
192
    if ($ref_biblionumber) {
193
        my $framework = $input->param('frameworkcode');
192
        my $framework = $input->param('frameworkcode');
194
        $framework //= GetFrameworkCode($ref_biblionumber);
193
        $framework //= GetFrameworkCode($ref_record_num) if $ref_record_source eq 'catalog';
194
        $framework //= '';
195
195
196
        # Getting MARC Structure
196
        # Getting MARC Structure
197
        my $tagslib = GetMarcStructure(1, $framework);
197
        my $tagslib = GetMarcStructure(1, $framework);
Lines 200-218 if ($merge) { Link Here
200
200
201
        # Creating a loop for display
201
        # Creating a loop for display
202
        my @records;
202
        my @records;
203
        foreach my $biblionumber (@biblionumbers) {
203
        foreach my $record_path ( $input->param('record') ) {
204
            my $marcrecord = GetMarcBiblio($biblionumber);
204
            my ( $record_source, $record_num ) = split_record_path $record_path;
205
            my $frameworkcode = GetFrameworkCode($biblionumber);
205
            my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
206
            # FIXME: We assume the default framework for import records.
207
            my $frameworkcode = $record_source eq 'catalog' ? GetFrameworkCode($record_num) : '';
206
            my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour});
208
            my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour});
207
            my $record = {
209
            my $record = {
208
                recordid => $biblionumber,
210
                record_path => $record_path,
211
                recordid => "$record_source-$record_num",
212
                record_source => $record_source,
213
                record_num => $record_num,
209
                record => $marcrecord,
214
                record => $marcrecord,
210
                frameworkcode => $frameworkcode,
215
                frameworkcode => $frameworkcode,
211
                display => $recordObj->createMergeHash($tagslib),
216
                display => $recordObj->createMergeHash($tagslib),
212
            };
217
            };
213
            if ($ref_biblionumber and $ref_biblionumber == $biblionumber) {
218
            if ($ref_record_path and $ref_record_path eq $record_path) {
214
                $record->{reference} = 1;
219
                $record->{reference} = 1;
215
                $template->param(ref_record => $record);
220
                $template->param(ref_record_path => $record);
216
                unshift @records, $record;
221
                unshift @records, $record;
217
            } else {
222
            } else {
218
                push @records, $record;
223
                push @records, $record;
Lines 223-229 if ($merge) { Link Here
223
228
224
        # Parameters
229
        # Parameters
225
        $template->param(
230
        $template->param(
226
            ref_biblionumber => $ref_biblionumber,
231
            ref_record_path => $ref_record_path,
232
            ref_recordid => "$ref_record_source-$ref_record_num",
227
            records => \@records,
233
            records => \@records,
228
            ref_record => $records[0],
234
            ref_record => $records[0],
229
            framework => $framework,
235
            framework => $framework,
Lines 232-242 if ($merge) { Link Here
232
        );
238
        );
233
    } else {
239
    } else {
234
        my @records;
240
        my @records;
235
        foreach my $biblionumber (@biblionumbers) {
241
        foreach my $record_path ( $input->multi_param('record') ) {
236
            my $frameworkcode = GetFrameworkCode($biblionumber);
242
            my ( $record_source, $record_num ) = split_record_path $record_path;
243
244
            my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
245
            # FIXME: We assume the default framework for import records.
246
            my $frameworkcode = $record_source eq 'catalog' ? GetFrameworkCode($record_num) : '';
237
            my $record = {
247
            my $record = {
238
                biblionumber => $biblionumber,
248
                record_path => $record_path,
239
                data => GetBiblioData($biblionumber),
249
                recordid => "$record_path-$record_num",
250
                record_source => $record_source,
251
                record_num => $record_num,
252
                preview_link => $sources->{$record_source}->{get_preview_link}($record_num),
253
                data => TransformMarcToKoha( $marcrecord, $frameworkcode ),
240
                frameworkcode => $frameworkcode,
254
                frameworkcode => $frameworkcode,
241
            };
255
            };
242
            push @records, $record;
256
            push @records, $record;
Lines 258-261 if (@errors) { Link Here
258
}
272
}
259
273
260
output_html_with_http_headers $input, $cookie, $template->output;
274
output_html_with_http_headers $input, $cookie, $template->output;
261
exit;
275
276
sub _delete_catalog {
277
    my ( $biblionumber ) = @_;
278
    return DelBiblio($biblionumber);
279
}
280
281
sub _fetch_catalog {
282
    my ( $biblionumber ) = @_;
283
284
    return GetMarcBiblio( $biblionumber );
285
}
286
287
sub _get_link_catalog {
288
    my ( $biblionumber ) = @_;
289
290
    return "/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber";
291
}
292
293
sub _get_preview_link_catalog {
294
    my ( $biblionumber ) = @_;
295
296
    return "/cgi-bin/koha/catalogue/showmarc.pl?id=$biblionumber";
297
}
298
299
sub _merge_other_catalog {
300
    my ( $biblionumber, $ref_biblionumber ) = @_;
301
302
    my $dbh = C4::Context->dbh;
303
    my @errors;
304
305
    my @notmoveditems;
306
    my $itemnumbers = get_itemnumbers_of($biblionumber);
307
    foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
308
        if ( !MoveItemFromBiblio( $itemnumber, $biblionumber, $ref_biblionumber ) ) {
309
            push @notmoveditems, $itemnumber;
310
        }
311
    }
312
313
    # If some items could not be moved :
314
    if (scalar(@notmoveditems) > 0) {
315
        my $itemlist = join(' ',@notmoveditems);
316
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
317
    }
318
319
    my $sth_subscription = $dbh->prepare("
320
        UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
321
    ");
322
    my $sth_subscriptionhistory = $dbh->prepare("
323
        UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
324
    ");
325
    my $sth_serial = $dbh->prepare("
326
        UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
327
    ");
328
329
    # Moving subscriptions from the other record to the reference record
330
    my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
331
    if ($subcount > 0) {
332
        $sth_subscription->execute($ref_biblionumber, $biblionumber);
333
        $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber);
334
    }
335
336
    # Moving serials
337
    $sth_serial->execute($ref_biblionumber, $biblionumber);
338
339
    # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
340
    foreach my $myorder( GetOrdersByBiblionumber($biblionumber) ) {
341
        $myorder->{'biblionumber'} = $ref_biblionumber;
342
        ModOrder ($myorder);
343
        # TODO : add error control (in ModOrder?)
344
    }
345
346
    if (scalar(@errors) == 0) {
347
        MergeHolds($dbh, $ref_biblionumber, $biblionumber);
348
    }
349
350
    return @errors;
351
}
352
353
sub _update_catalog {
354
    my ( $record, $biblionumber, $frameworkcode ) = @_;
355
    ModBiblio( $record, $biblionumber, $frameworkcode );
356
}
357
358
sub _fetch_import_batch {
359
    my ( $import_recordid ) = @_;
360
    return C4::ImportBatch::GetRecordFromImportBiblio( $import_recordid );
361
}
362
363
sub _get_preview_link_import_batch {
364
    my ( $import_recordid ) = @_;
365
366
    return "/cgi-bin/koha/catalogue/showmarc.pl?importid=$import_recordid";
367
}
368
369
sub _update_import_batch {
370
    my ( $record, $import_recordid ) = @_;
371
    ModBiblioInBatch( $import_recordid, $record );
372
}
(-)a/koha-tmpl/intranet-tmpl/prog/css/merge-record.css (+61 lines)
Line 0 Link Here
1
.merge-record-fixed-contents {
2
    display: inline-block;
3
}
4
5
.merge-record-fixed-contents, .merge-record-subfield {
6
    padding: 2px;
7
}
8
9
.merge-record-unique-0, #tabs .merge-record-unique-0 {
10
    background-color: #005AC8;
11
    color: white;
12
}
13
14
.merge-record-unique-1, #tabs .merge-record-unique-1 {
15
    background-color: #AA0A3C;
16
    color: white;
17
}
18
19
.merge-record-unique-2, #tabs .merge-record-unique-2 {
20
    background-color: #F0F032;
21
}
22
23
.merge-record-unique-3, #tabs .merge-record-unique-3 {
24
    background-color: #00A0FA;
25
    color: white;
26
}
27
28
.merge-record-unique-4, #tabs .merge-record-unique-4 {
29
    background-color: #FA78FA;
30
}
31
32
.merge-record-unique-5, #tabs .merge-record-unique-5 {
33
    background-color: #14D2DC;
34
}
35
36
.merge-record-unique-6, #tabs .merge-record-unique-6 {
37
    background-color: #8214A0;
38
    color: white;
39
}
40
41
.merge-record-unique-7, #tabs .merge-record-unique-7 {
42
    background-color: #FA7850;
43
}
44
45
.merge-record-unique-8, #tabs .merge-record-unique-8 {
46
    background-color: #0AB45A;
47
    color: white;
48
}
49
50
.merge-record-unique-9, #tabs .merge-record-unique-9 {
51
    background-color: #006E82;
52
    color: white;
53
}
54
55
.merge-record-unique-10, #tabs .merge-record-unique-10 {
56
    background-color: #A0FA82;
57
}
58
59
.merge-record-unique-11, #tabs .merge-record-unique-11 {
60
    background-color: #F9E5BD;
61
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities_js.inc (-1 / +1 lines)
Lines 9-15 function mergeAuth(authid, summary) { Link Here
9
        if (typeof alreadySelected.mergereference !== 'undefined') {
9
        if (typeof alreadySelected.mergereference !== 'undefined') {
10
            refstring = "&mergereference=" + alreadySelected.mergereference;
10
            refstring = "&mergereference=" + alreadySelected.mergereference;
11
        }
11
        }
12
        window.location.href = "/cgi-bin/koha/authorities/merge.pl?authid=" + authid + "&authid=" + alreadySelected.authid + refstring;
12
        window.location.href = "/cgi-bin/koha/authorities/merge.pl?record=catalog/" + authid + "&record=catalog/" + alreadySelected.authid + refstring;
13
    } else {
13
    } else {
14
        $.cookie('auth_to_merge', JSON.stringify({ 'authid': authid, 'summary': summary }), { 'path' : '/' });
14
        $.cookie('auth_to_merge', JSON.stringify({ 'authid': authid, 'summary': summary }), { 'path' : '/' });
15
        showMergingInProgress();
15
        showMergingInProgress();
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc (-4 / +5 lines)
Lines 4-10 Link Here
4
            <ul id="ulrecord[% record.recordid %]">
4
            <ul id="ulrecord[% record.recordid %]">
5
                [% FOREACH field IN record.display %]
5
                [% FOREACH field IN record.display %]
6
                  [% IF field.tag != biblionumbertag %]
6
                  [% IF field.tag != biblionumbertag %]
7
                    <li id="k[% field.key %]">
7
                    <li id="k[% field.key %]" class="merge-record-field">
8
                        [% IF (tabrecord.reference) %]
8
                        [% IF (tabrecord.reference) %]
9
                            <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.recordid %]_[% field.key %]" />
9
                            <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.recordid %]_[% field.key %]" />
10
                        [% ELSE %]
10
                        [% ELSE %]
Lines 15-21 Link Here
15
                        <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
15
                        <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
16
                        <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
16
                        <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
17
                        [% IF ( field.value ) %]
17
                        [% IF ( field.value ) %]
18
                            / [% field.value %]
18
                            / <span class="merge-record-fixed-contents">[% field.value %]</span>
19
                            <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
19
                            <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
20
                            <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value %]" />
20
                            <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value %]" />
21
                        [% END %]
21
                        [% END %]
Lines 23-29 Link Here
23
                        [% IF ( field.subfield.size ) %]
23
                        [% IF ( field.subfield.size ) %]
24
                            <ul>
24
                            <ul>
25
                                [% FOREACH subfield IN field.subfield %]
25
                                [% FOREACH subfield IN field.subfield %]
26
                                    <li id="k[% subfield.subkey %]">
26
                                    <li id="k[% subfield.subkey %]" class="merge-record-subfield">
27
                                        [% IF (tabrecord.reference) %]
27
                                        [% IF (tabrecord.reference) %]
28
                                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.recordid %]_[% subfield.subkey %]" />
28
                                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.recordid %]_[% subfield.subkey %]" />
29
                                        [% ELSE %]
29
                                        [% ELSE %]
Lines 51-57 Link Here
51
        [% FOREACH record IN sourcerecords %]
51
        [% FOREACH record IN sourcerecords %]
52
            <li>
52
            <li>
53
                <a href="#tabrecord[% record.recordid %]">
53
                <a href="#tabrecord[% record.recordid %]">
54
                    [% record.recordid %]
54
                    [% IF record.record_source == 'batch' %]import[% END %]
55
                    #[% record.record_num %]
55
                    [% IF record.reference %](ref)[% END %]
56
                    [% IF record.reference %](ref)[% END %]
56
                </a>
57
                </a>
57
            </li>
58
            </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt (-1 / +1 lines)
Lines 69-75 Link Here
69
     } else {
69
     } else {
70
         var params = [];
70
         var params = [];
71
         $(checkboxes).each(function() {
71
         $(checkboxes).each(function() {
72
             params.push('biblionumber=' + $(this).val());
72
             params.push('record=catalog/' + $(this).val());
73
         });
73
         });
74
         var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
74
         var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
75
         location.href = url;
75
         location.href = url;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-12 / +13 lines)
Lines 2-7 Link Here
2
2
3
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
4
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
5
<link rel="stylesheet" href="[% interface %]/[% theme %]/css/merge-record.css">
5
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'doc-head-close.inc' %]
6
<script type="text/javascript" src="[% interface %]/[% theme %]/js/merge-record.js"></script>
7
<script type="text/javascript" src="[% interface %]/[% theme %]/js/merge-record.js"></script>
7
[% INCLUDE 'merge-record-strings.inc' %]
8
[% INCLUDE 'merge-record-strings.inc' %]
Lines 111-118 $(document).ready(function(){ Link Here
111
112
112
    // Check all checkboxes in first tab, and uncheck all others to avoid
113
    // Check all checkboxes in first tab, and uncheck all others to avoid
113
    // inconsistencies from a page refresh.
114
    // inconsistencies from a page refresh.
114
    $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').prop('checked', true);
115
    $('#tabs div#tabrecord[% ref_recordid %]').find('input[type="checkbox"]').prop('checked', true);
115
    $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').prop('checked', false);
116
    $('#tabs > div:not("#tabrecord[% ref_recordid %]")').find('input[type="checkbox"]').prop('checked', false);
116
117
117
    //Set focus to cataloging search
118
    //Set focus to cataloging search
118
    $("input[name=q]:eq(0)").focus();
119
    $("input[name=q]:eq(0)").focus();
Lines 150-161 $(document).ready(function(){ Link Here
150
       [% END %]
151
       [% END %]
151
152
152
    [% ELSE %]
153
    [% ELSE %]
153
        <p>The merge was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% ref_biblionumber %]">Click here to see the merged record.</a></p>
154
        <p>The merge was successful. <a href="[% ref_record_link %]">Click here to see the merged record.</a></p>
154
        <h3>Report</h3>
155
        <h3>Report</h3>
155
        <table>
156
        <table>
156
            <thead>
157
            <thead>
157
                <tr>
158
                <tr>
158
                    <th>Biblionumber</th>
159
                    <th>Record #</th>
159
                    [% FOREACH key IN report_header.keys.sort %]
160
                    [% FOREACH key IN report_header.keys.sort %]
160
                        [% tag = key.substr(0, 3) %]
161
                        [% tag = key.substr(0, 3) %]
161
                        [% code = key.substr(3, 1) %]
162
                        [% code = key.substr(3, 1) %]
Lines 172-178 $(document).ready(function(){ Link Here
172
                [% FOREACH record IN report_records %]
173
                [% FOREACH record IN report_records %]
173
                    <tr>
174
                    <tr>
174
                        <td>
175
                        <td>
175
                            [% record.biblionumber %]
176
                            [% record.record_num %]
176
                            [% IF loop.first %]
177
                            [% IF loop.first %]
177
                                (record kept)
178
                                (record kept)
178
                            [% END %]
179
                            [% END %]
Lines 205-220 $(document).ready(function(){ Link Here
205
        [% FOREACH record IN records %]
206
        [% FOREACH record IN records %]
206
            <li class="radio">
207
            <li class="radio">
207
                [% IF loop.first %]
208
                [% IF loop.first %]
208
                    <input type="radio" value="[% record.biblionumber %]" checked="checked" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
209
                    <input type="radio" value="[% record.record_path %]" checked="checked" id="ref_record[% record.recordid %]" name="ref_record" onclick="changeFramework('[% record.frameworkcode %]')" />
209
                [% ELSE %]
210
                [% ELSE %]
210
                    <input type="radio" value="[% record.biblionumber %]" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
211
                    <input type="radio" value="[% record.record_path %]" id="ref_record[% record.recordid %]" name="ref_record" onclick="changeFramework('[% record.frameworkcode %]')" />
211
                [% END %]
212
                [% END %]
212
                <label for="ref_biblionumber[% record.biblionumber %]">
213
                <label for="ref_record[% record.recordid %]">
213
                    [% record.data.title %]
214
                    [% record.data.title %]
214
                    [% FOREACH subtitle IN record.subtitles %]
215
                    [% FOREACH subtitle IN record.subtitles %]
215
                        [% subtitle.subfield %]
216
                        [% subtitle.subfield %]
216
                    [% END %]
217
                    [% END %]
217
                    ([% record.biblionumber %]) <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber %]" class="previewData">View MARC</a>
218
                    ([% IF record.record_source == 'batch' %]import [% END %]#[% record.record_num %]) <a href="[% record.preview_link %]" class="previewData">View MARC</a>
218
                </label>
219
                </label>
219
            </li>
220
            </li>
220
        [% END %]
221
        [% END %]
Lines 231-237 $(document).ready(function(){ Link Here
231
    </ol>
232
    </ol>
232
233
233
    [% FOREACH record IN records %]
234
    [% FOREACH record IN records %]
234
        <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
235
        <input type="hidden" name="record" value="[% record.record_path %]" />
235
    [% END %]
236
    [% END %]
236
    <fieldset class="action">
237
    <fieldset class="action">
237
        <input type="submit" value="Next" />
238
        <input type="submit" value="Next" />
Lines 274-282 $(document).ready(function(){ Link Here
274
[% PROCESS mergetarget %]
275
[% PROCESS mergetarget %]
275
</div> <!-- .yui-u -->
276
</div> <!-- .yui-u -->
276
277
277
<input type="hidden" name="ref_biblionumber" value="[% ref_biblionumber %]" />
278
<input type="hidden" name="ref_record" value="[% ref_record_path %]" />
278
[% FOREACH record IN records %]
279
[% FOREACH record IN records %]
279
    <input type="hidden" name="biblionumber" value="[% record.recordid %]" />
280
    <input type="hidden" name="record" value="[% record.record_path %]" />
280
[% END %]
281
[% END %]
281
<input type="hidden" name="frameworkcode" value="[% framework %]" />
282
<input type="hidden" name="frameworkcode" value="[% framework %]" />
282
283
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-2 / +3 lines)
Lines 12-19 Link Here
12
            [% IF ( record.record_type == 'biblio' ) %]
12
            [% IF ( record.record_type == 'biblio' ) %]
13
                <td 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>
13
                <td 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>
14
            [% ELSIF ( record.record_type == 'auth' ) %]
14
            [% ELSIF ( record.record_type == 'auth' ) %]
15
                <td 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> |
15
                <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> |
16
        <a href="/cgi-bin/koha/authorities/merge.pl?mergereference=breeding&authid=[% record_lis.match_id %]&authid=[% record_lis.import_record_id %]">Merge</a>
16
                    <a href="/cgi-bin/koha/authorities/merge.pl?ref_record=batch-[% import_batch_id %]/[% record_lis.import_record_id %]&record=catalog/[% record_lis.match_id %]&record=batch-[% import_batch_id %]/[% record_lis.import_record_id %]">Merge</a>
17
                </td>
17
                </td>
18
            [% END %]
18
            [% END %]
19
        </tr>
19
        </tr>
Lines 121-126 $(document).ready(function(){ Link Here
121
            }
121
            }
122
            if (aData['diff_url']){
122
            if (aData['diff_url']){
123
                $('td:eq(5)', nRow).html(
123
                $('td:eq(5)', nRow).html(
124
                    (aData['merge_url'] ? '<a href="'+aData['merge_url']+'">Merge</a> ' : '') +
124
                    '<a href="'+aData['diff_url']+'">View</a>'
125
                    '<a href="'+aData['diff_url']+'">View</a>'
125
                );
126
                );
126
            }
127
            }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-1 / +1 lines)
Lines 207-213 $(document).ready(function(){ Link Here
207
        } else {
207
        } else {
208
            var params = [];
208
            var params = [];
209
            $(checkboxes).each(function() {
209
            $(checkboxes).each(function() {
210
                params.push('biblionumber=' + $(this).val());
210
                params.push('record=catalog/' + $(this).val());
211
            });
211
            });
212
            var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
212
            var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
213
            location.href = url;
213
            location.href = url;
(-)a/koha-tmpl/intranet-tmpl/prog/js/merge-record.js (+58 lines)
Lines 181-184 $(document).ready(function(){ Link Here
181
      }
181
      }
182
      rebuild_target($('#tabs'), $('#resultul'));
182
      rebuild_target($('#tabs'), $('#resultul'));
183
    });
183
    });
184
185
    // Keep track of all the class names added; easier than finding the right one to remove later.
186
    var record_class_names = '';
187
188
    // Start by marking subfield as unique to its record.
189
    $('.record').each( function(i) {
190
      var record_class = 'merge-record-unique-' + i;
191
      record_class_names += record_class + ' ';
192
193
      $(this).find('.merge-record-fixed-contents, .merge-record-subfield').addClass( record_class );
194
    } );
195
196
    // Mark the tabs the same color as the subfields.
197
    $(window).load( function() { $('#tabs a.ui-tabs-anchor').addClass( function(i) { return 'merge-record-unique-' + i } ) } );
198
199
    // We iterate through every subfield of every field of the first record, and check to see if it
200
    // exists in every other record.
201
    //
202
    // I'm sorry if this leaves you feeling... loopy.
203
    $('.record').eq(0).find('.merge-record-field').each( function() {
204
      var field = $(this).find('.field').text();
205
206
      $(this).find('.merge-record-fixed-contents, .merge-record-subfield').each( function() {
207
        var text = field + $(this).text().replace(/\s+/g, ' ');
208
        var $matching_subfields = $(this);
209
        var common_subfield = true;
210
211
        $('.record').slice(1).each( function() {
212
          var found = false;
213
          $(this).find('.merge-record-field').each( function() {
214
            var other_field = $(this).find('.field').text();
215
            $(this).find('.merge-record-fixed-contents, .merge-record-subfield').each( function() {
216
              var other_text = field + $(this).text().replace(/\s+/g, ' ');
217
218
              if (other_text == text) {
219
                // Little jQueryism to build up a custom set of elements that we can later remove
220
                // classes from all at once.
221
                $matching_subfields = $matching_subfields.add(this);
222
                found = true;
223
                return false;
224
              }
225
            } );
226
227
            if (found == true) return false;
228
          } );
229
230
          if (found == false) {
231
            common_subfield = false;
232
            return false;
233
          }
234
        } );
235
236
        if (common_subfield) {
237
          // If the subfield exists in all records, remove the "unique" class from all of them.
238
          $matching_subfields.removeClass(record_class_names);
239
        }
240
      } );
241
    } );
184
});
242
});
(-)a/tools/batch_records_ajax.pl (-2 / +6 lines)
Lines 78-83 foreach my $record (@$records) { Link Here
78
    my $match = GetImportRecordMatches( $record->{'import_record_id'}, 1 );
78
    my $match = GetImportRecordMatches( $record->{'import_record_id'}, 1 );
79
    my $match_citation = '';
79
    my $match_citation = '';
80
    my $match_id;
80
    my $match_id;
81
    my $script_name;
81
    if ( $#$match > -1 ) {
82
    if ( $#$match > -1 ) {
82
        if ( $match->[0]->{'record_type'} eq 'biblio' ) {
83
        if ( $match->[0]->{'record_type'} eq 'biblio' ) {
83
            $match_citation .= $match->[0]->{'title'}
84
            $match_citation .= $match->[0]->{'title'}
Lines 85-96 foreach my $record (@$records) { Link Here
85
            $match_citation .= ' ' . $match->[0]->{'author'}
86
            $match_citation .= ' ' . $match->[0]->{'author'}
86
              if defined( $match->[0]->{'author'} );
87
              if defined( $match->[0]->{'author'} );
87
            $match_id = $match->[0]->{'biblionumber'};
88
            $match_id = $match->[0]->{'biblionumber'};
89
            $script_name = 'cataloguing/merge.pl';
88
        }
90
        }
89
        elsif ( $match->[0]->{'record_type'} eq 'auth' ) {
91
        elsif ( $match->[0]->{'record_type'} eq 'auth' ) {
90
            if ( defined( $match->[0]->{'authorized_heading'} ) ) {
92
            if ( defined( $match->[0]->{'authorized_heading'} ) ) {
91
                $match_citation .= $match->[0]->{'authorized_heading'};
93
                $match_citation .= $match->[0]->{'authorized_heading'};
92
                $match_id = $match->[0]->{'candidate_match_id'};
94
                $match_id = $match->[0]->{'candidate_match_id'};
93
            }
95
            }
96
            # Uncomment this when support for merging authorities is ready
97
            #$script_name = 'authorities/merge.pl';
94
        }
98
        }
95
    }
99
    }
96
100
Lines 107-113 foreach my $record (@$records) { Link Here
107
          || q{},
111
          || q{},
108
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
112
        score => $#$match > -1 ? $match->[0]->{'score'} : 0,
109
        match_id => $match_id,
113
        match_id => $match_id,
110
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id" : undef
114
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id" : undef,
115
        merge_url => ($match_id && $script_name) ? "/cgi-bin/koha/$script_name?ref_record=batch-$record->{import_batch_id}/$record->{import_record_id}&record=catalog/$match_id&record=batch-$record->{import_batch_id}/$record->{import_record_id}" : undef
111
      };
116
      };
112
}
117
}
113
118
114
- 

Return to bug 14578