Skip to content

Commit

Permalink
road to 1.3.2 :
Browse files Browse the repository at this point in the history
* many bugfixes
* adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
  • Loading branch information
tipaul committed Nov 12, 2002
1 parent f8c08a6 commit e11872a
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 115 deletions.
59 changes: 41 additions & 18 deletions C4/Biblio.pm
@@ -1,6 +1,11 @@
package C4::Biblio;
# $Id$
# $Log$
# Revision 1.26 2002/11/12 15:58:43 tipaul
# road to 1.3.2 :
# * many bugfixes
# * adding value_builder : you can map a subfield in the marc_subfield_structure to a sub stored in "value_builder" directory. In this directory you can create screen used to build values with any method. In this commit is a 1st draft of the builder for 100$a unimarc french subfield, which is composed of 35 digits, with 12 differents values (only the 4th first are provided for instance)
#
# Revision 1.25 2002/10/25 10:58:26 tipaul
# Road to 1.3.2
# * bugfixes and improvements
Expand Down Expand Up @@ -355,20 +360,24 @@ sub MARCgettagslib {
}

if ($forlibrarian eq 1) {
$sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value from marc_subfield_structure");
$sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure");
} else {
$sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value from marc_subfield_structure");
$sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure");
}
$sth->execute;

my $subfield;
my $authorised_value;
while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value) = $sth->fetchrow) {
my $thesaurus_category;
my $value_builder;
while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder) = $sth->fetchrow) {
$res->{$tag}->{$subfield}->{lib}=$lib;
$res->{$tag}->{$subfield}->{tab}=$tab;
$res->{$tag}->{$subfield}->{mandatory}=$mandatory;
$res->{$tag}->{$subfield}->{repeatable}=$repeatable;
$res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
$res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
$res->{$tag}->{$subfield}->{value_builder}=$value_builder;
}
return $res;
}
Expand Down Expand Up @@ -461,7 +470,7 @@ sub MARCadditem {

sub MARCaddsubfield {
# Add a new subfield to a tag into the DB.
my ($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
my ($dbh,$bibid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
# if not value, end of job, we do nothing
if (not($subfieldvalue)) {
return;
Expand All @@ -476,21 +485,21 @@ sub MARCaddsubfield {
$sth=$dbh->prepare("select max(blobidlink)from marc_blob_subfield");
$sth->execute;
my ($res)=$sth->fetchrow;
$sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?)");
$sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,valuebloblink) values (?,?,?,?,?,?,?)");
if ($tagid<100) {
$sth->execute($bibid,'0'.$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
$sth->execute($bibid,'0'.$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
} else {
$sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$res);
$sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$res);
}
if ($sth->errstr) {
print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
}
# $dbh->do("unlock tables");
} else {
my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?)");
$sth->execute($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
my $sth=$dbh->prepare("insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
$sth->execute($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
if ($sth->errstr) {
print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
print STDERR "ERROR ==> insert into marc_subfield_table (bibid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($bibid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
}
}
&MARCaddword($dbh,$bibid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
Expand All @@ -509,6 +518,7 @@ sub MARCgetbiblio {
$sth->execute($bibid);
my $prevtagorder=1;
my $prevtag;
my $previndicator;
my %subfieldlist={};
while (my $row=$sth->fetchrow_hashref) {
if ($row->{'valuebloblink'}) { #---- search blob if there is one
Expand All @@ -517,16 +527,24 @@ sub MARCgetbiblio {
$sth2->finish;
$row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
}
# warn "$row->{bibid} = $row->{tag} - $row->{subfieldcode}";
if ($row->{tagorder} ne $prevtagorder) {
my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
if (length($prevtag) <3) {
$prevtag = "0".$prevtag;
}
$previndicator.=" ";
my $field = MARC::Field->new( $prevtag, substr($previndicator,0,1), substr($previndicator,1,1), %subfieldlist);
# warn $field->as_formatted();
$record->add_fields($field);
$prevtagorder=$row->{tagorder};
$prevtag = $row->{tag};
$previndicator=$row->{tag};
%subfieldlist={};
%subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
} else {
%subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
$prevtag= $row->{tag};
$previndicator=$row->{indicator};
}
}
# the last has not been included inside the loop... do it now !
Expand Down Expand Up @@ -841,14 +859,18 @@ sub MARCkoha2marcOnefield {
}

sub MARChtml2marc {
my ($dbh,$rtags,$rsubfields,$rvalues) = @_;
my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
my $prevtag = @$rtags[0];
my $record = MARC::Record->new();
my %subfieldlist={};
for (my $i=0; $i<= @$rtags; $i++) {
# rebuild MARC::Record
if (@$rtags[$i] ne $prevtag) {
my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
if ($prevtag<10) {
$prevtag='0'.10;
}
$indicators{$prevtag}.=' ';
my $field = MARC::Field->new( $prevtag, substr($indicators{$prevtag},0,1),substr($indicators{$prevtag},1,1), %subfieldlist);
$record->add_fields($field);
$prevtag = @$rtags[$i];
%subfieldlist={};
Expand Down Expand Up @@ -991,8 +1013,8 @@ sub NEWnewbiblio {
$sth->execute("biblioitems.biblioitemnumber");
(my $tagfield2, my $tagsubfield2) = $sth->fetchrow;
if ($tagsubfield1 != $tagsubfield2) {
print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
print "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same subfield number";
print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same subfield number";
die;
}
my $newfield = MARC::Field->new( $tagfield1,'','',
Expand All @@ -1008,6 +1030,7 @@ sub NEWnewbiblio {

sub NEWnewitem {
my ($dbh, $record,$bibid) = @_;
warn "add item : ".$record->as_formatted();
# add item in old-DB
my $item = &MARCmarc2koha($dbh,$record);
# needs old biblionumber and biblioitemnumber
Expand Down Expand Up @@ -1408,7 +1431,7 @@ sub OLDnewitems {
# foreach my $barcode (@barcodes) {
# $barcode = uc($barcode);
$barcode = $dbh->quote($barcode);
$sth->prepare("Insert into items set
$sth=$dbh->prepare("Insert into items set
itemnumber = ?, biblionumber = ?,
biblioitemnumber = ?, barcode = ?,
booksellerid = ?, dateaccessioned = NOW(),
Expand All @@ -1422,7 +1445,7 @@ sub OLDnewitems {
$item->{'booksellerid'},
$item->{'homebranch'},$item->{'homebranch'},
$item->{'price'},$item->{'replacementprice'},
NOW(),$item->{'itemnotes'},$item->{'loan'});
$item->{'itemnotes'},$item->{'loan'});

$sth->execute;
if (defined $sth->errstr) {
Expand Down
1 change: 1 addition & 0 deletions MARCdetail.pl
Expand Up @@ -59,6 +59,7 @@ =head1 FUNCTIONS
my $tagslib = &MARCgettagslib($dbh,1);

my $record =MARCgetbiblio($dbh,$bibid);
warn $record->as_formatted();
# open template
my $template = gettemplate("catalogue/MARCdetail.tmpl",0);
# fill arrays
Expand Down
91 changes: 70 additions & 21 deletions acqui.simple/addbiblio.pl
Expand Up @@ -35,16 +35,19 @@
use MARC::File::USMARC;

sub find_value {
my ($tagfield,$subfield,$record) = @_;
my ($tagfield,$insubfield,$record) = @_;
my $result;
my $indicator;
foreach my $field ($record->field($tagfield)) {
my @subfields = $field->subfields();
foreach my $subfield (@subfields) {
if (@$subfield[0] eq $subfield) {
if (@$subfield[0] eq $insubfield) {
$result .= @$subfield[1];
$indicator = $field->indicator(1).$field->indicator(2);
}
}
}
return($indicator,$result);
}

sub MARCfindbreeding {
Expand All @@ -55,13 +58,12 @@ sub MARCfindbreeding {
if ($marc) {
my $record = MARC::File::USMARC::decode($marc);
if (ref($record) eq undef) {
warn "not a MARC record !";
warn "not a MARC record : $marc";
return -1;
} else {
return $record;
}
}
warn "not MARC";
return -1;

}
Expand All @@ -88,12 +90,21 @@ sub MARCfindbreeding {
if ($op eq "addbiblio") {
#------------------------------------------------------------------------------------------------------------------------------
# rebuild
my @tags = $input->param('tag[]');
my @subfields = $input->param('subfield[]');
my @values = $input->param('value[]');
my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
my @tags = $input->param('tag');
my @subfields = $input->param('subfield');
my @values = $input->param('field_value');
# 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);
# warn "record ".$record->as_formatted();
# MARC::Record builded => now, record in DB
my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record);
my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
# build item screen. There is no item for instance.
my @loop_data =();
my $i=0;
Expand All @@ -111,7 +122,23 @@ sub MARCfindbreeding {
$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
$subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
$subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
$authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
my @authorised_values;
push @authorised_values, "" unless ($subfield_data{mandatory});
while ((my $value) = $authorised_values_sth->fetchrow_array) {
push @authorised_values, $value;
}
$subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
-values=> \@authorised_values,
-size=>1,
-multiple=>0,
);
} elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
} else {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
}
push(@loop_data, \%subfield_data);
}
}
Expand All @@ -121,10 +148,19 @@ sub MARCfindbreeding {
#------------------------------------------------------------------------------------------------------------------------------
} elsif ($op eq "additem") {
#------------------------------------------------------------------------------------------------------------------------------
my @tags = $input->param('tag[]');
my @subfields = $input->param('subfield[]');
my @values = $input->param('value[]');
my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
my @tags = $input->param('tag');
my @subfields = $input->param('subfield');
my @values = $input->param('field_value');
# 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 %indicators;
$indicators{995}=' ';
warn "REs : $tags[0] - $tags[1] - $subfields[0] - $subfields[1] - $values[0] - $values[1]";
my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values,%indicators);
my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
# now, build existiing item list
my $temp = MARCgetbiblio($dbh,$bibid);
Expand Down Expand Up @@ -203,17 +239,17 @@ sub MARCfindbreeding {
my $tag;
my $i=0;
my $authorised_values_sth = $dbh->prepare("select authorised_value from authorised_values where category=?");
# loop through each tab 0 through 9
# loop through each tab 0 through 9
for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
# loop through each tag
# my @fields = $record->fields();
my @loop_data =();
foreach my $tag (keys %{$tagslib}) {
my $previous_tag = '';
my @subfields_data;
# loop through each subfield
my $indicator;
# loop through each subfield
foreach my $subfield (keys %{$tagslib->{$tag}}) {
next if ($subfield eq 'lib');
next if ($subfield eq 'lib'); # skip lib and tabs, which are koha internal
next if ($subfield eq 'tab');
next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
my %subfield_data;
Expand All @@ -222,8 +258,10 @@ sub MARCfindbreeding {
$subfield_data{marc_lib}="<DIV id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</div>";
$subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
$subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
# if breeding is not empty
if ($record ne -1) {
my $value = find_value($tag,$subfield,$record);
my ($x,$value) = find_value($tag,$subfield,$record);
$indicator = $x if $x;
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
$authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
my @authorised_values;
Expand All @@ -237,9 +275,14 @@ sub MARCfindbreeding {
-size=>1,
-multiple=>0,
);
} elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
} elsif ($tagslib->{$tag}->{$subfield}->{value_builder}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../value_builder/$tagslib->{$tag}->{$subfield}->{value_builder}?index=$i',$i)\">...</a>";
} else {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\">";
}
# if breeding is empty
} else {
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
$authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
Expand All @@ -253,6 +296,10 @@ sub MARCfindbreeding {
-size=>1,
-multiple=>0,
);
} elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">...</a>";
} elsif ($tagslib->{$tag}->{$subfield}->{value_builder}) {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" DISABLE READONLY> <a href=\"javascript:Dopop('../value_builder/$tagslib->{$tag}->{$subfield}->{value_builder}?index=$i',$i)\">...</a>";
} else {
$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
}
Expand All @@ -262,8 +309,10 @@ sub MARCfindbreeding {
}
if ($#subfields_data>=0) {
my %tag_data;
$tag_data{tag}=$tag.' -'. $tagslib->{$tag}->{lib};
$tag_data{subfield} = \@subfields_data;
$tag_data{tag}=$tag;
$tag_data{tag_lib} = $tagslib->{$tag}->{lib};
$tag_data{indicator} = $indicator;
$tag_data{subfield_loop} = \@subfields_data;
push (@loop_data, \%tag_data);
}
}
Expand All @@ -283,7 +332,7 @@ sub MARCfindbreeding {
$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
$subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
$subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
$subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value\">";
$subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
push(@loop_data, \%subfield_data);
$i++
}
Expand Down

0 comments on commit e11872a

Please sign in to comment.