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 (-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 190-195 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
190
('maxoutstanding','5','','maximum amount withstanding to be able make holds','Integer'),
190
('maxoutstanding','5','','maximum amount withstanding to be able make holds','Integer'),
191
('maxRecordsForFacets','20',NULL,NULL,'Integer'),
191
('maxRecordsForFacets','20',NULL,NULL,'Integer'),
192
('maxreserves','50','','Define maximum number of holds a patron can place','Integer'),
192
('maxreserves','50','','Define maximum number of holds a patron can place','Integer'),
193
('MergeReportFields','',NULL,'Displayed fields for deleted MARC records after merge','Free'),
193
('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'),
194
('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'),
194
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
195
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
195
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
196
('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
(-)a/installer/data/mysql/updatedatabase.pl (+11 lines)
Lines 8551-8556 if (CheckVersion($DBversion)) { Link Here
8551
    SetVersion($DBversion);
8551
    SetVersion($DBversion);
8552
}
8552
}
8553
8553
8554
$DBversion = "XXX";
8555
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
8556
    $dbh->do("
8557
        INSERT INTO systempreferences (variable,value,explanation,options,type)
8558
        VALUES('MergeReportFields','','Displayed fields for deleted MARC records after merge',NULL,'Free');
8559
    ");
8560
    print "Upgrade to $DBversion done (Add system preference 'MergeReportFields')\n";
8561
    SetVersion($DBversion);
8562
}
8563
8564
8554
=head1 FUNCTIONS
8565
=head1 FUNCTIONS
8555
8566
8556
=head2 TableExists($table)
8567
=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 191-196 Cataloging: Link Here
191
                  yes: Display
191
                  yes: Display
192
                  no: "Don't display"
192
                  no: "Don't display"
193
            - acquisition details on the biblio detail page.
193
            - acquisition details on the biblio detail page.
194
        -
195
            - pref: MergeReportFields
196
            - "fields to display for deleted records after merge"
197
            - "<br />example: '001,245ab,600'"
198
            - "displays:"
199
            - "<ul>"
200
            - "<li>value of 001</li>"
201
            - "<li>subfields a and b of fields 245</li>"
202
            - "<li>all subfields of fields 600</li>"
194
    Importing:
203
    Importing:
195
        -
204
        -
196
            - When matching on ISBN with the record import tool,
205
            - 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 29-40 $(document).ready(function(){ Link Here
29
93
30
    // Creating tabs
94
    // Creating tabs
31
    $("#tabs").tabs();
95
    $("#tabs").tabs();
32
});
33
96
97
    // Check all checkboxes in first tab, and uncheck all others to avoid
98
    // inconsistencies from a page refresh.
99
    $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').attr('checked', true);
100
    $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').removeAttr('checked');
34
101
35
function changeFramework(fw) {
102
});
36
    $("#Frameworks").val(fw);
103
37
}
104
  [% END %]
105
[% END %]
38
106
39
//]]>
107
//]]>
40
</script>
108
</script>
Lines 52-74 function changeFramework(fw) { Link Here
52
120
53
<h1>Merging records</h1>
121
<h1>Merging records</h1>
54
[% IF ( result ) %]
122
[% IF ( result ) %]
55
    [% IF ( errors ) %]
123
    [% IF ( errors.size ) %]
56
124
       [% FOREACH error IN errors %]
57
	[% FOREACH error IN errors %]
125
           <div class="dialog alert">
58
	    <div class="dialog alert">
59
60
                [% IF error.code == 'CANNOT_MOVE' %]
126
                [% IF error.code == 'CANNOT_MOVE' %]
61
                    The following items could not be moved from the old record to the new one: [% error.value %]
127
                    The following items could not be moved from the old record to the new one: [% error.value %]
62
                [% ELSE %]
128
                [% ELSE %]
63
                    [% error %]
129
                    [% error %]
64
                [% END %]
130
                [% END %]
65
131
                <br />
66
            <br />Therefore, the record to be merged has not been deleted.</div>
132
                Therefore, the record to be merged has not been deleted.
67
	[% END %]
133
            </div>
134
       [% END %]
68
135
69
    [% ELSE %]
136
    [% ELSE %]
70
        <script type="text/javascript">window.location.href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]"</script>
137
        <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>
71
        <p>The merging was successful. <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=[% biblio1 %]">Click here to see the merged record.</a></p>
138
        <h3>Report</h3>
139
        <table>
140
            <thead>
141
                <tr>
142
                    <th>Biblionumber</th>
143
                    [% FOREACH key IN report_header.keys.sort %]
144
                        [% tag = key.substr(0, 3) %]
145
                        [% code = key.substr(3, 1) %]
146
                        [% IF code == '@' %]
147
                            [% header = tag %]
148
                        [% ELSE %]
149
                            [% header = tag _ '$' _ code %]
150
                        [% END %]
151
                        <th>[% header %]</th>
152
                    [% END %]
153
                </tr>
154
            </thead>
155
            <tbody>
156
                [% FOREACH record IN report_records %]
157
                    <tr>
158
                        <td>
159
                            [% record.biblionumber %]
160
                            [% IF loop.first %]
161
                                (record kept)
162
                            [% END %]
163
                        </td>
164
                        [% FOREACH key IN report_header.keys.sort %]
165
                            <td>
166
                                [% values = record.fields.$key %]
167
                                [% IF values %]
168
                                    [% FOREACH value IN record.fields.$key %]
169
                                        [% value %]
170
                                        [% UNLESS loop.last %]<br />[% END %]
171
                                    [% END %]
172
                                [% END %]
173
                            </td>
174
                        [% END %]
175
                    </tr>
176
                [% END %]
177
            </tbody>
178
        </table>
72
    [% END %]
179
    [% END %]
73
180
74
[% ELSE %]
181
[% ELSE %]
Lines 77-140 function changeFramework(fw) { Link Here
77
<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>
184
<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>
78
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
185
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post">
79
    <fieldset class="rows">
186
    <fieldset class="rows">
80
	<legend>Merge reference</legend>
187
    <legend>Merge reference</legend>
81
	<ol>
188
    <ol>
82
	<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>
189
        [% FOREACH record IN records %]
83
	<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>
190
            <li class="radio">
84
191
                [% IF loop.first %]
85
    [% IF frameworkselect %]
192
                    <input type="radio" value="[% record.biblionumber %]" checked="checked" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
86
          <li><label for="frameworkcode">Using framework:</label>
193
                [% ELSE %]
87
                      <select name="frameworkcode" id="frameworkcode">
194
                    <input type="radio" value="[% record.biblionumber %]" id="ref_biblionumber[% record.biblionumber %]" name="ref_biblionumber" onclick="changeFramework('[% record.frameworkcode %]')" />
88
                                      <option value="Default">Default</option>
195
                [% END %]
89
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
196
                <label for="ref_biblionumber[% record.biblionumber %]">
90
                                          [% IF ( frameworkcodeloo.selected ) %]
197
                    [% record.data.title %]
91
                                              <option value="[% frameworkcodeloo.value %]" selected="selected">
198
                    [% FOREACH subtitle IN record.subtitles %]
92
                                          [% ELSE %]
199
                        [% subtitle.subfield %]
93
                                              <option value="[% frameworkcodeloo.value %]">
200
                    [% END %]
94
                                          [% END %]
201
                    (<a href="/cgi-bin/koha/catalogue/showmarc.pl?id=[% record.biblionumber %]" title="MARC" rel="gb_page_center[600,500]">[% record.biblionumber %]</a>)
95
                                           [% frameworkcodeloo.frameworktext %]
202
                </label>
96
                                           </option>
203
            </li>
97
                                      [% END %]
204
        [% END %]
98
                      </select></li>
205
99
    [% END %]
206
        [% IF frameworkselect.size %]
100
</ol>
207
            <li>
208
                <label for="frameworkcode">Using framework:</label>
209
                <select name="frameworkcode" id="frameworkcode">
210
                    <option value="">Default</option>
211
                    [% FOREACH frameworkcode IN frameworkselect %]
212
                        [% IF ( frameworkcode.selected ) %]
213
                            <option value="[% frameworkcode.value %]" selected="selected">
214
                        [% ELSE %]
215
                            <option value="[% frameworkcode.value %]">
216
                        [% END %]
217
                            [% frameworkcode.frameworktext %]
218
                        </option>
219
                    [% END %]
220
                </select>
221
            </li>
222
        [% END %]
223
    </ol>
101
224
102
	<input type="hidden" name="biblionumber" value="[% biblio1 %]" />
225
    [% FOREACH record IN records %]
103
	<input type="hidden" name="biblionumber" value="[% biblio2 %]" />
226
        <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
104
	<fieldset class="action"><input type="submit" value="Next" /></fieldset>
227
    [% END %]
228
    <fieldset class="action">
229
        <input type="submit" value="Next" />
230
    </fieldset>
105
    </fieldset>
231
    </fieldset>
106
</form>
232
</form>
107
[% ELSE %]
233
[% ELSE %]
108
[% IF ( errors ) %]
234
[% IF ( errors.size ) %]
109
    <div class="dialog alert">
235
    <div class="dialog alert">
110
	[% FOREACH error IN errors %]
236
        [% FOREACH error IN errors %]
111
	    <p>
237
            <p>[% error %]</p>
112
                [% IF error.code == 'WRONG_COUNT' %]
238
        [% END %]
113
                    Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
114
                [% ELSE %]
115
                    [% error %]
116
                [% END %]
117
118
            </p>
119
	[% END %]
120
    </div>
239
    </div>
121
[% ELSE %]
240
[% ELSE %]
122
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
241
<form id="mergeform" action="/cgi-bin/koha/cataloguing/merge.pl" method="post" onsubmit="return mergeformsubmit()">
123
242
124
<div class="yui-g">
243
<div class="yui-g">
125
<div class="yui-u first">
244
<div class="yui-u first">
126
[% PROCESS mergesource recordid1=biblio1 recordid2=biblio2 %]
245
[% PROCESS mergesource sourcerecords=records %]
127
</div>
246
</div>
128
<div class="yui-u">
247
<div class="yui-u">
129
[% PROCESS mergetarget %]
248
[% PROCESS mergetarget %]
130
</div> <!-- .yui-u -->
249
</div> <!-- .yui-u -->
131
250
132
<input type="hidden" name="biblio1" value="[% biblio1 %]" />
251
<input type="hidden" name="ref_biblionumber" value="[% ref_biblionumber %]" />
133
<input type="hidden" name="biblio2" value="[% biblio2 %]" />
252
[% FOREACH record IN records %]
134
<input type="hidden" name="mergereference" value="[% mergereference %]" />
253
    <input type="hidden" name="biblionumber" value="[% record.biblionumber %]" />
254
[% END %]
135
<input type="hidden" name="frameworkcode" value="[% framework %]" />
255
<input type="hidden" name="frameworkcode" value="[% framework %]" />
136
256
137
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
257
<fieldset class="action">
258
    <input type="submit" name="merge" value="Merge" />
259
    <label for="report_fields">Fields to display in report:</label>
260
    <input type="text" name="report_fields" id="report_fields" value="[% MergeReportFields %]" />
261
    <span class="hint">(Example: "001,245ab,600")
262
</fieldset>
138
</div>
263
</div>
139
</form>
264
</form>
140
[% END %]
265
[% 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