From 6143a2bf440ca44968c6609db8f3663ce3a3c9da Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 28 May 2013 16:24:53 +0200 Subject: [PATCH] Bug 8064: Merge several biblios This patch improves the existing merging tool by adding possibility to merge more than 2 biblios. There is no functional changes: - Add some biblios to a list - In the list check some biblios and click on 'Merge selected records' - Choose the biblio which will be kept, all others will be deleted - On the next page you have all biblios you chose in tabs (left side of the screen) and the preview of result (right side) - Pick some fields or subfields from records that will be deleted or delete some fields from reference record. - Click on 'Merge', if there is no errors you are redirected to the biblio view. Added checks for non-repeatable subfields Added checks for mandatory fields and subfields before submitting the form. Added a final report which display deleted records (see syspref MergeReportFields) Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Util/MARC.pm | 37 +-- cataloguing/merge.pl | 280 ++++++++++-------- .../8064_MergeReportFields_syspref.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/includes/merge-record.inc | 139 +++++---- .../admin/preferences/cataloguing.pref | 9 + .../prog/en/modules/cataloguing/merge.tt | 239 +++++++++++---- .../prog/en/modules/virtualshelves/shelves.tt | 20 +- 8 files changed, 450 insertions(+), 277 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/8064_MergeReportFields_syspref.sql diff --git a/Koha/Util/MARC.pm b/Koha/Util/MARC.pm index 5d026ee3cf..22774b63b2 100644 --- a/Koha/Util/MARC.pm +++ b/Koha/Util/MARC.pm @@ -46,16 +46,11 @@ sub createMergeHash { if ( !defined($tagslib) || $tagslib->{$fieldtag}->{'@'}->{'tab'} >= 0 ) { - push @array, - { - field => [ - { - tag => $fieldtag, - key => _createKey(), - value => $field->data(), - } - ] - }; + push @array, { + tag => $fieldtag, + key => _createKey(), + value => $field->data(), + }; } } else { @@ -70,12 +65,11 @@ sub createMergeHash { && $tagslib->{$fieldtag}->{ @$subfield[0] }->{'tab'} >= 0 ) ) { - push @subfield_array, - { + push @subfield_array, { subtag => @$subfield[0], subkey => _createKey(), value => @$subfield[1], - }; + }; } } @@ -89,17 +83,12 @@ sub createMergeHash { && @subfield_array ) { - push @array, - { - field => [ - { - tag => $fieldtag, - key => _createKey(), - indicator1 => $field->indicator(1), - indicator2 => $field->indicator(2), - subfield => [@subfield_array], - } - ] + push @array, { + tag => $fieldtag, + key => _createKey(), + indicator1 => $field->indicator(1), + indicator2 => $field->indicator(2), + subfield => [@subfield_array], }; } diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index 876f066f01..a1e56be541 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl - # Copyright 2009 BibLibre # Parts Copyright Catalyst IT 2011 # @@ -19,9 +18,9 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -#use warnings; FIXME - Bug 2505 +use Modern::Perl; use CGI qw ( -utf8 ); + use C4::Output; use C4::Auth; use C4::Items; @@ -33,7 +32,7 @@ use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/; use Koha::MetadataRecord; my $input = new CGI; -my @biblionumber = $input->param('biblionumber'); +my @biblionumbers = $input->param('biblionumber'); my $merge = $input->param('merge'); my @errors; @@ -54,28 +53,41 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( if ($merge) { my $dbh = C4::Context->dbh; - my $sth; # Creating a new record from the html code my $record = TransformHtmlToMarc( $input ); - my $tobiblio = $input->param('biblio1'); - my $frombiblio = $input->param('biblio2'); + my $ref_biblionumber = $input->param('ref_biblionumber'); + @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers; + + # prepare report + my @report_records; + my $report_fields_str = $input->param('report_fields'); + $report_fields_str ||= C4::Context->preference('MergeReportFields'); + my @report_fields; + foreach my $field_str (split /,/, $report_fields_str) { + if ($field_str =~ /(\d{3})([0-9a-z]*)/) { + my ($field, $subfields) = ($1, $2); + push @report_fields, { + tag => $field, + subfields => [ split //, $subfields ] + } + } + } # Rewriting the leader - $record->leader(GetMarcBiblio($tobiblio)->leader()); + $record->leader(GetMarcBiblio($ref_biblionumber)->leader()); my $frameworkcode = $input->param('frameworkcode'); my @notmoveditems; # Modifying the reference record - ModBiblio($record, $tobiblio, $frameworkcode); + ModBiblio($record, $ref_biblionumber, $frameworkcode); # Moving items from the other record to the reference record - # Also moving orders from the other record to the reference record, only if the order is linked to an item of the other record - my $itemnumbers = get_itemnumbers_of($frombiblio); - foreach my $itloop ($itemnumbers->{$frombiblio}) { - foreach my $itemnumber (@$itloop) { - my $res = MoveItemFromBiblio($itemnumber, $frombiblio, $tobiblio); + foreach my $biblionumber (@biblionumbers) { + my $itemnumbers = get_itemnumbers_of($biblionumber); + foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) { + my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber); if (not defined $res) { push @notmoveditems, $itemnumber; } @@ -87,137 +99,165 @@ if ($merge) { push @errors, { code => "CANNOT_MOVE", value => $itemlist }; } - # Moving subscriptions from the other record to the reference record - my $subcount = CountSubscriptionFromBiblionumber($frombiblio); - if ($subcount > 0) { - $sth = $dbh->prepare("UPDATE subscription SET biblionumber = ? WHERE biblionumber = ?"); - $sth->execute($tobiblio, $frombiblio); - - $sth = $dbh->prepare("UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ?"); - $sth->execute($tobiblio, $frombiblio); - + my $sth_subscription = $dbh->prepare(" + UPDATE subscription SET biblionumber = ? WHERE biblionumber = ? + "); + my $sth_subscriptionhistory = $dbh->prepare(" + UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ? + "); + my $sth_serial = $dbh->prepare(" + UPDATE serial SET biblionumber = ? WHERE biblionumber = ? + "); + + my $report_header = {}; + foreach my $biblionumber ($ref_biblionumber, @biblionumbers) { + # build report + my $marcrecord = GetMarcBiblio($biblionumber); + my %report_record = ( + biblionumber => $biblionumber, + fields => {}, + ); + foreach my $field (@report_fields) { + my @marcfields = $marcrecord->field($field->{tag}); + foreach my $marcfield (@marcfields) { + my $tag = $marcfield->tag(); + my %subfields; + if (scalar @{$field->{subfields}}) { + foreach my $subfield (@{$field->{subfields}}) { + my @values = $marcfield->subfield($subfield); + $report_header->{ $tag . $subfield } = 1; + push @{ $report_record{fields}->{$tag . $subfield} }, @values; + } + } elsif ($field->{tag} gt '009') { + my @marcsubfields = $marcfield->subfields(); + foreach my $marcsubfield (@marcsubfields) { + my ($code, $value) = @$marcsubfield; + $report_header->{ $tag . $code } = 1; + push @{ $report_record{fields}->{ $tag . $code } }, $value; + } + } else { + $report_header->{ $tag . '@' } = 1; + push @{ $report_record{fields}->{ $tag .'@' } }, $marcfield->data(); + } + } + } + push @report_records, \%report_record; } - # Moving serials - $sth = $dbh->prepare("UPDATE serial SET biblionumber = ? WHERE biblionumber = ?"); - $sth->execute($tobiblio, $frombiblio); + foreach my $biblionumber (@biblionumbers) { + # Moving subscriptions from the other record to the reference record + my $subcount = CountSubscriptionFromBiblionumber($biblionumber); + if ($subcount > 0) { + $sth_subscription->execute($ref_biblionumber, $biblionumber); + $sth_subscriptionhistory->execute($ref_biblionumber, $biblionumber); + } - # TODO : Moving reserves + # Moving serials + $sth_serial->execute($ref_biblionumber, $biblionumber); # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio) - my @allorders = GetOrdersByBiblionumber($frombiblio); - my @tobiblioitem = GetBiblioItemByBiblioNumber ($tobiblio); + my @allorders = GetOrdersByBiblionumber($biblionumber); + my @tobiblioitem = GetBiblioItemByBiblioNumber ($ref_biblionumber); my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber }; foreach my $myorder (@allorders) { - $myorder->{'biblionumber'} = $tobiblio; + $myorder->{'biblionumber'} = $ref_biblionumber; ModOrder ($myorder); # TODO : add error control (in ModOrder?) } - # Deleting the other record + # Deleting the other records if (scalar(@errors) == 0) { - # Move holds - MergeHolds($dbh,$tobiblio,$frombiblio); - my $error = DelBiblio($frombiblio); - push @errors, $error if ($error); + # Move holds + MergeHolds($dbh, $ref_biblionumber, $biblionumber); + my $error = DelBiblio($biblionumber); + push @errors, $error if ($error); } +} # Parameters $template->param( - result => 1, - biblio1 => $input->param('biblio1') + result => 1, + report_records => \@report_records, + report_header => $report_header, + ref_biblionumber => $input->param('ref_biblionumber') ); #------------------------- # Show records to merge #------------------------- } else { - my $mergereference = $input->param('mergereference'); - my $biblionumber = $input->param('biblionumber'); - - if (scalar(@biblionumber) != 2) { - push @errors, { code => "WRONG_COUNT", value => scalar(@biblionumber) }; - } - else { - my $data1 = GetBiblioData($biblionumber[0]); - my $record1 = GetMarcBiblio($biblionumber[0]); - - my $data2 = GetBiblioData($biblionumber[1]); - my $record2 = GetMarcBiblio($biblionumber[1]); - - # Checks if both records use the same framework - my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]); - my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]); - - - my $subtitle1 = GetRecordValue('subtitle', $record1, $frameworkcode1); - my $subtitle2 = GetRecordValue('subtitle', $record2, $frameworkcode1); - - if ($mergereference) { - - my $framework; - if ($frameworkcode1 ne $frameworkcode2) { - $framework = $input->param('frameworkcode') - or push @errors, "Famework not selected."; + my $ref_biblionumber = $input->param('ref_biblionumber'); + + if ($ref_biblionumber) { + my $framework = $input->param('frameworkcode'); + $framework //= GetFrameworkCode($ref_biblionumber); + + # Getting MARC Structure + my $tagslib = GetMarcStructure(1, $framework); + + my $marcflavour = lc(C4::Context->preference('marcflavour')); + + # Creating a loop for display + my @records; + foreach my $biblionumber (@biblionumbers) { + my $marcrecord = GetMarcBiblio($biblionumber); + my $frameworkcode = GetFrameworkCode($biblionumber); + my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour}); + my $record = { + biblionumber => $biblionumber, + record => $marcrecord, + frameworkcode => $frameworkcode, + display => $recordObj->createMergeHash($tagslib), + }; + if ($ref_biblionumber and $ref_biblionumber == $biblionumber) { + $record->{reference} = 1; + $template->param(ref_record => $record); + unshift @records, $record; } else { - $framework = $frameworkcode1; + push @records, $record; } - - # Getting MARC Structure - my $tagslib = GetMarcStructure(1, $framework); - - my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0]; - - # Creating a loop for display - - my $recordObj1 = new Koha::MetadataRecord({ 'record' => GetMarcBiblio($mergereference), 'schema' => lc C4::Context->preference('marcflavour') }); - my $recordObj2 = new Koha::MetadataRecord({ 'record' => GetMarcBiblio($notreference), 'schema' => lc C4::Context->preference('marcflavour') }); - - my @record1 = $recordObj1->createMergeHash($tagslib); - my @record2 = $recordObj2->createMergeHash($tagslib); - - # Parameters - $template->param( - biblio1 => $mergereference, - biblio2 => $notreference, - mergereference => $mergereference, - record1 => @record1, - record2 => @record2, - framework => $framework, - ); } - else { + my ($biblionumbertag) = GetMarcFromKohaField('biblio.biblionumber'); + + # Parameters + $template->param( + ref_biblionumber => $ref_biblionumber, + records => \@records, + ref_record => $records[0], + framework => $framework, + biblionumbertag => $biblionumbertag, + MergeReportFields => C4::Context->preference('MergeReportFields'), + ); + } else { + my @records; + foreach my $biblionumber (@biblionumbers) { + my $frameworkcode = GetFrameworkCode($biblionumber); + my $record = { + biblionumber => $biblionumber, + data => GetBiblioData($biblionumber), + frameworkcode => $frameworkcode, + }; + push @records, $record; + } # Ask the user to choose which record will be the kept - $template->param( - choosereference => 1, - biblio1 => $biblionumber[0], - biblio2 => $biblionumber[1], - title1 => $data1->{'title'}, - subtitle1 => $subtitle1, - title2 => $data2->{'title'}, - subtitle2 => $subtitle2 + $template->param( + choosereference => 1, + records => \@records, + ); + + my $frameworks = getframeworks; + my @frameworkselect; + foreach my $thisframeworkcode ( keys %$frameworks ) { + my %row = ( + value => $thisframeworkcode, + frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, ); - if ($frameworkcode1 ne $frameworkcode2) { - my $frameworks = getframeworks; - my @frameworkselect; - foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - if ($frameworkcode1 eq $thisframeworkcode){ - $row{'selected'} = 1; - } - push @frameworkselect, \%row; - } - $template->param( - frameworkselect => \@frameworkselect, - frameworkcode1 => $frameworkcode1, - frameworkcode2 => $frameworkcode2, - ); - } + push @frameworkselect, \%row; } + $template->param( + frameworkselect => \@frameworkselect, + ); } } @@ -228,11 +268,3 @@ if (@errors) { output_html_with_http_headers $input, $cookie, $template->output; exit; - -=head1 FUNCTIONS - -=cut - -# ------------------------ -# Functions -# ------------------------ diff --git a/installer/data/mysql/atomicupdate/8064_MergeReportFields_syspref.sql b/installer/data/mysql/atomicupdate/8064_MergeReportFields_syspref.sql new file mode 100644 index 0000000000..6441fee981 --- /dev/null +++ b/installer/data/mysql/atomicupdate/8064_MergeReportFields_syspref.sql @@ -0,0 +1,2 @@ +INSERT INTO systempreferences (variable,value,explanation,options,type) +VALUES('MergeReportFields','','Displayed fields for deleted MARC records after merge',NULL,'Free'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 2e4a01924b..60b776acb5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -218,6 +218,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('maxRecordsForFacets','20',NULL,NULL,'Integer'), ('maxreserves','50','','Define maximum number of holds a patron can place','Integer'), ('MembershipExpiryDaysNotice',NULL,'Send an account expiration notice that a patron\'s card is about to expire after',NULL,'Integer'), +('MergeReportFields','',NULL,'Displayed fields for deleted MARC records after merge','Free'), ('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'), ('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''), ('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc index 81a7cc878c..4752515fcc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc @@ -1,91 +1,102 @@ [% BLOCK sourcetab %] -
- [% IF ( records ) %] - +
-
    - [% FOREACH record IN records %] - [% FOREACH fiel IN record.field %] -
  • - [% IF (defaultrecord) %] - - [% ELSE %] - - [% END %] - [% fiel.tag %] +
      + [% FOREACH field IN record.display %] + [% IF field.tag != biblionumbertag %] +
    • + [% IF (tabrecord.reference) %] + + [% ELSE %] + + [% END %] + - - - [% IF ( fiel.value ) %] / [% fiel.value %] - - - [% END %] + + + [% IF ( field.value ) %] + / [% field.value %] + + + [% END %] - [% IF ( fiel.subfield ) %] -
        - [% FOREACH subfiel IN fiel.subfield %] -
      • - [% IF (defaultrecord) %] - - [% ELSE %] - + [% IF ( field.subfield.size ) %] +
          + [% FOREACH subfield IN field.subfield %] +
        • + [% IF (tabrecord.reference) %] + + [% ELSE %] + + [% END %] + + + +
        • + [% END %] +
        [% END %] - [% subfiel.subtag %] / [% subfiel.value %] - -
      • - [% END %] -
      + [% END %] [% END %] - [% END %] -
    • - [% END %] -
    +
- [% END %] -
+
[% END %] + [% BLOCK mergesource %]

Source records

- [% PROCESS sourcetab records=record1 recordnumber=1 defaultrecord=1 %] - [% PROCESS sourcetab records=record2 recordnumber=2 defaultrecord=0 %] + [% IF ( sourcerecords.size ) %] + [% FOREACH record IN sourcerecords %] + [% PROCESS sourcetab tabrecord=record %] + [% END %] + [% END %]
[% END %] + [% BLOCK mergetarget %]

Destination record

    - [% FOREACH record IN record1 %] - [% FOREACH fiel IN record.field %]
  • - [% fiel.tag %] - - - [% IF ( fiel.value ) %] / - [% fiel.value %] - - + [% FOREACH field IN ref_record.display %] + [% IF field.tag != biblionumbertag %] +
  • + [% field.tag %] + + + [% IF ( field.value ) %] + / [% field.value %] + + [% END %] - [% IF ( fiel.subfield ) %] -
      - [% FOREACH subfiel IN fiel.subfield %] -
    • - [% subfiel.subtag %] / [% subfiel.value %] - - -
    • - [% END %] -
    + [% IF ( field.subfield ) %] +
      + [% FOREACH subfield IN field.subfield %] +
    • + [% subfield.subtag %] / [% subfield.value %] + + +
    • + [% END %] +
    [% END %] -
  • [% END %] - [% END %] + + [% END %] + [% END %]
-
+
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 703e17ce47..108e6e6f20 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -207,6 +207,15 @@ Cataloging: yes: Display no: "Don't display" - acquisition details on the biblio detail page. + - + - pref: MergeReportFields + - "fields to display for deleted records after merge" + - "
example: '001,245ab,600'" + - "displays:" + - "
    " + - "
  • value of 001
  • " + - "
  • subfields a and b of fields 245
  • " + - "
  • all subfields of fields 600
  • " Importing: - - When matching on ISBN with the record import tool, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt index 2e306fd26e..b6495fa41c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt @@ -13,12 +13,76 @@ div#result { margin-top: 1em; } @@ -55,23 +123,62 @@ function changeFramework(fw) {

    Merging records

    [% IF ( result ) %] - [% IF ( errors ) %] - - [% FOREACH error IN errors %] -
    - + [% IF ( errors.size ) %] + [% FOREACH error IN errors %] +
    [% IF error.code == 'CANNOT_MOVE' %] The following items could not be moved from the old record to the new one: [% error.value %] [% ELSE %] [% error %] [% END %] - -
    Therefore, the record to be merged has not been deleted.
    - [% END %] +
    + Therefore, the record to be merged has not been deleted. +
    + [% END %] [% ELSE %] - -

    The merging was successful. Click here to see the merged record.

    +

    The merge was successful. Click here to see the merged record.

    +

    Report

    + + + + + [% FOREACH key IN report_header.keys.sort %] + [% tag = key.substr(0, 3) %] + [% code = key.substr(3, 1) %] + [% IF code == '@' %] + [% header = tag %] + [% ELSE %] + [% header = tag _ '$' _ code %] + [% END %] + + [% END %] + + + + [% FOREACH record IN report_records %] + + + [% FOREACH key IN report_header.keys.sort %] + + [% END %] + + [% END %] + +
    Biblionumber[% header %]
    + [% record.biblionumber %] + [% IF loop.first %] + (record kept) + [% END %] + + [% values = record.fields.$key %] + [% IF values %] + [% FOREACH value IN record.fields.$key %] + [% value %] + [% UNLESS loop.last %]
    [% END %] + [% END %] + [% END %] +
    [% END %] [% ELSE %] @@ -80,64 +187,82 @@ function changeFramework(fw) {

    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.

    - Merge reference -
      -
    1. -
    2. - - [% IF frameworkselect %] -
    3. -
    4. - [% END %] -
    + Merge reference +
      + [% FOREACH record IN records %] +
    1. + [% IF loop.first %] + + [% ELSE %] + + [% END %] + +
    2. + [% END %] + + [% IF frameworkselect.size %] +
    3. + + +
    4. + [% END %] +
    - - -
    + [% FOREACH record IN records %] + + [% END %] +
    + +
    [% ELSE %] -[% IF ( errors ) %] +[% IF ( errors.size ) %]
    - [% FOREACH error IN errors %] -

    - [% IF error.code == 'WRONG_COUNT' %] - Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time. - [% ELSE %] - [% error %] - [% END %] - -

    - [% END %] + [% FOREACH error IN errors %] +

    [% error %]

    + [% END %]
    [% ELSE %]
    -[% PROCESS mergesource recordid1=biblio1 recordid2=biblio2 %] +[% PROCESS mergesource sourcerecords=records %]
    [% PROCESS mergetarget %]
    - - - + +[% FOREACH record IN records %] + +[% END %] -
    +
    + + + + (Example: "001,245ab,600") +
    [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index ffc12de77a..e710e581ac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -196,14 +196,18 @@ $(document).ready(function(){ * This function checks if the adequate number of records are checked for merging */ function MergeItems() { - var checkboxes = $("input:checkbox:checked"); - var nbCheckbox = checkboxes.length; - if (nbCheckbox != 2) { - alert(_("Two records must be selected for merging.")); - } else { - location.href='/cgi-bin/koha/cataloguing/merge.pl?biblionumber=' + checkboxes[0].value + '&biblionumber=' + checkboxes[1].value; - } - return false; + var checkboxes = $("input:checkbox:checked"); + if (checkboxes.length > 0) { + var params = []; + $(checkboxes).each(function() { + params.push('biblionumber=' + $(this).val()); + }); + var url = '/cgi-bin/koha/cataloguing/merge.pl?' + params.join('&'); + location.href = url; + } else { + alert(_("You must select at least one record")); + } + return false; } /** -- 2.39.5