diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 3bece70888..6af767c5ab 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1,6 +1,20 @@ package C4::Biblio; # $Id$ # $Log$ +# Revision 1.35 2003/02/03 18:46:00 acli +# Minor factoring in C4/Biblio.pm, plus change to export the per-tag +# 'mandatory' property to a per-subfield 'tag_mandatory' template parameter, +# so that addbiblio.tmpl can distinguish between mandatory subfields in a +# mandatory tag and mandatory subfields in an optional tag +# +# Not-minor factoring in acqui.simple/addbiblio.pl to make the if-else blocks +# smaller, and to add some POD; need further testing for this +# +# Added function to check if a MARC subfield name is "koha-internal" (instead +# of checking it for 'lib' and 'tag' everywhere); temporarily added to Koha.pm +# +# Use above function in acqui.simple/additem.pl and search.marc/search.pl +# # Revision 1.34 2003/01/28 14:50:04 tipaul # fixing MARCmodbiblio API and reindenting code # @@ -376,23 +390,17 @@ used to manage MARC_word table and should not be useful elsewhere sub MARCgettagslib { my ($dbh,$forlibrarian)= @_; my $sth; - if ($forlibrarian eq 1) { - $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure order by tagfield"); - } else { - $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure order by tagfield"); - } + my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac'; + $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure order by tagfield"); $sth->execute; my ($lib,$tag,$res,$tab,$mandatory,$repeatable); - while ( ($tag,$lib,$tab) = $sth->fetchrow) { + while ( ($tag,$lib,$mandatory) = $sth->fetchrow) { $res->{$tag}->{lib}=$lib; - $res->{$tab}->{tab}=""; + $res->{$tab}->{tab}=""; # XXX + $res->{$tag}->{mandatory}=$mandatory; } - if ($forlibrarian eq 1) { - $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield"); - } else { - $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield"); - } + $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield"); $sth->execute; my $subfield; diff --git a/C4/Koha.pm b/C4/Koha.pm index cd97111a25..4cac54dfd4 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -54,6 +54,7 @@ Koha.pm provides many functions for Koha scripts. &fixEthnicity &borrowercategories ðnicitycategories + &subfield_is_koha_internal_p $DEBUG); use vars qw(); @@ -150,6 +151,17 @@ sub ethnicitycategories { return(\@codes,\%labels); } +# FIXME.. this should be moved to a MARC-specific module +sub subfield_is_koha_internal_p ($) { + my($subfield) = @_; + + # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!) + # But real MARC subfields are always single-character + # so it really is safer just to check the length + + return length $subfield != 1; +} + 1; __END__ diff --git a/acqui.simple/addbiblio.pl b/acqui.simple/addbiblio.pl index 2b2c1a0799..5d51a25145 100755 --- a/acqui.simple/addbiblio.pl +++ b/acqui.simple/addbiblio.pl @@ -26,9 +26,13 @@ use C4::Output; use C4::Interface::CGI::Output; use C4::Biblio; use C4::Context; +use C4::Koha; # XXX subfield_is_koha_internal_p use HTML::Template; use MARC::File::USMARC; +use vars qw( $tagslib ); +use vars qw( $is_a_modif ); + =item find_value @@ -86,6 +90,176 @@ sub MARCfindbreeding { } +=item build_authorized_values_list + +=cut + +sub build_authorized_values_list ($$$$$) { + my($tag, $subfield, $value, $dbh, $authorised_values_sth) = @_; + + my @authorised_values; + my %authorised_lib; + + # builds list, depending on authorised value... + + #---- branch + if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { + my $sth=$dbh->prepare("select branchcode,branchname from branches"); + $sth->execute; + push @authorised_values, "" + unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + + while (my ($branchcode,$branchname) = $sth->fetchrow_array) { + push @authorised_values, $branchcode; + $authorised_lib{$branchcode}=$branchname; + } + + #----- itemtypes + } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") { + my $sth=$dbh->prepare("select itemtype,description from itemtypes"); + $sth->execute; + push @authorised_values, "" + unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + + while (my ($itemtype,$description) = $sth->fetchrow_array) { + push @authorised_values, $itemtype; + $authorised_lib{$itemtype}=$description; + } + + #---- "true" authorised value + } else { + $authorised_values_sth->execute + ($tagslib->{$tag}->{$subfield}->{authorised_value}); + + push @authorised_values, "" + unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + + while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) { + push @authorised_values, $value; + $authorised_lib{$value}=$lib; + } + } + return CGI::scrolling_list( -name => 'field_value', + -values => \@authorised_values, + -default => $value, + -labels => \%authorised_lib, + -size => 1, + -multiple => 0 ); +} + +sub build_tabs ($$$) { + my($template, $record, $dbh) = @_; + + # fill arrays + my @loop_data =(); + my $tag; + my $i=0; + my $authorised_values_sth = $dbh->prepare("select authorised_value,lib + from authorised_values + where category=? order by authorised_value"); + + # loop through each tab 0 through 9 + for (my $tabloop = 0; $tabloop <= 9; $tabloop++) { + # my @fields = $record->fields(); + my @loop_data = (); + foreach my $tag (sort(keys (%{$tagslib}))) { + my $previous_tag = ''; + my @subfields_data; + my $indicator; + + # loop through each subfield + foreach my $subfield (sort(keys %{$tagslib->{$tag}})) { + next if subfield_is_koha_internal_p($subfield); + next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); + my %subfield_data; + $subfield_data{tag}=$tag; + $subfield_data{subfield}=$subfield; + $subfield_data{marc_lib}="