X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=cataloguing%2Fmerge.pl;h=020001d010477afdecb711ba7c8d2eb574453f4d;hb=0048c94b32fed9b6a4728be744db80821b621770;hp=be84df5bb458fba179991cfc83aa3778206f3ed4;hpb=4747ea7462c04770484386538b1594c1760bc75b;p=koha_fer diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index be84df5bb4..020001d010 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -2,6 +2,7 @@ # Copyright 2009 BibLibre +# Parts Copyright Catalyst IT 2011 # # This file is part of Koha. # @@ -14,18 +15,20 @@ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +#use warnings; FIXME - Bug 2505 use CGI; use C4::Output; use C4::Auth; use C4::Items; use C4::Biblio; use C4::Serials; -use YAML; +use C4::Koha; +use C4::Reserves qw/MergeHolds/; my $input = new CGI; my @biblionumber = $input->param('biblionumber'); @@ -48,15 +51,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( #------------------------ if ($merge) { - my @params = $input->param(); my $dbh = C4::Context->dbh; my $sth; # Creating a new record from the html code - my $record = TransformHtmlToMarc( \@params , $input ); + my $record = TransformHtmlToMarc( $input ); my $tobiblio = $input->param('biblio1'); my $frombiblio = $input->param('biblio2'); - my $frameworkcode = &GetFrameworkCode($tobiblio); + + # Rewriting the leader + $record->leader(GetMarcBiblio($tobiblio)->leader()); + + my $frameworkcode = $input->param('frameworkcode'); my @notmoveditems; # Modifying the reference record @@ -64,7 +70,6 @@ if ($merge) { # Moving items from the other record to the reference record my $itemnumbers = get_itemnumbers_of($frombiblio); - use Data::Dumper; foreach my $itloop ($itemnumbers->{$frombiblio}) { foreach my $itemnumber (@$itloop) { my $res = MoveItemFromBiblio($itemnumber, $frombiblio, $tobiblio); @@ -98,84 +103,119 @@ if ($merge) { # Deleting the other record if (scalar(@errors) == 0) { + # Move holds + MergeHolds($dbh,$tobiblio,$frombiblio); my $error = DelBiblio($frombiblio); push @errors, $error if ($error); } - # Errors - my @errors_loop = map{{error => $_}}@errors; - # Parameters - $template->param({ - errors => \@errors_loop, + $template->param( result => 1, biblio1 => $input->param('biblio1') - }); - + ); #------------------------- # Show records to merge #------------------------- } else { - my $mergereference = $input->param('mergereference'); my $biblionumber = $input->param('biblionumber'); - my $data1 = GetBiblioData($biblionumber[0]); - my $data2 = GetBiblioData($biblionumber[1]); - - # Ask the user to choose which record will be the kept - if (not $mergereference) { - $template->param({ - choosereference => 1, - biblio1 => $biblionumber[0], - biblio2 => $biblionumber[1], - title1 => $data1->{'title'}, - title2 => $data2->{'title'} - }); - } else { - - if (scalar(@biblionumber) != 2) { - push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged."; - } - - # Checks if both records use the same framework - my $frameworkcode1 = &GetFrameworkCode($biblionumber[0]); - my $frameworkcode2 = &GetFrameworkCode($biblionumber[1]); - my $framework; - if ($frameworkcode1 ne $frameworkcode2) { - push @errors, "The records selected for merging are using different frameworks. Currently merging is only available for records using the same framework."; - } else { - $framework = $frameworkcode1; - } - - # Getting MARC Structure - my $tagslib = GetMarcStructure(1, $framework); - - my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0]; - - # Creating a loop for display - my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib); - my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib); - - # Errors - my @errors_loop = map{{error => $_}}@errors; - - # Parameters - $template->param({ - errors => \@errors_loop, - biblio1 => $mergereference, - biblio2 => $notreference, - mergereference => $mergereference, - record1 => @record1, - record2 => @record2, - framework => $framework - }); + if (scalar(@biblionumber) != 2) { + push @errors, "An unexpected number of records was provided for merging. Currently only two records at a time can be merged."; + } + 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."; + } else { + $framework = $frameworkcode1; + } + + # Getting MARC Structure + my $tagslib = GetMarcStructure(1, $framework); + + my $notreference = ($biblionumber[0] == $mergereference) ? $biblionumber[1] : $biblionumber[0]; + + # Creating a loop for display + my @record1 = _createMarcHash(GetMarcBiblio($mergereference), $tagslib); + my @record2 = _createMarcHash(GetMarcBiblio($notreference), $tagslib); + + # Parameters + $template->param( + biblio1 => $mergereference, + biblio2 => $notreference, + mergereference => $mergereference, + record1 => @record1, + record2 => @record2, + framework => $framework, + ); + } + else { + + # 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 + ); + 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, + ); + } + } } } + +if (@errors) { + # Errors + my @errors_loop = map{{error => $_}}@errors; + $template->param( errors => \@errors_loop ); +} + output_html_with_http_headers $input, $cookie, $template->output; exit; +=head1 FUNCTIONS + +=cut # ------------------------ # Functions @@ -235,14 +275,15 @@ sub _createMarcHash { } -=item CreateKey +=head2 CreateKey - Create a random value to set it into the input name +Create a random value to set it into the input name =cut -sub createKey(){ +sub createKey { return int(rand(1000000)); } +