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

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