&NEWmodbiblioframework
&MARCkoha2marcBiblio &MARCmarc2koha
- &MARCkoha2marcItem &MARChtml2marc
+ &MARCkoha2marcItem &MARChtml2marc &MARChtml2xml
&MARCgetbiblio &MARCgetitem
&XMLgetbiblio
}
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.="</datafield>\n";
+ $first=1;
+ }
+ else {
+ if (@$values[$i] ne "") {
+ # leader
+ if (@$tags[$i] eq "000") {
+ $xml.="<leader>@$values[$i]</leader>\n";
+ $first=1;
+ # rest of the fixed fields
+ } elsif (@$tags[$i] < 10) {
+ $xml.="<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
+ $first=1;
+ }
+ else {
+ my $ind1 = substr(@$indicator[$j],0,1);
+ my $ind2 = substr(@$indicator[$j],1,1);
+ $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\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.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $first=0;
+ }
+ $xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+
+ }
+ }
+ $prevtag = @$tags[$i];
+ }
+ $xml.= MARC::File::XML::footer();
+ warn $xml;
+ return $xml
+}
=head2 MARChtml2marc
$MARCrecord = MARChtml2marc($dbh,$rtags,$rsubfields,$rvalues,%indicators);
# $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
#
# 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');
# 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);
# 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");
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);