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

(-)a/C4/ImportBatch.pm (-1 / +1 lines)
Lines 1121-1127 sub GetImportRecordsRange { Link Here
1121
1121
1122
    $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title';
1122
    $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title';
1123
1123
1124
    my $query = "SELECT title, author, isbn, issn, authorized_heading, import_records.import_record_id,
1124
    my $query = "SELECT title, author, isbn, issn, authorized_heading, import_records.import_record_id, import_records.import_batch_id,
1125
                                           record_sequence, status, overlay_status,
1125
                                           record_sequence, status, overlay_status,
1126
                                           matched_biblionumber, matched_authid, record_type
1126
                                           matched_biblionumber, matched_authid, record_type
1127
                                    FROM   import_records
1127
                                    FROM   import_records
(-)a/cataloguing/merge.pl (-85 / +192 lines)
Lines 29-41 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::Items;
34
use Koha::Items;
35
use Koha::MetadataRecord;
35
use Koha::MetadataRecord;
36
36
37
my $input = new CGI;
37
my $input = new CGI;
38
my @biblionumbers = $input->multi_param('biblionumber');
38
my @record_paths = $input->multi_param('record');
39
my $merge = $input->param('merge');
39
my $merge = $input->param('merge');
40
40
41
my @errors;
41
my @errors;
Lines 50-66 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
50
    }
50
    }
51
);
51
);
52
52
53
my $sources = {
54
    catalog => {
55
        delete => \&_delete_catalog,
56
        fetch => \&_fetch_catalog,
57
        get_link => \&_get_link_catalog,
58
        get_preview_link => \&_get_preview_link_catalog,
59
        merge_other => \&_merge_other_catalog,
60
        update => \&_update_catalog,
61
    },
62
    batch => {
63
        fetch => \&_fetch_import_batch,
64
        get_link => \&_get_preview_link_import_batch,
65
        get_preview_link => \&_get_preview_link_import_batch,
66
        update => \&_update_import_batch,
67
    },
68
};
69
70
sub split_record_path {
71
    my ($source, $num) = split /\//, shift, 2;
72
    $source =~ s/-.*//;
73
74
    return ( $source, $num );
75
}
76
53
#------------------------
77
#------------------------
54
# Merging
78
# Merging
55
#------------------------
79
#------------------------
56
if ($merge) {
80
if ($merge) {
57
81
58
    my $dbh = C4::Context->dbh;
59
60
    # Creating a new record from the html code
82
    # Creating a new record from the html code
61
    my $record       = TransformHtmlToMarc( $input, 1 );
83
    my $record       = TransformHtmlToMarc( $input );
62
    my $ref_biblionumber = $input->param('ref_biblionumber');
84
    my $ref_record_path = $input->param('ref_record');
63
    @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers;
85
86
    my ( $ref_record_source, $ref_record_num ) = split_record_path $ref_record_path;
87
    my @other_record_paths = map +[ split_record_path $_ ], grep { $_ ne $ref_record_path } @record_paths;
64
88
65
    # prepare report
89
    # prepare report
66
    my @report_records;
90
    my @report_records;
Lines 78-126 if ($merge) { Link Here
78
    }
102
    }
79
103
80
    # Rewriting the leader
104
    # Rewriting the leader
81
    $record->leader(GetMarcBiblio({ biblionumber => $ref_biblionumber })->leader());
105
    my $orig_ref_record = $sources->{$ref_record_source}->{fetch}($ref_record_num);
106
    $record->leader( $orig_ref_record->leader() );
82
107
83
    my $frameworkcode = $input->param('frameworkcode');
108
    my $frameworkcode = $input->param('frameworkcode');
84
    my @notmoveditems;
109
    my @notmoveditems;
85
110
86
    # Modifying the reference record
111
    # Modifying the reference record
87
    ModBiblio($record, $ref_biblionumber, $frameworkcode);
112
    $sources->{$ref_record_source}->{update}( $record, $ref_record_num, $frameworkcode );
88
113
89
    # Moving items from the other record to the reference record
114
    # Are all the records from the same source?
90
    foreach my $biblionumber (@biblionumbers) {
115
    my $all_records_same_source = 1;
91
        my $items = Koha::Items->search({ biblionumber => $biblionumber });
116
92
        while ( my $item = $items->next) {
117
    # Merging in information from other records
93
            my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber );
118
    foreach my $record_path (@other_record_paths) {
94
            if ( not defined $res ) {
119
        my ( $record_source, $record_num ) = @$record_path;
95
                push @notmoveditems, $item->itemnumber;
120
121
        if ( $record_source eq $ref_record_source ) {
122
            # We only want to merge in information from the other records if they're the same kind.
123
            #
124
            # We can't merge serials from an import bib to a catalog bib, for instance.
125
            my @record_errors = $sources->{$record_source}->{merge_other}( $record_num, $ref_record_num );
126
127
            if ( @record_errors ) {
128
                push @errors, @record_errors;
129
            } else {
130
                push @errors, $sources->{$record_source}->{delete}( $record_num );
96
            }
131
            }
132
        } else {
133
            $all_records_same_source = 0;
97
        }
134
        }
98
    }
135
    }
99
    # If some items could not be moved :
100
    if (scalar(@notmoveditems) > 0) {
101
        my $itemlist = join(' ',@notmoveditems);
102
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
103
    }
104
105
    my $sth_subscription = $dbh->prepare("
106
        UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
107
    ");
108
    my $sth_subscriptionhistory = $dbh->prepare("
109
        UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
110
    ");
111
    my $sth_serial = $dbh->prepare("
112
        UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
113
    ");
114
    my $sth_suggestions = $dbh->prepare("
115
        UPDATE suggestions SET biblionumber = ? WHERE biblionumber = ?
116
    ");
117
136
118
    my $report_header = {};
137
    my $report_header = {};
119
    foreach my $biblionumber ($ref_biblionumber, @biblionumbers) {
138
    foreach my $record_path ( [ $ref_record_source, $ref_record_num ], @other_record_paths ) {
139
        my ( $record_source, $record_num ) = @$record_path;
140
120
        # build report
141
        # build report
121
        my $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
142
        my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
122
        my %report_record = (
143
        my %report_record = (
123
            biblionumber => $biblionumber,
144
            record_num => $record_num,
124
            fields => {},
145
            fields => {},
125
        );
146
        );
126
        foreach my $field (@report_fields) {
147
        foreach my $field (@report_fields) {
Lines 149-202 if ($merge) { Link Here
149
        push @report_records, \%report_record;
170
        push @report_records, \%report_record;
150
    }
171
    }
151
172
152
    foreach my $biblionumber (@biblionumbers) {
153
        # Moving subscriptions from the other record to the reference record
154
        my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
155
        if ($subcount > 0) {
156
            $sth_subscription->execute($ref_biblionumber, $biblionumber);
157
            $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber);
158
        }
159
160
    # Moving serials
161
    $sth_serial->execute($ref_biblionumber, $biblionumber);
162
163
    # Moving suggestions
164
    $sth_suggestions->execute($ref_biblionumber, $biblionumber);
165
166
    # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
167
    my @allorders = GetOrdersByBiblionumber($biblionumber);
168
    foreach my $myorder (@allorders) {
169
        $myorder->{'biblionumber'} = $ref_biblionumber;
170
        ModOrder ($myorder);
171
    # TODO : add error control (in ModOrder?)
172
    }
173
174
    # Deleting the other records
175
    if (scalar(@errors) == 0) {
176
        # Move holds
177
        MergeHolds($dbh, $ref_biblionumber, $biblionumber);
178
        my $error = DelBiblio($biblionumber);
179
        push @errors, $error if ($error);
180
    }
181
}
182
183
    # Parameters
173
    # Parameters
184
    $template->param(
174
    $template->param(
175
        all_records_same_source => $all_records_same_source,
185
        result => 1,
176
        result => 1,
186
        report_records => \@report_records,
177
        report_records => \@report_records,
187
        report_header => $report_header,
178
        report_header => $report_header,
188
        ref_biblionumber => scalar $input->param('ref_biblionumber')
179
        ref_record_path => scalar $input->param('ref_record'),
180
        ref_record_id => "$ref_record_source-$ref_record_num",
181
        ref_record_link => $sources->{$ref_record_source}->{get_link}($ref_record_num),
189
    );
182
    );
190
183
191
#-------------------------
184
#-------------------------
192
# Show records to merge
185
# Show records to merge
193
#-------------------------
186
#-------------------------
194
} else {
187
} else {
195
    my $ref_biblionumber = $input->param('ref_biblionumber');
188
    my $ref_record_path = $input->param('ref_record');
189
190
    if ($ref_record_path) {
191
        my ( $ref_record_source, $ref_record_num ) = split_record_path $ref_record_path;
196
192
197
    if ($ref_biblionumber) {
198
        my $framework = $input->param('frameworkcode');
193
        my $framework = $input->param('frameworkcode');
199
        $framework //= GetFrameworkCode($ref_biblionumber);
194
        $framework //= GetFrameworkCode($ref_record_num) if $ref_record_source eq 'catalog';
195
        $framework //= '';
200
196
201
        # Getting MARC Structure
197
        # Getting MARC Structure
202
        my $tagslib = GetMarcStructure(1, $framework);
198
        my $tagslib = GetMarcStructure(1, $framework);
Lines 205-223 if ($merge) { Link Here
205
201
206
        # Creating a loop for display
202
        # Creating a loop for display
207
        my @records;
203
        my @records;
208
        foreach my $biblionumber (@biblionumbers) {
204
        foreach my $record_path ( $input->param('record') ) {
209
            my $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
205
            my ( $record_source, $record_num ) = split_record_path $record_path;
210
            my $frameworkcode = GetFrameworkCode($biblionumber);
206
            my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
207
            # FIXME: We assume the default framework for import records.
208
            my $frameworkcode = $record_source eq 'catalog' ? GetFrameworkCode($record_num) : '';
211
            my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour});
209
            my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour});
212
            my $record = {
210
            my $record = {
213
                recordid => $biblionumber,
211
                record_path => $record_path,
212
                recordid => "$record_source-$record_num",
213
                record_source => $record_source,
214
                record_num => $record_num,
214
                record => $marcrecord,
215
                record => $marcrecord,
215
                frameworkcode => $frameworkcode,
216
                frameworkcode => $frameworkcode,
216
                display => $recordObj->createMergeHash($tagslib),
217
                display => $recordObj->createMergeHash($tagslib),
217
            };
218
            };
218
            if ($ref_biblionumber and $ref_biblionumber == $biblionumber) {
219
            if ($ref_record_path and $ref_record_path eq $record_path) {
219
                $record->{reference} = 1;
220
                $record->{reference} = 1;
220
                $template->param(ref_record => $record);
221
                $template->param(ref_record_path => $record);
221
                unshift @records, $record;
222
                unshift @records, $record;
222
            } else {
223
            } else {
223
                push @records, $record;
224
                push @records, $record;
Lines 228-234 if ($merge) { Link Here
228
229
229
        # Parameters
230
        # Parameters
230
        $template->param(
231
        $template->param(
231
            ref_biblionumber => $ref_biblionumber,
232
            ref_record_path => $ref_record_path,
233
            ref_recordid => "$ref_record_source-$ref_record_num",
232
            records => \@records,
234
            records => \@records,
233
            ref_record => $records[0],
235
            ref_record => $records[0],
234
            framework => $framework,
236
            framework => $framework,
Lines 237-247 if ($merge) { Link Here
237
        );
239
        );
238
    } else {
240
    } else {
239
        my @records;
241
        my @records;
240
        foreach my $biblionumber (@biblionumbers) {
242
        foreach my $record_path ( $input->multi_param('record') ) {
241
            my $frameworkcode = GetFrameworkCode($biblionumber);
243
            my ( $record_source, $record_num ) = split_record_path $record_path;
244
245
            my $marcrecord = $sources->{$record_source}->{fetch}($record_num);
246
            # FIXME: We assume the default framework for import records.
247
            my $frameworkcode = $record_source eq 'catalog' ? GetFrameworkCode($record_num) : '';
242
            my $record = {
248
            my $record = {
243
                biblionumber => $biblionumber,
249
                record_path => $record_path,
244
                data => GetBiblioData($biblionumber),
250
                recordid => "$record_path-$record_num",
251
                record_source => $record_source,
252
                record_num => $record_num,
253
                preview_link => $sources->{$record_source}->{get_preview_link}($record_num),
254
                data => TransformMarcToKoha( $marcrecord, $frameworkcode ),
245
                frameworkcode => $frameworkcode,
255
                frameworkcode => $frameworkcode,
246
            };
256
            };
247
            push @records, $record;
257
            push @records, $record;
Lines 263-266 if (@errors) { Link Here
263
}
273
}
264
274
265
output_html_with_http_headers $input, $cookie, $template->output;
275
output_html_with_http_headers $input, $cookie, $template->output;
266
exit;
276
277
sub _delete_catalog {
278
    my ( $biblionumber ) = @_;
279
    return DelBiblio($biblionumber);
280
}
281
282
sub _fetch_catalog {
283
    my ( $biblionumber ) = @_;
284
285
    return GetMarcBiblio({ biblionumber => $biblionumber });
286
}
287
288
sub _get_link_catalog {
289
    my ( $biblionumber ) = @_;
290
291
    return "/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber";
292
}
293
294
sub _get_preview_link_catalog {
295
    my ( $biblionumber ) = @_;
296
297
    return "/cgi-bin/koha/catalogue/showmarc.pl?id=$biblionumber";
298
}
299
300
sub _merge_other_catalog {
301
    my ( $biblionumber, $ref_biblionumber ) = @_;
302
303
    my $dbh = C4::Context->dbh;
304
    my @errors;
305
306
    my @notmoveditems;
307
    my $itemnumbers = get_itemnumbers_of($biblionumber);
308
    foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
309
        if ( !MoveItemFromBiblio( $itemnumber, $biblionumber, $ref_biblionumber ) ) {
310
            push @notmoveditems, $itemnumber;
311
        }
312
    }
313
314
    # If some items could not be moved :
315
    if (scalar(@notmoveditems) > 0) {
316
        my $itemlist = join(' ',@notmoveditems);
317
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
318
    }
319
320
    my $sth_subscription = $dbh->prepare("
321
        UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
322
    ");
323
    my $sth_subscriptionhistory = $dbh->prepare("
324
        UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
325
    ");
326
    my $sth_serial = $dbh->prepare("
327
        UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
328
    ");
329
330
    # Moving subscriptions from the other record to the reference record
331
    my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
332
    if ($subcount > 0) {
333
        $sth_subscription->execute($ref_biblionumber, $biblionumber);
334
        $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber);
335
    }
336
337
    # Moving serials
338
    $sth_serial->execute($ref_biblionumber, $biblionumber);
339
340
    # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
341
    foreach my $myorder( GetOrdersByBiblionumber($biblionumber) ) {
342
        $myorder->{'biblionumber'} = $ref_biblionumber;
343
        ModOrder ($myorder);
344
        # TODO : add error control (in ModOrder?)
345
    }
346
347
    if (scalar(@errors) == 0) {
348
        MergeHolds($dbh, $ref_biblionumber, $biblionumber);
349
    }
350
351
    return @errors;
352
}
353
354
sub _update_catalog {
355
    my ( $record, $biblionumber, $frameworkcode ) = @_;
356
    ModBiblio( $record, $biblionumber, $frameworkcode );
357
}
358
359
sub _fetch_import_batch {
360
    my ( $import_recordid ) = @_;
361
    return C4::ImportBatch::GetRecordFromImportBiblio( $import_recordid );
362
}
363
364
sub _get_preview_link_import_batch {
365
    my ( $import_recordid ) = @_;
366
367
    return "/cgi-bin/koha/catalogue/showmarc.pl?importid=$import_recordid";
368
}
369
370
sub _update_import_batch {
371
    my ( $record, $import_recordid ) = @_;
372
    ModBiblioInBatch( $import_recordid, $record );
373
}
(-)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 (-5 / +6 lines)
Lines 4-11 Link Here
4
            <ul id="ulrecord[% record.recordid | html %]">
4
            <ul id="ulrecord[% record.recordid | html %]">
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 | html %]">
7
                    <li id="k[% field.key | html %]" class="merge-record-field">
8
                        [% IF (tabrecord.reference) %]
8
                        [% IF (record.reference) %]
9
                            <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.recordid | html %]_[% field.key | html %]" />
9
                            <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.recordid | html %]_[% field.key | html %]" />
10
                        [% ELSE %]
10
                        [% ELSE %]
11
                            <input type="checkbox" class="fieldpick" id="rec_[% record.recordid | html %]_[% field.key | html %]" />
11
                            <input type="checkbox" class="fieldpick" id="rec_[% record.recordid | html %]_[% field.key | html %]" />
Lines 15-21 Link Here
15
                        <input type="hidden" name="tag_[% field.tag | html %]_indicator1_[% field.key | html %]" value="[% field.indicator1 | html %]" />
15
                        <input type="hidden" name="tag_[% field.tag | html %]_indicator1_[% field.key | html %]" value="[% field.indicator1 | html %]" />
16
                        <input type="hidden" name="tag_[% field.tag | html %]_indicator2_[% field.key | html %]" value="[% field.indicator2 | html %]" />
16
                        <input type="hidden" name="tag_[% field.tag | html %]_indicator2_[% field.key | html %]" value="[% field.indicator2 | html %]" />
17
                        [% IF ( field.value ) %]
17
                        [% IF ( field.value ) %]
18
                            / [% field.value | html %]
18
                            / <span class="merge-record-fixed-contents">[% field.value | html %]</span>
19
                            <input type="hidden" name="tag_[% field.tag | html %]_code_00_[% field.key | html %]" value="00" />
19
                            <input type="hidden" name="tag_[% field.tag | html %]_code_00_[% field.key | html %]" value="00" />
20
                            <input type="hidden" name="tag_[% field.tag | html %]_subfield_00_[% field.key | html %]" value="[% field.value | html %]" />
20
                            <input type="hidden" name="tag_[% field.tag | html %]_subfield_00_[% field.key | html %]" value="[% field.value | html %]" />
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 | html %]">
26
                                    <li id="k[% subfield.subkey | html %]" class="merge-record-subfield">
27
                                        [% IF (tabrecord.reference) %]
27
                                        [% IF (tabrecord.reference) %]
28
                                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.recordid | html %]_[% subfield.subkey | html %]" />
28
                                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.recordid | html %]_[% subfield.subkey | html %]" />
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 | uri %]">
53
                <a href="#tabrecord[% record.recordid | uri %]">
54
                    [% record.recordid | html %]
54
                    [% IF record.record_source == 'batch' %]import[% END %]
55
                    #[% record.record_num | html %]
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 281-287 Link Here
281
         } else {
281
         } else {
282
             var params = [];
282
             var params = [];
283
             $(checkboxes).each(function() {
283
             $(checkboxes).each(function() {
284
                 params.push('biblionumber=' + $(this).val());
284
                 params.push('record=catalog/' + $(this).val());
285
             });
285
             });
286
             var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
286
             var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
287
             location.href = url;
287
             location.href = url;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-8 / +9 lines)
Lines 5-10 Link Here
5
5
6
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
7
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
8
[% Asset.css("css/merge-record.css") | $raw %]
8
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'doc-head-close.inc' %]
9
<style>
10
<style>
10
div.record ul, div.record li { float:none; display:block; }
11
div.record ul, div.record li { float:none; display:block; }
Lines 44-50 div#result { margin-top: 1em; } Link Here
44
        <table>
45
        <table>
45
            <thead>
46
            <thead>
46
                <tr>
47
                <tr>
47
                    <th>Biblionumber</th>
48
                    <th>Record #</th>
48
                    [% FOREACH key IN report_header.keys.sort %]
49
                    [% FOREACH key IN report_header.keys.sort %]
49
                        [% tag = key.substr(0, 3) %]
50
                        [% tag = key.substr(0, 3) %]
50
                        [% code = key.substr(3, 1) %]
51
                        [% code = key.substr(3, 1) %]
Lines 94-109 div#result { margin-top: 1em; } Link Here
94
        [% FOREACH record IN records %]
95
        [% FOREACH record IN records %]
95
            <li class="radio">
96
            <li class="radio">
96
                [% IF loop.first %]
97
                [% IF loop.first %]
97
                    <input type="radio" value="[% record.biblionumber | html %]" checked="checked" id="ref_biblionumber[% record.biblionumber | html %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode | html %]')" />
98
                    <input type="radio" value="[% record.record_source | html %]/[% record.record_num | html %]" checked="checked" id="ref_recorf[% record.record_source | html %]/[% record.record_num | html %]" name="ref_record" onclick="changeFramework('[% record.frameworkcode | html %]')" />
98
                [% ELSE %]
99
                [% ELSE %]
99
                    <input type="radio" value="[% record.biblionumber | html %]" id="ref_biblionumber[% record.biblionumber | html %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode | html %]')" />
100
                    <input type="radio" value="[% record.record_source | html %]/[% record.record_num | html %]" id="ref_record[% record.record_source | html %]/[% record.record_num | html %]" name="ref_record" onclick="changeFramework('[% record.frameworkcode | html %]')" />
100
                [% END %]
101
                [% END %]
101
                <label for="ref_biblionumber[% record.biblionumber | html %]">
102
                <label for="ref_record[% record.record_source | html %]/[% record.record_num | html %]">
102
                    [% record.data.title | html %]
103
                    [% record.data.title | html %]
103
                    [% FOREACH subtitle IN record.subtitles %]
104
                    [% FOREACH subtitle IN record.subtitles %]
104
                        [% subtitle.subfield | html %]
105
                        [% subtitle.subfield | html %]
105
                    [% END %]
106
                    [% END %]
106
                    ([% record.biblionumber | uri %]) <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber | uri %]" class="previewData">View MARC</a>
107
                    ([% record.record_source | uri %]/[% record.record_num | uri %]) <a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.record_source | uri %]/[% record.record_num | uri %]" class="previewData">View MARC</a>
107
                </label>
108
                </label>
108
            </li>
109
            </li>
109
        [% END %]
110
        [% END %]
Lines 120-126 div#result { margin-top: 1em; } Link Here
120
    </ol>
121
    </ol>
121
122
122
    [% FOREACH record IN records %]
123
    [% FOREACH record IN records %]
123
        <input type="hidden" name="biblionumber" value="[% record.biblionumber | html %]" />
124
        <input type="hidden" name="record" value="[% record.record_source | html %]/[% record.record_num | html %]" />
124
    [% END %]
125
    [% END %]
125
    <fieldset class="action">
126
    <fieldset class="action">
126
        <input type="submit" value="Next" />
127
        <input type="submit" value="Next" />
Lines 284-291 div#result { margin-top: 1em; } Link Here
284
285
285
            // Check all checkboxes in first tab, and uncheck all others to avoid
286
            // Check all checkboxes in first tab, and uncheck all others to avoid
286
            // inconsistencies from a page refresh.
287
            // inconsistencies from a page refresh.
287
            $('#tabs div#tabrecord[% ref_biblionumber | html %]').find('input[type="checkbox"]').prop('checked', true);
288
            $('#tabs div#tabrecord[% ref_record_path | html %]').find('input[type="checkbox"]').prop('checked', true);
288
            $('#tabs > div:not("#tabrecord[% ref_biblionumber | html %]")').find('input[type="checkbox"]').prop('checked', false);
289
            $('#tabs > div:not("#tabrecord[% ref_record_path | html %]")').find('input[type="checkbox"]').prop('checked', false);
289
290
290
            //Set focus to cataloging search
291
            //Set focus to cataloging search
291
            $("input[name=q]:eq(0)").focus();
292
            $("input[name=q]:eq(0)").focus();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-1 / +2 lines)
Lines 508-513 Link Here
508
                        }
508
                        }
509
                        if (aData['diff_url']) {
509
                        if (aData['diff_url']) {
510
                            $('td:eq(5)', nRow).html(
510
                            $('td:eq(5)', nRow).html(
511
                                (aData['merge_url'] ? '<a href="'+aData['merge_url']+'">Merge</a> ' : '') +
511
                                '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
512
                                '<a href="' + aData['diff_url'] + '">' + _("View") + '</a>'
512
                            );
513
                            );
513
                        }
514
                        }
Lines 576-579 Link Here
576
            [% END %]
577
            [% END %]
577
        </ul>
578
        </ul>
578
    </nav>
579
    </nav>
579
[% END %]
580
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-1 / +1 lines)
Lines 644-650 Link Here
644
            } else {
644
            } else {
645
                var params = [];
645
                var params = [];
646
                $(checkboxes).each(function() {
646
                $(checkboxes).each(function() {
647
                    params.push('biblionumber=' + $(this).val());
647
                    params.push('record=catalog/' + $(this).val());
648
                });
648
                });
649
                var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
649
                var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
650
                location.href = url;
650
                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&type=$record->{record_type}" : undef
114
        diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id&type=$record->{record_type}" : 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