[Koha-cvs] koha acqui.simpleaddbiblio.pl C4/Biblio.pm koha... [rel_2_2]
paul poulain
paul at koha-fr.org
Mon Jun 12 12:33:54 CEST 2006
CVSROOT: /cvsroot/koha
Module name: koha
Branch: rel_2_2
Changes by: paul poulain <tipaul> 06/06/12 10:33:54
Modified files:
acqui.simple : addbiblio.pl
C4 : Biblio.pm
koha-tmpl/intranet-tmpl/default/en/acqui.simple: addbiblio.tmpl
Log message:
[IMPORTANT]
when cloning a tag, there was a problem to detect the tag change when rebuilding the XML/MARC record :
the test was done on an empty field.
with the new CloneTag sub, this empty field was quite tricky to create on the fly.
so i've added on each subfield a <input name="firstsubfield"> saying wether the subfield is the 1st or not.
Thus, when a tag is cloned, it is cloned properly.
HTML2marc and well as HTML2xml have been modified, but PLEASE DOUBLE CHECK my work
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/acqui.simple/addbiblio.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.52.2.43&r2=1.52.2.44
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Biblio.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.115.2.54&r2=1.115.2.55
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.33.2.24&r2=1.33.2.25
Patches:
Index: acqui.simple/addbiblio.pl
===================================================================
RCS file: /cvsroot/koha/koha/acqui.simple/Attic/addbiblio.pl,v
retrieving revision 1.52.2.43
retrieving revision 1.52.2.44
diff -u -b -r1.52.2.43 -r1.52.2.44
--- acqui.simple/addbiblio.pl 9 Jun 2006 15:58:09 -0000 1.52.2.43
+++ acqui.simple/addbiblio.pl 12 Jun 2006 10:33:53 -0000 1.52.2.44
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# $Id: addbiblio.pl,v 1.52.2.43 2006/06/09 15:58:09 tipaul Exp $
+# $Id: addbiblio.pl,v 1.52.2.44 2006/06/12 10:33:53 tipaul Exp $
# Copyright 2000-2002 Katipo Communications
#
@@ -202,7 +202,7 @@
builds the <input ...> entry for a subfield.
=cut
sub create_input () {
- my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_;
+ my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth,$firstsubfield) = @_;
# must be encoded as utf-8 before it reaches the editor
#use Encode;
#$value = encode('utf-8', $value);
@@ -218,6 +218,7 @@
$subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield};
$subfield_data{index} = $i;
+ $subfield_data{firstsubfield} = $firstsubfield;
$subfield_data{visibility} = "display:none" unless (($tagslib->{$tag}->{$subfield}->{hidden}%2==0) or $value ne ''); #check parity
# it's an authorised field
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
@@ -271,6 +272,7 @@
# loop through each tab 0 through 9
for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
my @loop_data = ();
+# loop through each tag
foreach my $tag (sort(keys (%{$tagslib}))) {
my $indicator;
# if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
@@ -295,7 +297,7 @@
}
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
next if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'biblio.biblionumber');
- push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
+ push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth,$#subfields_data>=0?0:1));
$i++;
} else {
my @subfields=$field->subfields();
@@ -304,7 +306,7 @@
my $value=$subfields[$subfieldcount][1];
next if (length $subfield !=1);
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
- push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
+ push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth),$#subfields_data>=0?0:1);
$i++;
}
}
@@ -315,7 +317,7 @@
next if ($tag<10);
next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-4) or ($tagslib->{$tag}->{$subfield}->{hidden}>=5) ); #check for visibility flag
next if (defined($field->subfield($subfield)));
- push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
+ push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth,$#subfields_data>0?0:1));
$i++;
}
if ($#subfields_data >= 0) {
@@ -335,7 +337,7 @@
if ($#fields >=1 && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
my @subfields_data;
my %tag_data;
- push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth));
+ push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth),$#subfields_data>=0?0:1);
$tag_data{tag} = '';
$tag_data{tag_lib} = '';
$tag_data{indicator} = '';
@@ -354,7 +356,7 @@
next if (length $subfield !=1);
next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-5) or ($tagslib->{$tag}->{$subfield}->{hidden}>=4) ); #check for visibility flag
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
- push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
+ push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth,$#subfields_data>=0?0:1));
$i++;
}
if ($#subfields_data >= 0) {
@@ -493,14 +495,15 @@
my @tags = $input->param('tag');
my @subfields = $input->param('subfield');
my @values = $input->param('field_value');
- use Data::Dumper;
- warn "DUMP : ".Dumper(@values);
# build indicator hash.
my @ind_tag = $input->param('ind_tag');
my @indicator = $input->param('indicator');
+ my @firstsubfields = $input->param('firstsubfield');
+ use Data::Dumper;
+ warn "DUMP PL : ".Dumper(@tags);
my $record;
if (C4::Context->preference('TemplateEncoding') eq "iso-8859-1") {
- $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
+ $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,\@firstsubfields,\@indicator,\@ind_tag);
} else {
my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
$record=MARC::Record->new_from_xml($xml,C4::Context->preference('TemplateEncoding'),C4::Context->preference('marcflavour'));
Index: C4/Biblio.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Biblio.pm,v
retrieving revision 1.115.2.54
retrieving revision 1.115.2.55
diff -u -b -r1.115.2.54 -r1.115.2.55
--- C4/Biblio.pm 2 Jun 2006 15:36:18 -0000 1.115.2.54
+++ C4/Biblio.pm 12 Jun 2006 10:33:54 -0000 1.115.2.55
@@ -26,7 +26,7 @@
use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.115.2.54 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.115.2.55 $' =~ /\d+/g;
shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
@ISA = qw(Exporter);
@@ -1041,7 +1041,7 @@
return $record;
}
sub MARChtml2xml {
- my ($tags,$subfields,$values,$indicator,$ind_tag) = @_;
+ my ($tags,$subfields,$values,$firstsubfields,$indicator,$ind_tag) = @_;
use MARC::File::XML;
my $xml= MARC::File::XML::header(C4::Context->preference('TemplateEncoding'),C4::Context->preference('marcflavour'));
#$xml =~ s/UTF-8/ISO-8859-1/;
@@ -1056,7 +1056,7 @@
@$values[$i] =~ s/>/>/g;
@$values[$i] =~ s/"/"/g;
@$values[$i] =~ s/'/'/g;
- if ((@$tags[$i] ne $prevtag)){
+ if (@$firstsubfields[$i]){
$j++ unless (@$tags[$i] eq "");
#warn "IND:".substr(@$indicator[$j],0,1).substr(@$indicator[$j],1,1)." ".@$tags[$i];
if (!$first){
@@ -1108,17 +1108,25 @@
#warn $xml;
return $xml;
}
+
sub MARChtml2marc {
- my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
+ my ($dbh,$rtags,$rsubfields,$rvalues,$rfirstsubfields,%indicators) = @_;
+# rtag : a reference to the list of tags (same for every subfield of a given tag
+# rsubfields : a reference to the list of subfield codes
+# rvalues : a reference to the list of subfield values
+# rfirstsubfields : a reference to a list, each entry containing 0 or 1. 0 means that the corresponding subfield it NOT the 1st of the tag, 1 meaning it is.
+# this last list is useful to detect a new repeated tag.
+
my $prevtag = -1;
my $record = MARC::Record->new();
# my %subfieldlist=();
my $prevvalue; # if tag <10
my $field; # if tag >=10
+ # parses each entry of the list
for (my $i=0; $i< @$rtags; $i++) {
- # rebuild MARC::Record
-# warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
- if (@$rtags[$i] ne $prevtag) {
+ # if it is the 1st subfield of a field, save the previous field
+ if (@$rfirstsubfields[$i]) {
+ # if it is <10, just create the value
if ($prevtag < 10) {
if ($prevvalue) {
if (($prevtag ne '000') && ($prevvalue ne "")) {
@@ -1127,11 +1135,13 @@
$record->leader($prevvalue);
}
}
+ # if it is >=10, create the complete MARC field
} else {
if (($field) && ($field ne "")) {
$record->add_fields($field);
}
}
+ # now undefine the previous field to create a new blank one.
$indicators{@$rtags[$i]}.=' ';
# skip blank tags, I hope this works
if (@$rtags[$i] eq ''){
@@ -1152,7 +1162,7 @@
# warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
}
$prevtag = @$rtags[$i];
- } else {
+ } else { # it is not the 1st subfield, store the value or append the subfield
if (@$rtags[$i] <10) {
$prevvalue=@$rvalues[$i];
} else {
@@ -1170,10 +1180,7 @@
}
#}
# the last has not been included inside the loop... do it now !
- #use Data::Dumper;
- #warn Dumper($field->{_subfields});
$record->add_fields($field) if (($field) && $field ne "");
- #warn "HTML2MARC=".$record->as_formatted;
return $record;
}
@@ -2838,6 +2845,7 @@
sub DisplayISBN {
my ($isbn)=@_;
+ return "" unless $isbn;
my $seg1;
if(substr($isbn, 0, 1) <=7) {
$seg1 = substr($isbn, 0, 1);
@@ -3008,8 +3016,19 @@
=cut
-# $Id: Biblio.pm,v 1.115.2.54 2006/06/02 15:36:18 tipaul Exp $
+# $Id: Biblio.pm,v 1.115.2.55 2006/06/12 10:33:54 tipaul Exp $
# $Log: Biblio.pm,v $
+# Revision 1.115.2.55 2006/06/12 10:33:54 tipaul
+# [IMPORTANT]
+#
+# when cloning a tag, there was a problem to detect the tag change when rebuilding the XML/MARC record :
+# the test was done on an empty field.
+# with the new CloneTag sub, this empty field was quite tricky to create on the fly.
+# so i've added on each subfield a <input name="firstsubfield"> saying wether the subfield is the 1st or not.
+# Thus, when a tag is cloned, it is cloned properly.
+#
+# HTML2marc and well as HTML2xml have been modified, but PLEASE DOUBLE CHECK my work
+#
# Revision 1.115.2.54 2006/06/02 15:36:18 tipaul
# - fixing a small bug in html2marc, when the 1st subfield of a field was empty, the 2nd could not be filled as the MARC::Field had not been created.
#
Index: koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl
===================================================================
RCS file: /cvsroot/koha/koha/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl,v
retrieving revision 1.33.2.24
retrieving revision 1.33.2.25
diff -u -b -r1.33.2.24 -r1.33.2.25
--- koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl 9 Jun 2006 16:01:46 -0000 1.33.2.24
+++ koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl 12 Jun 2006 10:33:54 -0000 1.33.2.25
@@ -87,7 +87,7 @@
<a style="cursor: crosshair; color: grey; font-size: 80%;" onclick="cloneSubfield('subfield<!-- TMPL_VAR NAME="tag" --><!-- TMPL_VAR name="index" -->')">+</a>
<!-- /TMPL_IF -->
<input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->"/>
- <input type="hidden" name="subfieldYYY" value="<!-- TMPL_VAR NAME="subfield" -->" size="2" maxlength="1"/>
+ <input type="hidden" name="firstsubfield" value="<!-- TMPL_VAR NAME="firstsubfield" -->" size="2" maxlength="1"/>
<input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->"/>
<input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->"/>
<input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->"/>
@@ -289,9 +289,7 @@
function openAuth(tagid,authtype,X) {
// defaultid=document.getElementById(subfieldid);
-// alert("X"+X);
Y=X.parentNode.getAttribute("id");
-// alert("tagid"+Y);
newin=window.open("../authorities/auth_finder.pl?authtypecode="+ authtype+ "&tagid="+Y, "value builder",'width=550,height=550,toolbar=false,scrollbars=yes');
}
@@ -299,10 +297,9 @@
function cloneTag(index) {
var original = document.getElementById(index);
var clone = original.cloneNode(true);
- clone.setAttribute("id", index + index);
// OK, now rename the id of the
+ clone.setAttribute("id", index + index);
original.parentNode.insertBefore( clone, original.nextSibling);
-
}
function cloneSubfield(index) {
More information about the Koha-cvs
mailing list