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

(-)a/cataloguing/merge.pl (-162 / +197 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
4
# Copyright 2009 BibLibre
3
# Copyright 2009 BibLibre
5
# Parts Copyright Catalyst IT 2011
4
# Parts Copyright Catalyst IT 2011
6
#
5
#
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 32-45 use C4::Reserves qw/MergeHolds/; Link Here
32
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
31
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
33
32
34
my $input = new CGI;
33
my $input = new CGI;
35
my @biblionumber = $input->param('biblionumber');
34
my @biblionumbers = $input->param('biblionumber');
36
my $merge = $input->param('merge');
35
my $merge = $input->param('merge');
37
36
38
my @errors;
37
my @errors;
39
38
40
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41
    {
40
    {
42
        template_name   => "cataloguing/merge.tmpl",
41
        template_name   => "cataloguing/merge.tt",
43
        query           => $input,
42
        query           => $input,
44
        type            => "intranet",
43
        type            => "intranet",
45
        authnotrequired => 0,
44
        authnotrequired => 0,
Lines 53-218 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
53
if ($merge) {
52
if ($merge) {
54
53
55
    my $dbh = C4::Context->dbh;
54
    my $dbh = C4::Context->dbh;
56
    my $sth;
57
55
58
    # Creating a new record from the html code
56
    # Creating a new record from the html code
59
    my $record       = TransformHtmlToMarc( $input );
57
    my $record = TransformHtmlToMarc( $input );
60
    my $tobiblio     =  $input->param('biblio1');
58
    my $ref_biblionumber = $input->param('ref_biblionumber');
61
    my $frombiblio   =  $input->param('biblio2');
59
    @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers;
60
61
    # prepare report
62
    my @report_records;
63
    my $report_fields_str = $input->param('report_fields');
64
    $report_fields_str ||= C4::Context->preference('MergeReportFields');
65
    my @report_fields;
66
    foreach my $field_str (split /,/, $report_fields_str) {
67
        if ($field_str =~ /(\d{3})([0-9a-z]*)/) {
68
            my ($field, $subfields) = ($1, $2);
69
            push @report_fields, {
70
                tag => $field,
71
                subfields => [ split //, $subfields ]
72
            }
73
        }
74
    }
62
75
63
    # Rewriting the leader
76
    # Rewriting the leader
64
    $record->leader(GetMarcBiblio($tobiblio)->leader());
77
    $record->leader(GetMarcBiblio($ref_biblionumber)->leader());
65
78
66
    my $frameworkcode = $input->param('frameworkcode');
79
    my $frameworkcode = $input->param('frameworkcode');
67
    my @notmoveditems;
80
    my @notmoveditems;
68
81
69
    # Modifying the reference record
82
    # Modifying the reference record
70
    ModBiblio($record, $tobiblio, $frameworkcode);
83
    ModBiblio($record, $ref_biblionumber, $frameworkcode);
71
84
72
    # Moving items from the other record to the reference record
85
    # Moving items from the other record to the reference record
73
    # Also moving orders from the other record to the reference record, only if the order is linked to an item of the other record
86
    foreach my $biblionumber (@biblionumbers) {
74
    my $itemnumbers = get_itemnumbers_of($frombiblio);
87
        my $itemnumbers = get_itemnumbers_of($biblionumber);
75
    foreach my $itloop ($itemnumbers->{$frombiblio}) {
88
        foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
76
    foreach my $itemnumber (@$itloop) {
89
            my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber);
77
        my $res = MoveItemFromBiblio($itemnumber, $frombiblio, $tobiblio);
90
            if (not defined $res) {
78
        if (not defined $res) {
91
                push @notmoveditems, $itemnumber;
79
            push @notmoveditems, $itemnumber;
92
            }
80
        }
93
        }
81
    }
94
    }
82
    }
83
    # If some items could not be moved :
95
    # If some items could not be moved :
84
    if (scalar(@notmoveditems) > 0) {
96
    if (scalar(@notmoveditems) > 0) {
85
        my $itemlist = join(' ',@notmoveditems);
97
        my $itemlist = join(' ',@notmoveditems);
86
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
98
        push @errors, { code => "CANNOT_MOVE", value => $itemlist };
87
    }
99
    }
88
100
89
    # Moving subscriptions from the other record to the reference record
101
    my $sth_subscription = $dbh->prepare("
90
    my $subcount = CountSubscriptionFromBiblionumber($frombiblio);
102
        UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?
91
    if ($subcount > 0) {
103
    ");
92
    $sth = $dbh->prepare("UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?");
104
    my $sth_subscriptionhistory = $dbh->prepare("
93
    $sth->execute($tobiblio, $frombiblio);
105
        UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?
94
106
    ");
95
    $sth = $dbh->prepare("UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?");
107
    my $sth_serial = $dbh->prepare("
96
    $sth->execute($tobiblio, $frombiblio);
108
        UPDATE serial SET biblionumber = ? WHERE biblionumber = ?
97
109
    ");
110
111
    my $report_header = {};
112
    foreach my $biblionumber ($ref_biblionumber, @biblionumbers) {
113
        # build report
114
        my $marcrecord = GetMarcBiblio($biblionumber);
115
        my %report_record = (
116
            biblionumber => $biblionumber,
117
            fields => {},
118
        );
119
        foreach my $field (@report_fields) {
120
            my @marcfields = $marcrecord->field($field->{tag});
121
            foreach my $marcfield (@marcfields) {
122
                my $tag = $marcfield->tag();
123
                my %subfields;
124
                if (scalar @{$field->{subfields}}) {
125
                    foreach my $subfield (@{$field->{subfields}}) {
126
                        my @values = $marcfield->subfield($subfield);
127
                        $report_header->{ $tag . $subfield } = 1;
128
                        push @{ $report_record{fields}->{$tag . $subfield} }, @values;
129
                    }
130
                } elsif ($field->{tag} gt '009') {
131
                    my @marcsubfields = $marcfield->subfields();
132
                    foreach my $marcsubfield (@marcsubfields) {
133
                        my ($code, $value) = @$marcsubfield;
134
                        $report_header->{ $tag . $code } = 1;
135
                        push @{ $report_record{fields}->{ $tag . $code } }, $value;
136
                    }
137
                } else {
138
                    $report_header->{ $tag . '@' } = 1;
139
                    push @{ $report_record{fields}->{ $tag .'@' } }, $marcfield->data();
140
                }
141
            }
142
        }
143
        push @report_records, \%report_record;
98
    }
144
    }
99
145
100
    # Moving serials
146
    foreach my $biblionumber (@biblionumbers) {
101
    $sth = $dbh->prepare("UPDATE serial SET biblionumber = ? WHERE biblionumber = ?");
147
        # Moving subscriptions from the other record to the reference record
102
    $sth->execute($tobiblio, $frombiblio);
148
        my $subcount = CountSubscriptionFromBiblionumber($biblionumber);
103
149
        if ($subcount > 0) {
104
    # TODO : Moving reserves
150
            $sth_subscription->execute($ref_biblionumber, $biblionumber);
151
            $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber);
152
        }
105
153
106
    # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
154
        # Moving serials
107
    my @allorders = GetOrdersByBiblionumber($frombiblio);
155
        $sth_serial->execute($ref_biblionumber, $biblionumber);
108
    my @tobiblioitem = GetBiblioItemByBiblioNumber ($tobiblio);
156
109
    my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber };
157
        # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
110
    foreach my $myorder (@allorders) {
158
        my @allorders = GetOrdersByBiblionumber($frombiblio);
111
        $myorder->{'biblionumber'} = $tobiblio;
159
        my @tobiblioitem = GetBiblioItemByBiblioNumber ($tobiblio);
112
        ModOrder ($myorder);
160
        my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber };
113
    # TODO : add error control (in ModOrder?)
161
        foreach my $myorder (@allorders) {
114
    }
162
            $myorder->{'biblionumber'} = $tobiblio;
163
            ModOrder ($myorder);
164
        # TODO : add error control (in ModOrder?)
165
        }
115
166
116
    # Deleting the other record
167
        # Deleting the other records
117
    if (scalar(@errors) == 0) {
168
        if (scalar(@errors) == 0) {
118
    # Move holds
169
            # Move holds
119
    MergeHolds($dbh,$tobiblio,$frombiblio);
170
            MergeHolds($dbh, $ref_biblionumber, $biblionumber);
120
    my $error = DelBiblio($frombiblio);
171
            my $error = DelBiblio($biblionumber);
121
    push @errors, $error if ($error);
172
            push @errors, $error if ($error);
173
        }
122
    }
174
    }
123
175
124
    # Parameters
176
    # Parameters
125
    $template->param(
177
    $template->param(
126
    result => 1,
178
        result => 1,
127
    biblio1 => $input->param('biblio1')
179
        report_records => \@report_records,
180
        report_header => $report_header,
181
        ref_biblionumber => $input->param('ref_biblionumber')
128
    );
182
    );
129
183
130
#-------------------------
184
#-------------------------
131
# Show records to merge
185
# Show records to merge
132
#-------------------------
186
#-------------------------
133
} else {
187
} else {
134
    my $mergereference = $input->param('mergereference');
188
    my $ref_biblionumber = $input->param('ref_biblionumber');
135
    my $biblionumber = $input->param('biblionumber');
189
136
190
    if ($ref_biblionumber) {
137
    if (scalar(@biblionumber) != 2) {
191
        my $framework = $input->param('frameworkcode');
138
        push @errors, { code => "WRONG_COUNT", value => scalar(@biblionumber) };
192
        $framework //= GetFrameworkCode($ref_biblionumber);
139
    }
193
140
    else {
194
        # Getting MARC Structure
141
        my $data1 = GetBiblioData($biblionumber[0]);
195
        my $tagslib = GetMarcStructure(1, $framework);
142
        my $record1 = GetMarcBiblio($biblionumber[0]);
196
143
197
        # Creating a loop for display
144
        my $data2 = GetBiblioData($biblionumber[1]);
198
        my @records;
145
        my $record2 = GetMarcBiblio($biblionumber[1]);
199
        foreach my $biblionumber (@biblionumbers) {
146
200
            my $marcrecord = GetMarcBiblio($biblionumber);
147
        # Checks if both records use the same framework
201
            my $frameworkcode = GetFrameworkCode($biblionumber);
148
        my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]);
202
            my $record = {
149
        my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]);
203
                biblionumber => $biblionumber,
150
204
                record => $marcrecord,
151
205
                frameworkcode => $frameworkcode,
152
        my $subtitle1 = GetRecordValue('subtitle', $record1, $frameworkcode1);
206
                display => _createMarcHash($marcrecord, $tagslib),
153
        my $subtitle2 = GetRecordValue('subtitle', $record2, $frameworkcode1);
207
            };
154
208
            if ($ref_biblionumber and $ref_biblionumber == $biblionumber) {
155
        if ($mergereference) {
209
                $record->{reference} = 1;
156
210
                $template->param(ref_record => $record);
157
            my $framework;
211
                unshift @records, $record;
158
            if ($frameworkcode1 ne $frameworkcode2) {
159
                $framework = $input->param('frameworkcode')
160
                  or push @errors, "Famework not selected.";
161
            } else {
212
            } else {
162
                $framework = $frameworkcode1;
213
                push @records, $record;
163
            }
214
            }
215
        }
164
216
165
            # Getting MARC Structure
217
        my ($biblionumbertag) = GetMarcFromKohaField('biblio.biblionumber');
166
            my $tagslib = GetMarcStructure(1, $framework);
167
168
            my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0];
169
170
            # Creating a loop for display
171
            my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib);
172
            my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib);
173
218
174
            # Parameters
219
        # Parameters
175
            $template->param(
220
        $template->param(
176
                biblio1 => $mergereference,
221
            ref_biblionumber => $ref_biblionumber,
177
                biblio2 => $notreference,
222
            records => \@records,
178
                mergereference => $mergereference,
223
            framework => $framework,
179
                record1 => @record1,
224
            biblionumbertag => $biblionumbertag,
180
                record2 => @record2,
225
            MergeReportFields => C4::Context->preference('MergeReportFields'),
181
                framework => $framework,
226
        );
182
            );
227
    }
228
    else {
229
        my @records;
230
        foreach my $biblionumber (@biblionumbers) {
231
            my $frameworkcode = GetFrameworkCode($biblionumber);
232
            my $record = {
233
                biblionumber => $biblionumber,
234
                data => GetBiblioData($biblionumber),
235
                frameworkcode => $frameworkcode,
236
            };
237
            push @records, $record;
183
        }
238
        }
184
        else {
185
186
        # Ask the user to choose which record will be the kept
239
        # Ask the user to choose which record will be the kept
187
            $template->param(
240
        $template->param(
188
                choosereference => 1,
241
            choosereference => 1,
189
                biblio1 => $biblionumber[0],
242
            records => \@records,
190
                biblio2 => $biblionumber[1],
243
        );
191
                title1 => $data1->{'title'},
244
192
                subtitle1 => $subtitle1,
245
        my $frameworks = getframeworks;
193
                title2 => $data2->{'title'},
246
        my @frameworkselect;
194
                subtitle2 => $subtitle2
247
        foreach my $thisframeworkcode ( keys %$frameworks ) {
248
            my %row = (
249
                value         => $thisframeworkcode,
250
                frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
195
            );
251
            );
196
            if ($frameworkcode1 ne $frameworkcode2) {
252
            push @frameworkselect, \%row;
197
                my $frameworks = getframeworks;
198
                my @frameworkselect;
199
                foreach my $thisframeworkcode ( keys %$frameworks ) {
200
                    my %row = (
201
                        value         => $thisframeworkcode,
202
                        frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
203
                    );
204
                    if ($frameworkcode1 eq $thisframeworkcode){
205
                        $row{'selected'} = 1;
206
                        }
207
                    push @frameworkselect, \%row;
208
                }
209
                $template->param(
210
                    frameworkselect => \@frameworkselect,
211
                    frameworkcode1 => $frameworkcode1,
212
                    frameworkcode2 => $frameworkcode2,
213
                );
214
            }
215
        }
253
        }
254
        $template->param(
255
            frameworkselect => \@frameworkselect,
256
        );
216
    }
257
    }
217
}
258
}
218
259
Lines 232-288 exit; Link Here
232
# Functions
273
# Functions
233
# ------------------------
274
# ------------------------
234
sub _createMarcHash {
275
sub _createMarcHash {
235
     my $record = shift;
276
    my $record = shift;
236
    my $tagslib = shift;
277
    my $tagslib = shift;
278
    my $hash = {};
237
    my @array;
279
    my @array;
238
    my @fields = $record->fields();
280
    my @fields = $record->fields();
239
281
240
241
    foreach my $field (@fields) {
282
    foreach my $field (@fields) {
242
    my $fieldtag = $field->tag();
283
        my $fieldtag = $field->tag();
243
    if ($fieldtag < 10) {
284
        if ($fieldtag < 10) {
244
        if ($tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
285
            if ($tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0) {
245
        push @array, {
286
                push @{ $hash->{fields} }, {
246
            field => [
247
                    {
248
                    tag => $fieldtag,
287
                    tag => $fieldtag,
249
                    key => createKey(),
288
                    key => createKey(),
250
                    value => $field->data(),
289
                    value => $field->data(),
251
                    }
252
                ]
253
                };
290
                };
254
        }
291
            }
255
    } else {
292
        } else {
256
        my @subfields = $field->subfields();
293
            if ($fieldtag ne '995' and defined $tagslib->{$fieldtag}) {
257
        my @subfield_array;
294
                my @subfields = $field->subfields();
258
        foreach my $subfield (@subfields) {
295
                my @subfield_array;
259
        if ($tagslib->{$fieldtag}->{@$subfield[0]}->{'tab'} >= 0) {
296
                foreach my $subfield (@subfields) {
260
            push @subfield_array, {
297
                    if (defined $tagslib->{$fieldtag}->{@$subfield[0]}->{tab}
261
                                    subtag => @$subfield[0],
298
                    and $tagslib->{$fieldtag}->{@$subfield[0]} ne ''
262
                                    subkey => createKey(),
299
                    and $tagslib->{$fieldtag}->{@$subfield[0]}->{tab} >= 0) {
263
                                    value => @$subfield[1],
300
                        push @subfield_array, {
264
                                  };
301
                            subtag => @$subfield[0],
265
        }
302
                            subkey => createKey(),
266
303
                            value => @$subfield[1],
267
        }
304
                        };
305
                    }
306
                }
268
307
269
        if ($tagslib->{$fieldtag}->{'tab'} >= 0 && $fieldtag ne '995') {
308
                if (defined $tagslib->{$fieldtag} and $fieldtag ne '995') {
270
        push @array, {
309
                    push @{ $hash->{fields} }, {
271
            field => [
310
                        tag => $fieldtag,
272
                {
311
                        key => createKey(),
273
                    tag => $fieldtag,
312
                        indicator1 => $field->indicator(1),
274
                    key => createKey(),
313
                        indicator2 => $field->indicator(2),
275
                    indicator1 => $field->indicator(1),
314
                        subfield   => [@subfield_array],
276
                    indicator2 => $field->indicator(2),
315
                    };
277
                    subfield   => [@subfield_array],
278
                }
316
                }
279
            ]
317
            }
280
            };
281
        }
318
        }
282
283
    }
284
    }
319
    }
285
    return [@array];
320
    return $hash;
286
321
287
}
322
}
288
323
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 427-429 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
427
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowHoldNotes',0,'Show hold notes on OPAC','','YesNo');
428
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowHoldNotes',0,'Show hold notes on OPAC','','YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
429
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
430
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MergeReportFields','','Displayed fields for deleted MARC records after merge',NULL,'Free');
(-)a/installer/data/mysql/updatedatabase.pl (+14 lines)
Lines 6984-6989 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( Link Here
6984
}
6984
}
6985
6985
6986
6986
6987
6988
6989
6990
$DBversion = "3.13.00.XXX";
6991
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
6992
    $dbh->do("
6993
        INSERT INTO systempreferences (variable,value,explanation,options,type)
6994
        VALUES('MergeReportFields','','Displayed fields for deleted MARC records after merge',NULL,'Free');
6995
    ");
6996
    print "Upgrade to $DBversion done (Add system preference 'MergeReportFields')\n";
6997
    SetVersion($DBversion);
6998
}
6999
7000
6987
=head1 FUNCTIONS
7001
=head1 FUNCTIONS
6988
7002
6989
=head2 TableExists($table)
7003
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+9 lines)
Lines 176-178 Cataloging: Link Here
176
            - pref: NotesBlacklist
176
            - pref: NotesBlacklist
177
              class: multi
177
              class: multi
178
            - note fields in title notes separator (OPAC record details) and in the description separator (Staff client record details). The fields should appear separated with commas and according with the Koha MARC format (eg 3.. for UNIMARC, 5.. for MARC21)
178
            - note fields in title notes separator (OPAC record details) and in the description separator (Staff client record details). The fields should appear separated with commas and according with the Koha MARC format (eg 3.. for UNIMARC, 5.. for MARC21)
179
        -
180
            - pref: MergeReportFields
181
            - "fields to display for deleted records after merge"
182
            - "<br />example: '001,245ab,600'"
183
            - "displays:"
184
            - "<ul>"
185
            - "<li>value of 001</li>"
186
            - "<li>subfields a and b of fields 245</li>"
187
            - "<li>all subfields of fields 600</li>"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-309 / +415 lines)
Lines 10-170 div#result { margin-top: 1em; } Link Here
10
<script type="text/javascript">
10
<script type="text/javascript">
11
//<![CDATA[
11
//<![CDATA[
12
12
13
[% UNLESS (result) %]
14
  [% IF (choosereference) %]
15
    function changeFramework(fw) {
16
        $("#frameworkcode").val(fw);
17
    }
18
  [% ELSE %]
19
    function check_mandatory () {
20
        var missing = {
21
            'fields': [],
22
            'subfields': []
23
        };
24
        for (tag in tagslib) {
25
            if (tag == '000' || tag == '001')
26
                continue;
27
            if (tagslib[tag].mandatory == 1) {
28
                if ($("#resultul span.field:contains("+ tag +")").length == 0) {
29
                    missing.fields.push(tag);
30
                }
31
            }
32
            for (subfieldcode in tagslib[tag]) {
33
                if (subfieldcode == 'lib' || subfieldcode == 'mandatory'
34
                || subfieldcode == 'repeatable' || subfieldcode == 'tab') {
35
                    continue;
36
                }
37
                if (tagslib[tag][subfieldcode].mandatory == 1 && tagslib[tag][subfieldcode].tab >= 0) {
38
                    var fields = $("#resultul span.field:contains("+ tag +")");
39
                    $(fields).each(function() {
40
                        var subfields = $(this).parent().find("span.subfield:contains("+ subfieldcode +")");
41
                        if (subfields.length == 0) {
42
                            missing.subfields.push( {
43
                                'tag': tag,
44
                                'subfieldcode': subfieldcode
45
                            } );
46
                        }
47
                    });
48
                }
49
            }
50
        }
51
52
        return missing;
53
    }
54
13
    // When submiting the form
55
    // When submiting the form
14
    function mergeformsubmit() {
56
    function mergeformsubmit() {
15
	    $("ul#ulrecord1").remove();
57
        var missing = check_mandatory();
16
	    $("ul#ulrecord2").remove();
58
        var alert_msg = '';
17
}
59
        var error = 0;
18
60
        if (missing.fields.length > 0) {
19
61
            alert_msg += _("Following required fields are missing:") + "\n";
20
$(document).ready(function(){
62
            for (var i in missing.fields) {
21
    // Creating tabs
63
                alert_msg += "\t- " + missing.fields[i] + "\n";
22
    $("#tabs").tabs();
64
                error ++;
23
65
            }
24
    // Getting marc structure via ajax
66
            alert_msg += "\n";
25
    tagslib = [];
67
        }
26
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
68
        if (missing.subfields.length > 0) {
27
	tagslib = json;
69
            alert_msg += _("Following required subfields are missing:") + "\n";
28
    });
70
            for (var i in missing.subfields) {
29
71
                var subfield = missing.subfields[i];
30
72
                alert_msg += "\t- " + subfield.tag + "$" + subfield.subfieldcode + "\n";
31
    // Toggle a field / subfield
73
                error ++;
32
    function toggleField(pField) {
74
            }
33
75
        }
34
	// Getting the key of the clicked checkbox
76
35
	var ckid   = $(pField).attr("id");
77
        if (error != 0) {
36
	var tab    = ckid.split('_');
78
            alert(alert_msg);
37
	var source = tab[1]; // From which record the click came from
79
            return false;
38
	var key    = tab[2];
80
        } else {
39
	var type   = $(pField).attr("class");
81
            $("#tabs").remove();
40
82
        }
41
	// Getting field/subfield
83
    }
42
	var field;
84
43
	var subfield;
85
    $(document).ready(function(){
44
	if (type == "subfieldpick") {
86
        // Creating tabs
45
87
        $("#tabs").tabs();
46
		    field = $(pField).parent().parent().parent().find("span.field").text();
88
47
		    subfield = $(pField).parent().find("span.subfield").text();
89
        // Getting marc structure via ajax
48
	} else {
90
        tagslib = [];
49
91
        $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
50
		    field = $(pField).parent().find("span.field").text();
92
            tagslib = json;
51
	}
93
        });
52
94
53
	// If the field has just been checked
95
54
	if (pField.checked) {
96
        // Toggle a field / subfield
55
97
        function toggleField(pField) {
56
	    // We check for repeatability
98
            // Getting the key of the clicked checkbox
57
	    var canbeadded = true;
99
            var ckid   = $(pField).attr("id");
58
	    if (type == "subfieldpick") {
100
            var tab    = ckid.split('_');
59
		var repeatable = 1;
101
            var source = tab[1]; // From which record the click came from
60
		var alreadyexists = 0;
102
            var key    = tab[2];
61
		if (tagslib[field] && tagslib[field][subfield]) {
103
            var type   = $(pField).attr("class");
62
		    repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number 
104
63
		    // TODO : Checking for subfields
105
            // Getting field/subfield
64
		}
106
            var field;
65
	    } else {
107
            var subfield;
66
		if (tagslib[field]) {
108
            if (type == "subfieldpick") {
67
		    repeatable = tagslib[field].repeatable;
109
                field = $(pField).parent().parent().parent().find("span.field").text();
68
		    alreadyexists = $("#resultul span.field:contains(" + field + ")");
110
                subfield = $(pField).parent().find("span.subfield").text();
69
		    if (repeatable == 0 && alreadyexists.length != 0) {
111
            } else {
70
			canbeadded = false;
112
                field = $(pField).parent().find("span.field").text();
71
		    }
113
            }
72
		}
114
73
	    }
115
            // If the field has just been checked
74
	    // If the field is not repeatable, we check if it already exists in the result table
116
            if (pField.checked) {
75
	    if (canbeadded == false) {
117
                // We check for repeatability
76
		alert(_("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
118
                var canbeadded = true;
77
		pField.checked = 0;
119
                if (type == "subfieldpick") {
78
	    } else {
120
                    var repeatable = 1;
79
121
                    var alreadyexists = 0;
80
		// Cloning the field or subfield we picked
122
                    if (tagslib[field] && tagslib[field][subfield]) {
81
		var clone = $(pField).parent().clone();
123
                        // Note : we can't use the dot notation here (tagslib.021)
82
124
                        // because the key is a number
83
		// Removing the checkboxes from it
125
                        repeatable = tagslib[field][subfield].repeatable;
84
		$(clone).find("input.subfieldpick, input.fieldpick").each(function() {
126
                        if (repeatable == 0) {
85
		    $(this).remove();
127
                            canbeadded = false;
86
		});
128
                            $("#resultul span.field:contains(" + field + ")")
87
129
                            .each(function() {
88
130
                                if ($(this).parent()
89
		// If we are a subfield
131
                                    .find("span.subfield:contains(" + subfield + ")")
90
		if (type == "subfieldpick") {
132
                                    .length == 0)
91
		    // then we need to find who is our parent field...
133
                                {
92
		    fieldkey = $(pField).parent().parent().parent().attr("id");
134
                                    canbeadded = true;
93
135
                                }
94
		    // Find where to add the subfield
136
                            });
95
137
                        }
96
		    // First, check if the field is not already in the destination record
138
                    }
97
		    if ($("#resultul li#" + fieldkey).length > 0) { 
139
                } else {
98
			// If so, we add our field to it
140
                    if (tagslib[field]) {
99
			$("#resultul li#" + fieldkey + " ul").append(clone);
141
                        repeatable = tagslib[field].repeatable;
100
		    } else {
142
                        alreadyexists = $("#resultul span.field:contains(" + field + ")");
101
			// If not, we add the subfield to the first matching field
143
                        if (repeatable == 0 && alreadyexists.length != 0) {
102
			var where = 0;
144
                            canbeadded = false;
103
			$("#resultul li span.field").each(function() {
145
                        }
104
			    if (where == 0 && $(this).text() == field) {
146
                    }
105
				where = this;
147
                }
106
			    }
148
                // If the field is not repeatable, we check if it already exists in the result table
107
			});
149
                if (canbeadded == false) {
108
150
                    var field_or_subfield = (type == "subfieldpick") ? _("subfield") : _("field");
109
			// If there is no matching field in the destination record
151
                    alert(_("The " + field_or_subfield + " is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
110
			if (where == 0) {
152
                    pField.checked = 0;
111
153
                } else {
112
			    // TODO: 
154
                    // Cloning the field or subfield we picked
113
			    // We select the whole field and removing non-selected subfields, instead of...
155
                    var clone = $(pField).parent().clone();
114
156
115
			    // Alerting the user 
157
                    // Removing the checkboxes from it
116
			    alert(_("This subfield cannot be added: there is no") + " " + field + " " + _("field in the destination record."));
158
                    $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
117
			    pField.checked = false;
159
                        $(this).remove();
118
160
                    });
119
			} else {
161
                    $(clone).find('label').each(function() {
120
			    $(where).nextAll("ul").append(clone);
162
                        $(this).replaceWith($(this).contents());
121
			}
163
                    });
122
164
123
		    }
165
                    // If we are a subfield
124
166
                    if (type == "subfieldpick") {
125
		    
167
                        // then we need to find who is our parent field...
126
		    
168
                        fieldkey = $(pField).parent().parent().parent().attr("id");
127
		} else {
169
128
		    // If we are a field
170
                        // Find where to add the subfield
129
		    var where = 0;
171
130
		    // Find where to add the field
172
                        // First, check if the field is not already in the destination record
131
		    $("#resultul li span.field").each(function() {
173
                        if ($("#resultul li#" + fieldkey).length > 0) { 
132
			if (where == 0 && $(this).text() > field) {
174
                            // If so, we add our field to it
133
			    where = this;
175
                            $("#resultul li#" + fieldkey + " ul").append(clone);
134
			}
176
                        } else {
135
		    });
177
                            // If not, we add the subfield to the first matching field
136
178
                            var where = 0;
137
		    $(where).parent().before(clone);
179
                            $("#resultul li span.field").each(function() {
138
		}
180
                                if (where == 0 && $(this).text() == field) {
139
	    }
181
                                    where = this;
140
	} else {
182
                                }
141
183
                            });
142
	    // Else, we remove it from the results tab
184
143
	    $("ul#resultul li#k" + key).remove();
185
                            // If there is no matching field in the destination record
144
	}
186
                            if (where == 0) {
145
}
187
                                // TODO:
146
188
                                // We select the whole field and removing non-selected subfields, instead of...
147
189
148
    // When a field is checked / unchecked 
190
                                // Alerting the user
149
    $('input.fieldpick').click(function() {
191
                                alert(_("This subfield cannot be added: there is no " + field + " field in the destination record."));
150
	toggleField(this);
192
                                pField.checked = false;
151
	// (un)check all subfields
193
152
	var ischecked = this.checked;
194
                            } else {
153
	$(this).parent().find("input.subfieldpick").each(function() {
195
                                $(where).nextAll("ul").append(clone);
154
	    this.checked = ischecked;
196
                            }
155
	});
197
                        }
156
    });
198
                    } else {
199
                        // If we are a field
200
                        var where = 0;
201
                        // Find where to add the field
202
                        $("#resultul li span.field").each(function() {
203
                            if (where == 0 && $(this).text() > field) {
204
                                where = this;
205
                            }
206
                        });
207
                        if (where) {
208
                            $(where).parent().before(clone);
209
                        } else {
210
                            $("#resultul").prepend(clone);
211
                        }
212
                    }
213
                }
214
            } else {
215
                // Else, we remove it from the results tab
216
                $("ul#resultul li#k" + key).remove();
217
            }
218
        }
219
220
        // Check all checkboxes in first tab, and uncheck all others to avoid
221
        // inconsistencies from a page refresh.
222
        $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').attr('checked', true);
223
        $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').removeAttr('checked');
224
225
        // When a field is checked / unchecked 
226
        $('input.fieldpick').click(function() {
227
            toggleField(this);
228
            // (un)check all subfields
229
            var ischecked = this.checked;
230
            $(this).parent().find("input.subfieldpick").each(function() {
231
                this.checked = ischecked;
232
            });
233
        });
234
235
        // When a field or subfield is checked / unchecked
236
        $("input.subfieldpick").click(function() {
237
            toggleField(this);
238
        });
157
239
158
    // When a field or subfield is checked / unchecked
159
    $("input.subfieldpick").click(function() {
160
	toggleField(this);
161
    });
240
    });
162
241
  [% END %]
163
});
242
[% END %]
164
165
function changeFramework(fw) {
166
    $("#Frameworks").val(fw);
167
}
168
243
169
//]]>
244
//]]>
170
</script>
245
</script>
Lines 182-204 function changeFramework(fw) { Link Here
182
257
183
<h1>Merging records</h1>
258
<h1>Merging records</h1>
184
[% IF ( result ) %]
259
[% IF ( result ) %]
185
    [% IF ( errors ) %]
260
    [% IF ( errors.size ) %]
186
261
        [% FOREACH error IN errors %]
187
	[% FOREACH error IN errors %]
262
            <div class="dialog alert">
188
	    <div class="dialog alert">
189
190
                [% IF error.code == 'CANNOT_MOVE' %]
263
                [% IF error.code == 'CANNOT_MOVE' %]
191
                    The following items could not be moved from the old record to the new one: [% error.value %]
264
                    The following items could not be moved from the old record to the new one: [% error.value %]
192
                [% ELSE %]
265
                [% ELSE %]
193
                    [% error %]
266
                    [% error %]
194
                [% END %]
267
                [% END %]
195
268
                <br />
196
            <br />Therefore, the record to be merged has not been deleted.</div>
269
                Therefore, the record to be merged has not been deleted.
197
	[% END %]
270
            </div>
271
        [% END %]
198
272
199
    [% ELSE %]
273
    [% ELSE %]
200
        <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script>
274
        <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>
201
        <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
275
        <h3>Report</h3>
276
        <table>
277
            <thead>
278
                <tr>
279
                    <th>Biblionumber</th>
280
                    [% FOREACH key IN report_header.keys.sort %]
281
                        [% tag = key.substr(0, 3) %]
282
                        [% code = key.substr(3, 1) %]
283
                        [% IF code == '@' %]
284
                            [% header = tag %]
285
                        [% ELSE %]
286
                            [% header = tag _ '$' _ code %]
287
                        [% END %]
288
                        <th>[% header %]</th>
289
                    [% END %]
290
                </tr>
291
            </thead>
292
            <tbody>
293
                [% FOREACH record IN report_records %]
294
                    <tr>
295
                        <td>
296
                            [% record.biblionumber %]
297
                            [% IF loop.first %]
298
                                (record kept)
299
                            [% END %]
300
                        </td>
301
                        [% FOREACH key IN report_header.keys.sort %]
302
                            <td>
303
                                [% values = record.fields.$key %]
304
                                [% IF values %]
305
                                    [% FOREACH value IN record.fields.$key %]
306
                                        [% value %]
307
                                        [% UNLESS loop.last %]<br />[% END %]
308
                                    [% END %]
309
                                [% END %]
310
                            </td>
311
                        [% END %]
312
                    </tr>
313
                [% END %]
314
            </tbody>
315
        </table>
202
    [% END %]
316
    [% END %]
203
317
204
[% ELSE %]
318
[% ELSE %]
Lines 207-252 function changeFramework(fw) { Link Here
207
<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>
321
<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>
208
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
322
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
209
    <fieldset class="rows">
323
    <fieldset class="rows">
210
	<legend>Merge reference</legend>
324
    <legend>Merge reference</legend>
211
	<ol>
325
    <ol>
212
	<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>
326
        [% FOREACH record IN records %]
213
	<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>
327
            <li class="radio">
214
328
                [% IF loop.first %]
215
    [% IF frameworkselect %]
329
                    <input type="radio" value="[% record.biblionumber %]" checked="checked" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
216
          <li><label for="frameworkcode">Using framework:</label>
330
                [% ELSE %]
217
                      <select name="frameworkcode" id="frameworkcode">
331
                    <input type="radio" value="[% record.biblionumber %]" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
218
                                      <option value="Default">Default</option>
332
                [% END %]
219
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
333
                <label for="ref_biblionumber[% record.biblionumber %]">
220
                                          [% IF ( frameworkcodeloo.selected ) %]
334
                    [% record.data.title %]
221
                                              <option value="[% frameworkcodeloo.value %]" selected="selected">
335
                    [% FOREACH subtitle IN record.subtitles %]
222
                                          [% ELSE %]
336
                        [% subtitle.subfield %]
223
                                              <option value="[% frameworkcodeloo.value %]">
337
                    [% END %]
224
                                          [% END %]
338
                    (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">[% record.biblionumber %]</a>)
225
                                           [% frameworkcodeloo.frameworktext %]
339
                </label>
226
                                           </option>
340
            </li>
227
                                      [% END %]
341
        [% END %]
228
                      </select></li>
342
343
        [% IF frameworkselect.size %]
344
            <li>
345
                <label for="frameworkcode">Using framework:</label>
346
                <select name="frameworkcode" id="frameworkcode">
347
                    <option value="">Default</option>
348
                    [% FOREACH frameworkcode IN frameworkselect %]
349
                        [% IF ( frameworkcode.selected ) %]
350
                            <option value="[% frameworkcode.value %]" selected="selected">
351
                        [% ELSE %]
352
                            <option value="[% frameworkcode.value %]">
353
                        [% END %]
354
                            [% frameworkcode.frameworktext %]
355
                        </option>
356
                    [% END %]
357
                </select>
358
            </li>
359
        [% END %]
360
    </ol>
361
362
    [% FOREACH record IN records %]
363
        <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
229
    [% END %]
364
    [% END %]
230
</ol>
365
    <fieldset class="action">
231
366
        <input type="submit" value="Next" />
232
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
367
    </fieldset>
233
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
234
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
235
    </fieldset>
368
    </fieldset>
236
</form>
369
</form>
237
[% ELSE %]
370
[% ELSE %]
238
[% IF ( errors ) %]
371
[% IF ( errors.size ) %]
239
    <div class="dialog alert">
372
    <div class="dialog alert">
240
	[% FOREACH error IN errors %]
373
        [% FOREACH error IN errors %]
241
	    <p>
374
            <p>[% error %]</p>
242
                [% IF error.code == 'WRONG_COUNT' %]
375
        [% END %]
243
                    Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
244
                [% ELSE %]
245
                    [% error %]
246
                [% END %]
247
248
            </p>
249
	[% END %]
250
    </div>
376
    </div>
251
[% ELSE %]
377
[% ELSE %]
252
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
378
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
Lines 256-387 function changeFramework(fw) { Link Here
256
<div id="tabs" class="toptabs">
382
<div id="tabs" class="toptabs">
257
<h2>Source records</h2>
383
<h2>Source records</h2>
258
    <ul>
384
    <ul>
259
	<li><a href="#tabrecord1">[% biblio1 %]</a></li>
385
        [% FOREACH record IN records %]
260
	<li><a href="#tabrecord2">[% biblio2 %]</a></li>
386
            <li>
387
                <a href="#tabrecord[% record.biblionumber %]">
388
                    [% record.biblionumber %]
389
                    [% IF record.reference %](ref)[% END %]
390
                </a>
391
            </li>
392
        [% END %]
261
    </ul>
393
    </ul>
262
    <div id="tabrecord1">
394
    [% IF ( records.size ) %]
263
	[% IF ( record1 ) %]
395
        [% FOREACH record IN records %]
264
396
            <div id="tabrecord[% record.biblionumber %]">
265
	    <div class="record">
397
                <div class="record">
266
		<ul id="ulrecord1">
398
                    <ul id="ulrecord[% record.biblionumber %]">
267
		[% FOREACH record IN record1 %]
399
                        [% FOREACH field IN record.display.fields %]
268
			[% FOREACH fiel IN record.field %]
400
                          [% IF field.tag != biblionumbertag %]
269
			<li id="k[% fiel.key %]">
401
                            <li id="k[% field.key %]">
270
			    <input type="checkbox" checked="checked" class="fieldpick" id="rec_1_[% fiel.key %]" /> 
402
                                [% IF (record.reference) %]
271
			    <span class="field">[% fiel.tag %]</span>
403
                                    <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
272
404
                                [% ELSE %]
273
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
405
                                    <input type="checkbox" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
274
			    <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
406
                                [% END %]
275
			    [% IF ( fiel.value ) %] / [% fiel.value %]
407
                                <label for="rec_[% record.biblionumber %]_[% field.key %]"><span class="field">[% field.tag %]</span></label>
276
				<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
408
277
				<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
409
                                <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
278
			    [% END %]
410
                                <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
279
411
                                [% IF ( field.value ) %]
280
			    [% IF ( fiel.subfield ) %]
412
                                    / [% field.value %]
281
				<ul>
413
                                    <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
282
				    [% FOREACH subfiel IN fiel.subfield %]
414
                                    <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value %]" />
283
					<li id="k[% subfiel.subkey %]">
415
                                [% END %]
284
					    <input type="checkbox" checked="checked" class="subfieldpick" id="rec_1_[% subfiel.subkey %]" /> 
416
285
					    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
417
                                [% IF ( field.subfield.size ) %]
286
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
418
                                    <ul>
287
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
419
                                        [% FOREACH subfield IN field.subfield %]
288
					</li>
420
                                            <li id="k[% subfield.subkey %]">
289
				    [% END %]
421
                                                [% IF (record.reference) %]
290
				</ul>
422
                                                    <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
291
			    [% END %]
423
                                                [% ELSE %]
292
		    [% END %]
424
                                                    <input type="checkbox" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
293
		    </li>
425
                                                [% END %]
294
		[% END %]
426
                                                <label for="rec_[% record.biblionumber %]_[% subfield.subkey %]"><span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]</label>
295
		</ul>
427
                                                <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
296
	    </div><!-- /div.record -->
428
                                                <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% subfield.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
297
[% END %]
429
                                            </li>
298
    </div><!-- /div#tabrecord1 -->
430
                                        [% END %]
299
    <div id="tabrecord2">
431
                                    </ul>
300
	[% IF ( record2 ) %]
432
                                [% END %]
301
433
                            </li>
302
	   <div class="record">
434
                          [% END %]
303
		<ul id="ulrecord2">
435
                        [% END %]
304
		[% FOREACH record IN record2 %]
436
                    </ul>
305
		    [% FOREACH fiel IN record.field %]
437
                </div><!-- /div.record -->
306
		    <li id="k[% fiel.key %]">
438
            </div><!-- /div#tabrecordXXX -->
307
			<input type="checkbox" class="fieldpick" id="rec_2_[% fiel.key %]" /> 
439
        [% END %]
308
			<span class="field">[% fiel.tag %]</span>
440
    [% END %]
309
310
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
311
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
312
			[% IF ( fiel.value ) %] / [% fiel.value %]
313
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
314
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
315
			[% END %]
316
317
			[% IF ( fiel.subfield ) %]
318
			    <ul>
319
				[% FOREACH subfiel IN fiel.subfield %]
320
				    <li id="k[% subfiel.subkey %]">
321
					<input type="checkbox" class="subfieldpick" id="rec_2_[% subfiel.subkey %]" />
322
					<span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
323
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
324
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
325
				    </li>
326
				[% END %]
327
			    </ul>
328
			[% END %]
329
		    [% END %]
330
		    </li>
331
		[% END %]
332
		</ul>
333
	    </div>
334
	    <!-- /div.record -->
335
336
337
338
339
	[% END %]
340
    </div><!-- /div#tabrecord2 -->
341
</div> <!-- // #tabs -->
441
</div> <!-- // #tabs -->
342
</div>
442
</div>
343
<div class="yui-u">
443
<div class="yui-u">
344
<div id="result">
444
<div id="result">
345
    <h2>Destination record</h2>
445
    <h2>Destination record</h2>
346
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
446
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
347
	    <ul id="resultul">
447
        <ul id="resultul">
348
	[% FOREACH record IN record1 %]
448
          [% FOREACH field IN ref_record.display.fields %]
349
		    [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]"><span class="field">[% fiel.tag %]</span>  
449
            [% IF field.tag != biblionumbertag %]
350
			<input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
450
              <li id="k[% field.key %]">
351
			<input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
451
                <span class="field">[% field.tag %]</span>
352
		    [% IF ( fiel.value ) %] /
452
                <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
353
			[% fiel.value %]
453
                <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
354
			<input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
454
                [% IF ( field.value ) %]
355
			<input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
455
                  / [% field.value %]
356
		    [% END %]
456
                  <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
357
			
457
                  <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value |html%]" />
358
		    [% IF ( fiel.subfield ) %]
458
                [% END %]
359
			<ul>
459
360
			    [% FOREACH subfiel IN fiel.subfield %]
460
                [% IF ( field.subfield ) %]
361
				<li id="k[% subfiel.subkey %]">
461
                  <ul>
362
				    <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
462
                    [% FOREACH subfield IN field.subfield %]
363
				    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
463
                      <li id="k[% subfield.subkey %]">
364
				    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
464
                        <span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]
365
				</li>
465
                        <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
366
			    [% END %]
466
                        <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
367
			</ul>
467
                      </li>
368
		    [% END %]
468
                    [% END %]
369
469
                  </ul>
370
		    [% END %]
470
                [% END %]
371
		    </li>
471
              </li>
372
		[% END %]
472
            [% END %]
373
473
          [% END %]
374
	    </ul>
474
        </ul>
375
</div>
475
</div>
376
</div> <!-- // #result -->
476
</div> <!-- // #result -->
377
</div> <!-- .yui-u -->
477
</div> <!-- .yui-u -->
378
478
379
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
479
<input type="hidden" name="ref_biblionumber" value="[% ref_biblionumber %]" />
380
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
480
[% FOREACH record IN records %]
381
<input type="hidden" name="mergereference" value="[% mergereference %]" />
481
    <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
482
[% END %]
382
<input type="hidden" name="frameworkcode" value="[% framework %]" />
483
<input type="hidden" name="frameworkcode" value="[% framework %]" />
383
484
384
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
485
<fieldset class="action">
486
    <input type="submit" name="merge" value="Merge" />
487
    <label for="report_fields">Fields to display in report:</label>
488
    <input type="text" name="report_fields" id="report_fields" value="[% MergeReportFields %]" />
489
    <span class="hint">(Example: "001,245ab,600")
490
</fieldset>
385
</div>
491
</div>
386
</form>
492
</form>
387
[% END %]
493
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-9 / +12 lines)
Lines 36-49 $(document).ready(function(){ Link Here
36
     * This function checks if the adequate number of records are checked for merging
36
     * This function checks if the adequate number of records are checked for merging
37
     */
37
     */
38
    function MergeItems() {
38
    function MergeItems() {
39
	var checkboxes = $("input:checkbox:checked");
39
        var checkboxes = $("input:checkbox:checked");
40
        var nbCheckbox = checkboxes.length;
40
        if (checkboxes.length > 0) {
41
	if (nbCheckbox != 2) {
41
            var params = [];
42
	    alert(_("Two records must be selected for merging."));
42
            $(checkboxes).each(function() {
43
	} else {
43
                params.push('biblionumber=' + $(this).val());
44
	    location.href='/cgi-bin/koha/cataloguing/merge.pl?biblionumber=' + checkboxes[0].value + '&amp;biblionumber=' + checkboxes[1].value;
44
            });
45
	}
45
            var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
46
	return false;
46
            location.href = url;
47
        } else {
48
            alert(_("You must select at least one record"));
49
        }
50
        return false;
47
    }
51
    }
48
52
49
    /**
53
    /**
50
- 

Return to bug 8064