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 70-81 sub createMergeHash { Link Here
70
                        && $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'} >= 0 )
65
                        && $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'} >= 0 )
71
                  )
66
                  )
72
                {
67
                {
73
                    push @subfield_array,
68
                    push @subfield_array, {
74
                      {
75
                        subtag => @$subfield[0],
69
                        subtag => @$subfield[0],
76
                        subkey => _createKey(),
70
                        subkey => _createKey(),
77
                        value  => @$subfield[1],
71
                        value  => @$subfield[1],
78
                      };
72
                    };
79
                }
73
                }
80
74
81
            }
75
            }
Lines 89-105 sub createMergeHash { Link Here
89
                && @subfield_array
83
                && @subfield_array
90
              )
84
              )
91
            {
85
            {
92
                push @array,
86
                push @array, {
93
                  {
87
                      tag        => $fieldtag,
94
                    field => [
88
                      key        => _createKey(),
95
                        {
89
                      indicator1 => $field->indicator(1),
96
                            tag        => $fieldtag,
90
                      indicator2 => $field->indicator(2),
97
                            key        => _createKey(),
91
                      subfield   => [@subfield_array],
98
                            indicator1 => $field->indicator(1),
99
                            indicator2 => $field->indicator(2),
100
                            subfield   => [@subfield_array],
101
                        }
102
                    ]
103
                  };
92
                  };
104
            }
93
            }
105
94
(-)a/cataloguing/merge.pl (-124 / +156 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-27 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
24
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
25
use C4::Output;
24
use C4::Output;
26
use C4::Auth;
25
use C4::Auth;
27
use C4::Items;
26
use C4::Items;
Lines 33-39 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;
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 203-208 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
203
('maxoutstanding','5','','maximum amount withstanding to be able make holds','Integer'),
203
('maxoutstanding','5','','maximum amount withstanding to be able make holds','Integer'),
204
('maxRecordsForFacets','20',NULL,NULL,'Integer'),
204
('maxRecordsForFacets','20',NULL,NULL,'Integer'),
205
('maxreserves','50','','Define maximum number of holds a patron can place','Integer'),
205
('maxreserves','50','','Define maximum number of holds a patron can place','Integer'),
206
('MergeReportFields','',NULL,'Displayed fields for deleted MARC records after merge','Free'),
206
('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'),
207
('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'),
207
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
208
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
208
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
209
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
(-)a/installer/data/mysql/updatedatabase.pl (+11 lines)
Lines 9732-9737 if ( CheckVersion($DBversion) ) { Link Here
9732
    SetVersion($DBversion);
9732
    SetVersion($DBversion);
9733
}
9733
}
9734
9734
9735
$DBversion = "XXX";
9736
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
9737
    $dbh->do("
9738
        INSERT INTO systempreferences (variable,value,explanation,options,type)
9739
        VALUES('MergeReportFields','','Displayed fields for deleted MARC records after merge',NULL,'Free');
9740
    ");
9741
    print "Upgrade to $DBversion done (Add system preference 'MergeReportFields')\n";
9742
    SetVersion($DBversion);
9743
}
9744
9745
9735
=head1 FUNCTIONS
9746
=head1 FUNCTIONS
9736
9747
9737
=head2 TableExists($table)
9748
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc (-64 / +75 lines)
Lines 1-91 Link Here
1
[% BLOCK sourcetab %]
1
[% BLOCK sourcetab %]
2
    <div id="tabrecord[% recordnumber %]">
2
    <div id="tabrecord[% record.biblionumber %]">
3
    [% IF ( records ) %]
4
5
        <div class="record">
3
        <div class="record">
6
        <ul id="ulrecord[% recordnumber %]">
4
            <ul id="ulrecord[% record.biblionumber %]">
7
        [% FOREACH record IN records %]
5
                [% FOREACH field IN record.display %]
8
            [% FOREACH fiel IN record.field %]
6
                  [% IF field.tag != biblionumbertag %]
9
            <li id="k[% fiel.key %]">
7
                    <li id="k[% field.key %]">
10
                [% IF (defaultrecord) %]
8
                        [% IF (tabrecord.reference) %]
11
                    <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% recordnumber %]_[% fiel.key %]" />
9
                            <input type="checkbox" checked="checked" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
12
                [% ELSE %]
10
                        [% ELSE %]
13
                    <input type="checkbox" class="fieldpick" id="rec_[% recordnumber %]_[% fiel.key %]" />
11
                            <input type="checkbox" class="fieldpick" id="rec_[% record.biblionumber %]_[% field.key %]" />
14
                [% END %]
12
                        [% END %]
15
                <span class="field">[% fiel.tag %]</span>
13
                        <label for="rec_[% record.biblionumber %]_[% field.key %]"><span class="field">[% field.tag %]</span></label>
16
14
17
                <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
15
                        <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
18
                <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
16
                        <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
19
                [% IF ( fiel.value ) %] / [% fiel.value %]
17
                        [% IF ( field.value ) %]
20
                <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
18
                            / [% field.value %]
21
                <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value %]" />
19
                            <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
22
                [% END %]
20
                            <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value %]" />
21
                        [% END %]
23
22
24
                [% IF ( fiel.subfield ) %]
23
                        [% IF ( field.subfield.size ) %]
25
                <ul>
24
                            <ul>
26
                    [% FOREACH subfiel IN fiel.subfield %]
25
                                [% FOREACH subfield IN field.subfield %]
27
                    <li id="k[% subfiel.subkey %]">
26
                                    <li id="k[% subfield.subkey %]">
28
                        [% IF (defaultrecord) %]
27
                                        [% IF (tabrecord.reference) %]
29
                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% recordnumber %]_[% subfiel.subkey %]" />
28
                                            <input type="checkbox" checked="checked" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
30
                        [% ELSE %]
29
                                        [% ELSE %]
31
                            <input type="checkbox" class="subfieldpick" id="rec_[% recordnumber %]_[% subfiel.subkey %]" />
30
                                            <input type="checkbox" class="subfieldpick" id="rec_[% record.biblionumber %]_[% subfield.subkey %]" />
31
                                        [% END %]
32
                                        <label for="rec_[% record.biblionumber %]_[% subfield.subkey %]"><span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]</label>
33
                                        <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
34
                                        <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% subfield.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
35
                                    </li>
36
                                [% END %]
37
                            </ul>
32
                        [% END %]
38
                        [% END %]
33
                        <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
34
                    <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
35
                    <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
36
                    </li>
39
                    </li>
37
                    [% END %]
40
                  [% END %]
38
                </ul>
39
                [% END %]
41
                [% END %]
40
            [% END %]
42
            </ul>
41
            </li>
42
        [% END %]
43
        </ul>
44
        </div><!-- /div.record -->
43
        </div><!-- /div.record -->
45
    [% END %]
44
    </div><!-- /div#tabrecordXXX -->
46
    </div><!-- /div#tabrecord[% recordnumber %] -->
47
[% END %]
45
[% END %]
46
48
[% BLOCK mergesource %]
47
[% BLOCK mergesource %]
49
<div id="tabs" class="toptabs">
48
<div id="tabs" class="toptabs">
50
<h2>Source records</h2>
49
<h2>Source records</h2>
51
    <ul>
50
    <ul>
52
    <li><a href="#tabrecord1">[% recordid1 %]</a></li>
51
        [% FOREACH record IN sourcerecords %]
53
    <li><a href="#tabrecord2">[% recordid2 %]</a></li>
52
            <li>
53
                <a href="#tabrecord[% record.biblionumber %]">
54
                    [% record.biblionumber %]
55
                    [% IF record.reference %](ref)[% END %]
56
                </a>
57
            </li>
58
        [% END %]
54
    </ul>
59
    </ul>
55
    [% PROCESS sourcetab records=record1 recordnumber=1 defaultrecord=1 %]
60
    [% IF ( sourcerecords.size ) %]
56
    [% PROCESS sourcetab records=record2 recordnumber=2 defaultrecord=0 %]
61
        [% FOREACH record IN sourcerecords %]
62
            [% PROCESS sourcetab tabrecord=record %]
63
        [% END %]
64
    [% END %]
57
</div> <!-- // #tabs -->
65
</div> <!-- // #tabs -->
58
[% END %]
66
[% END %]
67
59
[% BLOCK mergetarget %]
68
[% BLOCK mergetarget %]
60
<div id="result">
69
<div id="result">
61
    <h2>Destination record</h2>
70
    <h2>Destination record</h2>
62
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
71
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
63
        <ul id="resultul">
72
        <ul id="resultul">
64
        [% FOREACH record IN record1 %]
73
          [% FOREACH field IN ref_record.display %]
65
            [% FOREACH fiel IN record.field %]<li id="k[% fiel.key %]">
74
            [% IF field.tag != biblionumbertag %]
66
                <span class="field">[% fiel.tag %]</span>
75
              <li id="k[% field.key %]">
67
                <input type="hidden" name="tag_[% fiel.tag %]_indicator1_[% fiel.key %]" value="[% fiel.indicator1 %]" />
76
                <span class="field">[% field.tag %]</span>
68
                <input type="hidden" name="tag_[% fiel.tag %]_indicator2_[% fiel.key %]" value="[% fiel.indicator2 %]" />
77
                <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
69
                [% IF ( fiel.value ) %] /
78
                <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
70
                    [% fiel.value %]
79
                [% IF ( field.value ) %]
71
                    <input type="hidden" name="tag_[% fiel.tag %]_code_00_[% fiel.key %]" value="00" />
80
                  / [% field.value %]
72
                    <input type="hidden" name="tag_[% fiel.tag %]_subfield_00_[% fiel.key %]" value="[% fiel.value |html%]" />
81
                  <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
82
                  <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value |html%]" />
73
                [% END %]
83
                [% END %]
74
84
75
                [% IF ( fiel.subfield ) %]
85
                [% IF ( field.subfield ) %]
76
                    <ul>
86
                  <ul>
77
                        [% FOREACH subfiel IN fiel.subfield %]
87
                    [% FOREACH subfield IN field.subfield %]
78
                            <li id="k[% subfiel.subkey %]">
88
                      <li id="k[% subfield.subkey %]">
79
                                <span class="subfield">[% subfiel.subtag %]</span> / [% subfiel.value %]
89
                        <span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]
80
                                <input type="hidden" name="tag_[% subfiel.tag %]_code_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.subtag %]" />
90
                        <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
81
                                <input type="hidden" name="tag_[% subfiel.tag %]_subfield_[% subfiel.subtag %]_[% subfiel.key %]_[% subfiel.subkey %]" value="[% subfiel.value |html%]" />
91
                        <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
82
                            </li>
92
                      </li>
83
                        [% END %]
93
                    [% END %]
84
                    </ul>
94
                  </ul>
85
                [% END %]
95
                [% END %]
86
            </li>[% END %]
96
              </li>
87
        [% END %]
97
            [% END %]
98
          [% END %]
88
        </ul>
99
        </ul>
89
    </div>
100
</div>
90
</div> <!-- // #result -->
101
</div> <!-- // #result -->
91
[% END %]
102
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+9 lines)
Lines 207-212 Cataloging: Link Here
207
                  yes: Display
207
                  yes: Display
208
                  no: "Don't display"
208
                  no: "Don't display"
209
            - acquisition details on the biblio detail page.
209
            - acquisition details on the biblio detail page.
210
        -
211
            - pref: MergeReportFields
212
            - "fields to display for deleted records after merge"
213
            - "<br />example: '001,245ab,600'"
214
            - "displays:"
215
            - "<ul>"
216
            - "<li>value of 001</li>"
217
            - "<li>subfields a and b of fields 245</li>"
218
            - "<li>all subfields of fields 600</li>"
210
    Importing:
219
    Importing:
211
        -
220
        -
212
            - When matching on ISBN with the record import tool,
221
            - When matching on ISBN with the record import tool,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-57 / +182 lines)
Lines 13-24 div#result { margin-top: 1em; } Link Here
13
</style>
13
</style>
14
<script type="text/javascript">
14
<script type="text/javascript">
15
//<![CDATA[
15
//<![CDATA[
16
[% UNLESS (result) %]
17
  [% IF (choosereference) %]
18
    function changeFramework(fw) {
19
        $("#frameworkcode").val(fw);
20
    }
21
  [% ELSE %]
22
    function check_mandatory () {
23
        var missing = {
24
            'fields': [],
25
            'subfields': []
26
        };
27
        for (tag in tagslib) {
28
            if (tag == '000' || tag == '001')
29
                continue;
30
            if (tagslib[tag].mandatory == 1) {
31
                if ($("#resultul span.field:contains("+ tag +")").length == 0) {
32
                    missing.fields.push(tag);
33
                }
34
            }
35
            for (subfieldcode in tagslib[tag]) {
36
                if (subfieldcode == 'lib' || subfieldcode == 'mandatory'
37
                || subfieldcode == 'repeatable' || subfieldcode == 'tab') {
38
                    continue;
39
                }
40
                if (tagslib[tag][subfieldcode].mandatory == 1 && tagslib[tag][subfieldcode].tab >= 0) {
41
                    var fields = $("#resultul span.field:contains("+ tag +")");
42
                    $(fields).each(function() {
43
                        var subfields = $(this).parent().find("span.subfield:contains("+ subfieldcode +")");
44
                        if (subfields.length == 0) {
45
                            missing.subfields.push( {
46
                                'tag': tag,
47
                                'subfieldcode': subfieldcode
48
                            } );
49
                        }
50
                    });
51
                }
52
            }
53
        }
54
        return missing;
55
    }
16
56
17
    // When submiting the form
57
    // When submiting the form
18
    function mergeformsubmit() {
58
    function mergeformsubmit() {
19
	    $("ul#ulrecord1").remove();
59
        var missing = check_mandatory();
20
	    $("ul#ulrecord2").remove();
60
        var alert_msg = '';
21
}
61
        var error = 0;
62
        if (missing.fields.length > 0) {
63
            alert_msg += _("Following required fields are missing:") + "\n";
64
            for (var i in missing.fields) {
65
                alert_msg += "\t- " + missing.fields[i] + "\n";
66
                error ++;
67
            }
68
            alert_msg += "\n";
69
        }
70
        if (missing.subfields.length > 0) {
71
            alert_msg += _("Following required subfields are missing:") + "\n";
72
            for (var i in missing.subfields) {
73
                var subfield = missing.subfields[i];
74
                alert_msg += "\t- " + subfield.tag + "$" + subfield.subfieldcode + "\n";
75
                error ++;
76
            }
77
        }
78
79
        if (error != 0) {
80
            alert(alert_msg);
81
            return false;
82
        } else {
83
            $("#tabs").remove();
84
        }
85
    }
22
86
23
$(document).ready(function(){
87
$(document).ready(function(){
24
    // Getting marc structure via ajax
88
    // Getting marc structure via ajax
Lines 32-43 $(document).ready(function(){ Link Here
32
96
33
    // Creating tabs
97
    // Creating tabs
34
    $("#tabs").tabs();
98
    $("#tabs").tabs();
35
});
36
99
100
    // Check all checkboxes in first tab, and uncheck all others to avoid
101
    // inconsistencies from a page refresh.
102
    $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').attr('checked', true);
103
    $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').removeAttr('checked');
37
104
38
function changeFramework(fw) {
105
});
39
    $("#Frameworks").val(fw);
106
40
}
107
  [% END %]
108
[% END %]
41
109
42
//]]>
110
//]]>
43
</script>
111
</script>
Lines 55-77 function changeFramework(fw) { Link Here
55
123
56
<h1>Merging records</h1>
124
<h1>Merging records</h1>
57
[% IF ( result ) %]
125
[% IF ( result ) %]
58
    [% IF ( errors ) %]
126
    [% IF ( errors.size ) %]
59
127
       [% FOREACH error IN errors %]
60
	[% FOREACH error IN errors %]
128
           <div class="dialog alert">
61
	    <div class="dialog alert">
62
63
                [% IF error.code == 'CANNOT_MOVE' %]
129
                [% IF error.code == 'CANNOT_MOVE' %]
64
                    The following items could not be moved from the old record to the new one: [% error.value %]
130
                    The following items could not be moved from the old record to the new one: [% error.value %]
65
                [% ELSE %]
131
                [% ELSE %]
66
                    [% error %]
132
                    [% error %]
67
                [% END %]
133
                [% END %]
68
134
                <br />
69
            <br />Therefore, the record to be merged has not been deleted.</div>
135
                Therefore, the record to be merged has not been deleted.
70
	[% END %]
136
            </div>
137
       [% END %]
71
138
72
    [% ELSE %]
139
    [% ELSE %]
73
        <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script>
140
        <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>
74
        <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
141
        <h3>Report</h3>
142
        <table>
143
            <thead>
144
                <tr>
145
                    <th>Biblionumber</th>
146
                    [% FOREACH key IN report_header.keys.sort %]
147
                        [% tag = key.substr(0, 3) %]
148
                        [% code = key.substr(3, 1) %]
149
                        [% IF code == '@' %]
150
                            [% header = tag %]
151
                        [% ELSE %]
152
                            [% header = tag _ '$' _ code %]
153
                        [% END %]
154
                        <th>[% header %]</th>
155
                    [% END %]
156
                </tr>
157
            </thead>
158
            <tbody>
159
                [% FOREACH record IN report_records %]
160
                    <tr>
161
                        <td>
162
                            [% record.biblionumber %]
163
                            [% IF loop.first %]
164
                                (record kept)
165
                            [% END %]
166
                        </td>
167
                        [% FOREACH key IN report_header.keys.sort %]
168
                            <td>
169
                                [% values = record.fields.$key %]
170
                                [% IF values %]
171
                                    [% FOREACH value IN record.fields.$key %]
172
                                        [% value %]
173
                                        [% UNLESS loop.last %]<br />[% END %]
174
                                    [% END %]
175
                                [% END %]
176
                            </td>
177
                        [% END %]
178
                    </tr>
179
                [% END %]
180
            </tbody>
181
        </table>
75
    [% END %]
182
    [% END %]
76
183
77
[% ELSE %]
184
[% ELSE %]
Lines 80-143 function changeFramework(fw) { Link Here
80
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
187
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
81
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
188
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
82
    <fieldset class="rows">
189
    <fieldset class="rows">
83
	<legend>Merge reference</legend>
190
    <legend>Merge reference</legend>
84
	<ol>
191
    <ol>
85
	<li class="radio"><input type="radio" value="[% biblio1 %]" checked="checked" id="mergereference1" name="mergereference" onclick="changeFramework('[% frameworkcode1 %]')" /><label for="mergereference1">[% title1 %] [% FOREACH subtitl1 IN subtitle1 %] [% subtitl1.subfield %][% END %] (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% biblio1 %]" title="MARC" rel="gb_page_center[600,500]">[% biblio1 %]</a>)</label></li>
192
        [% FOREACH record IN records %]
86
	<li class="radio"><input type="radio" value="[% biblio2 %]" id="mergereference2" name="mergereference" onclick="changeFramework('[% frameworkcode2 %]')" /><label for="mergereference2">[% title2 %] [% FOREACH subtitl2 IN subtitle2 %] [% subtitl2.subfield %][% END %] (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% biblio2 %]" title="MARC" rel="gb_page_center[600,500]">[% biblio2 %]</a>)</label></li>
193
            <li class="radio">
87
194
                [% IF loop.first %]
88
    [% IF frameworkselect %]
195
                    <input type="radio" value="[% record.biblionumber %]" checked="checked" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
89
          <li><label for="frameworkcode">Using framework:</label>
196
                [% ELSE %]
90
                      <select name="frameworkcode" id="frameworkcode">
197
                    <input type="radio" value="[% record.biblionumber %]" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
91
                                      <option value="Default">Default</option>
198
                [% END %]
92
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
199
                <label for="ref_biblionumber[% record.biblionumber %]">
93
                                          [% IF ( frameworkcodeloo.selected ) %]
200
                    [% record.data.title %]
94
                                              <option value="[% frameworkcodeloo.value %]" selected="selected">
201
                    [% FOREACH subtitle IN record.subtitles %]
95
                                          [% ELSE %]
202
                        [% subtitle.subfield %]
96
                                              <option value="[% frameworkcodeloo.value %]">
203
                    [% END %]
97
                                          [% END %]
204
                    (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">[% record.biblionumber %]</a>)
98
                                           [% frameworkcodeloo.frameworktext %]
205
                </label>
99
                                           </option>
206
            </li>
100
                                      [% END %]
207
        [% END %]
101
                      </select></li>
208
102
    [% END %]
209
        [% IF frameworkselect.size %]
103
</ol>
210
            <li>
211
                <label for="frameworkcode">Using framework:</label>
212
                <select name="frameworkcode" id="frameworkcode">
213
                    <option value="">Default</option>
214
                    [% FOREACH frameworkcode IN frameworkselect %]
215
                        [% IF ( frameworkcode.selected ) %]
216
                            <option value="[% frameworkcode.value %]" selected="selected">
217
                        [% ELSE %]
218
                            <option value="[% frameworkcode.value %]">
219
                        [% END %]
220
                            [% frameworkcode.frameworktext %]
221
                        </option>
222
                    [% END %]
223
                </select>
224
            </li>
225
        [% END %]
226
    </ol>
104
227
105
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
228
    [% FOREACH record IN records %]
106
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
229
        <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
107
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
230
    [% END %]
231
    <fieldset class="action">
232
        <input type="submit" value="Next" />
233
    </fieldset>
108
    </fieldset>
234
    </fieldset>
109
</form>
235
</form>
110
[% ELSE %]
236
[% ELSE %]
111
[% IF ( errors ) %]
237
[% IF ( errors.size ) %]
112
    <div class="dialog alert">
238
    <div class="dialog alert">
113
	[% FOREACH error IN errors %]
239
        [% FOREACH error IN errors %]
114
	    <p>
240
            <p>[% error %]</p>
115
                [% IF error.code == 'WRONG_COUNT' %]
241
        [% END %]
116
                    Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
117
                [% ELSE %]
118
                    [% error %]
119
                [% END %]
120
121
            </p>
122
	[% END %]
123
    </div>
242
    </div>
124
[% ELSE %]
243
[% ELSE %]
125
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
244
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
126
245
127
<div class="yui-g">
246
<div class="yui-g">
128
<div class="yui-u first">
247
<div class="yui-u first">
129
[% PROCESS mergesource recordid1=biblio1 recordid2=biblio2 %]
248
[% PROCESS mergesource sourcerecords=records %]
130
</div>
249
</div>
131
<div class="yui-u">
250
<div class="yui-u">
132
[% PROCESS mergetarget %]
251
[% PROCESS mergetarget %]
133
</div> <!-- .yui-u -->
252
</div> <!-- .yui-u -->
134
253
135
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
254
<input type="hidden" name="ref_biblionumber" value="[% ref_biblionumber %]" />
136
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
255
[% FOREACH record IN records %]
137
<input type="hidden" name="mergereference" value="[% mergereference %]" />
256
    <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
257
[% END %]
138
<input type="hidden" name="frameworkcode" value="[% framework %]" />
258
<input type="hidden" name="frameworkcode" value="[% framework %]" />
139
259
140
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
260
<fieldset class="action">
261
    <input type="submit" name="merge" value="Merge" />
262
    <label for="report_fields">Fields to display in report:</label>
263
    <input type="text" name="report_fields" id="report_fields" value="[% MergeReportFields %]" />
264
    <span class="hint">(Example: "001,245ab,600")
265
</fieldset>
141
</div>
266
</div>
142
</form>
267
</form>
143
[% END %]
268
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt (-9 / +12 lines)
Lines 101-114 $(document).ready(function(){ Link Here
101
     * This function checks if the adequate number of records are checked for merging
101
     * This function checks if the adequate number of records are checked for merging
102
     */
102
     */
103
    function MergeItems() {
103
    function MergeItems() {
104
	var checkboxes = $("input:checkbox:checked");
104
        var checkboxes = $("input:checkbox:checked");
105
        var nbCheckbox = checkboxes.length;
105
        if (checkboxes.length > 0) {
106
	if (nbCheckbox != 2) {
106
            var params = [];
107
	    alert(_("Two records must be selected for merging."));
107
            $(checkboxes).each(function() {
108
	} else {
108
                params.push('biblionumber=' + $(this).val());
109
	    location.href='/cgi-bin/koha/cataloguing/merge.pl?biblionumber=' + checkboxes[0].value + '&amp;biblionumber=' + checkboxes[1].value;
109
            });
110
	}
110
            var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&');
111
	return false;
111
            location.href = url;
112
        } else {
113
            alert(_("You must select at least one record"));
114
        }
115
        return false;
112
    }
116
    }
113
117
114
    /**
118
    /**
115
- 

Return to bug 8064