From 531fb1fdcdafdf9c193adefc0c189da6679a15a7 Mon Sep 17 00:00:00 2001 From: kados Date: Mon, 6 Mar 2006 02:45:41 +0000 Subject: [PATCH] Adding fixes to MARC editor to HEAD --- C4/Biblio.pm | 72 ++++++++++++++++++++++++++++++++++++++-- cataloguing/addbiblio.pl | 14 +++----- cataloguing/additem.pl | 14 +++----- 3 files changed, 78 insertions(+), 22 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 1699b55ec4..cb582ad7a0 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -65,7 +65,7 @@ $VERSION = do { my @v = '$Revision$' =~ /\d+/g; &NEWmodbiblioframework &MARCkoha2marcBiblio &MARCmarc2koha - &MARCkoha2marcItem &MARChtml2marc + &MARCkoha2marcItem &MARChtml2marc &MARChtml2xml &MARCgetbiblio &MARCgetitem &XMLgetbiblio @@ -621,7 +621,72 @@ sub MARCkoha2marcOnefield { } return $record; } - +=head2 MARChtml2xml + +$XMLrecord = MARChtml2xml($rtags,$rsubfields,$rvalues,$indicator,$ind_tag); + +transforms the parameters (coming from HTML form) into a MARC::File::XML +object. parameters with r are references to arrays + +=cut +sub MARChtml2xml { + my ($tags,$subfields,$values,$indicator,$ind_tag) = @_; + use MARC::File::XML; + my $xml= MARC::File::XML::header(); + my $prevvalue; + my $prevtag=-1; + my $first=1; + my $j = -1; + for (my $i=0;$i<=@$tags;$i++){ + + if ((@$tags[$i] ne $prevtag)){ + $j++ unless (@$tags[$i] eq ""); + warn "IND:".substr(@$indicator[$j],0,1).substr(@$indicator[$j],1,1)." ".@$tags[$i]; + + if (!$first){ + $xml.="\n"; + $first=1; + } + else { + if (@$values[$i] ne "") { + # leader + if (@$tags[$i] eq "000") { + $xml.="@$values[$i]\n"; + $first=1; + # rest of the fixed fields + } elsif (@$tags[$i] < 10) { + $xml.="@$values[$i]\n"; + $first=1; + } + else { + my $ind1 = substr(@$indicator[$j],0,1); + my $ind2 = substr(@$indicator[$j],1,1); + $xml.="\n"; + $xml.="@$values[$i]\n"; + $first=0; + } + } + } + } else { + if (@$values[$i] eq "") { + } + else { + if ($first){ + my $ind1 = substr(@$indicator[$j],0,1); + my $ind2 = substr(@$indicator[$j],1,1); + $xml.="\n"; + $first=0; + } + $xml.="@$values[$i]\n"; + + } + } + $prevtag = @$tags[$i]; + } + $xml.= MARC::File::XML::footer(); + warn $xml; + return $xml +} =head2 MARChtml2marc $MARCrecord = MARChtml2marc($dbh,$rtags,$rsubfields,$rvalues,%indicators); @@ -2970,6 +3035,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.158 2006/03/06 02:45:41 kados +# Adding fixes to MARC editor to HEAD +# # Revision 1.157 2006/03/01 03:07:54 kados # rollback ... by accident I committed a rel_2_2 Biblio.pm # diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index b18e97b5ed..30ce44187b 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -418,11 +418,8 @@ if ($op eq "addbiblio") { # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); - my %indicators; - for (my $i=0;$i<=$#ind_tag;$i++) { - $indicators{$ind_tag[$i]} = $indicator[$i]; - } - my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); + my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); + my $record=MARC::Record::new_from_xml($xml); # check for a duplicate my ($duplicatebiblionumber,$duplicatebibid,$duplicatetitle) = FindDuplicate($record) if ($op eq "addbiblio") && (!$is_a_modif); my $confirm_not_duplicate = $input->param('confirm_not_duplicate'); @@ -466,11 +463,8 @@ if ($op eq "addbiblio") { # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); - my %indicators; - for (my $i=0;$i<=$#ind_tag;$i++) { - $indicators{$ind_tag[$i]} = $indicator[$i]; - } - my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); + my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); + my $record=MARC::Record::new_from_xml($xml); # adding an empty field my $field = MARC::Field->new("$addedfield",'','','a'=> ""); $record->append_fields($field); diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 82eabec234..6b7350d50d 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -74,11 +74,8 @@ if ($op eq "additem") { # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); - my %indicators; - for (my $i=0;$i<=$#ind_tag;$i++) { - $indicators{$ind_tag[$i]} = $indicator[$i]; - } - my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); + my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); + my $record=MARC::Record::new_from_xml($xml); # if autoBarcode is ON, calculate barcode... if (C4::Context->preference('autoBarcode')) { my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.barcode"); @@ -124,11 +121,8 @@ if ($op eq "additem") { my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); # my $itemnumber = $input->param('itemnumber'); - my %indicators; - for (my $i=0;$i<=$#ind_tag;$i++) { - $indicators{$ind_tag[$i]} = $indicator[$i]; - } - my $itemrecord = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); + my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); + my $itemrecord=MARC::Record::new_from_xml($xml); # MARC::Record builded => now, record in DB # warn "R: ".$record->as_formatted; my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWmoditem($dbh,$record,$biblionumber,$itemnumber,0); -- 2.39.2