From 5f4179a6c3d055fb3b8a4582cb9caaa114c1203a Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 3 Jun 2004 09:59:36 +0000 Subject: [PATCH] * frameworks and itemtypes are independant * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable --- C4/Biblio.pm | 74 +++++++++++++++++---------------------- C4/Koha.pm | 67 +++++++++++++++++++++++++++++++++++ acqui.simple/addbiblio.pl | 28 +++++++++------ acqui.simple/addbooks.pl | 16 ++++----- acqui.simple/additem.pl | 2 +- opac/opac-ISBDdetail.pl | 2 +- opac/opac-MARCdetail.pl | 2 +- 7 files changed, 128 insertions(+), 63 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index be06332de2..415e23198d 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -50,7 +50,7 @@ $VERSION = 0.01; &MARCfind_MARCbibid_from_oldbiblionumber &MARCfind_marc_from_kohafield &MARCfindsubfield - &MARCfind_itemtype + &MARCfind_frameworkcode &MARCgettagslib &NEWnewbiblio &NEWnewitem @@ -221,26 +221,27 @@ used to manage MARC_word table and should not be useful elsewhere =cut sub MARCgettagslib { - my ($dbh,$forlibrarian,$itemtype)= @_; - $itemtype="" unless $itemtype; + my ($dbh,$forlibrarian,$frameworkcode)= @_; + $frameworkcode="" unless $frameworkcode; my $sth; my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac'; - # check that itemtype framework exists - $sth=$dbh->prepare("select count(*) from marc_tag_structure where itemtype=? order by ?"); - $sth->execute($itemtype,$itemtype); + # check that framework exists + $sth=$dbh->prepare("select count(*) from marc_tag_structure where frameworkcode=?"); + $sth->execute($frameworkcode); my ($total) = $sth->fetchrow; - $itemtype="" unless ($total >0); - $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure where itemtype=? order by tagfield"); - $sth->execute($itemtype); + $frameworkcode="" unless ($total >0); + $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"); + $sth->execute($frameworkcode); my ($lib,$tag,$res,$tab,$mandatory,$repeatable); - while ( ($tag,$lib,$mandatory) = $sth->fetchrow) { + while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) { $res->{$tag}->{lib}=$lib; $res->{$tab}->{tab}=""; # XXX $res->{$tag}->{mandatory}=$mandatory; + $res->{$tag}->{repeatable}=$repeatable; } - $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where itemtype=? order by tagfield,tagsubfield"); - $sth->execute($itemtype); + $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"); + $sth->execute($frameworkcode); my $subfield; my $authorised_value; @@ -293,7 +294,7 @@ sub MARCfind_MARCbibid_from_oldbiblionumber { sub MARCaddbiblio { # pass the MARC::Record to this function, and it will create the records in the marc tables - my ($dbh,$record,$biblionumber,$bibid) = @_; + my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_; my @fields=$record->fields(); # warn "IN MARCaddbiblio $bibid => ".$record->as_formatted; # my $bibid; @@ -302,8 +303,8 @@ sub MARCaddbiblio { # if bibid empty => true add, find a new bibid number unless ($bibid) { $dbh->do("lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"); - my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber) values (now(),?)"); - $sth->execute($biblionumber); + my $sth=$dbh->prepare("insert into marc_biblio (datecreated,biblionumber,frameworkcode) values (now(),?,?)"); + $sth->execute($biblionumber,$frameworkcode); $sth=$dbh->prepare("select max(bibid) from marc_biblio"); $sth->execute; ($bibid)=$sth->fetchrow; @@ -703,13 +704,12 @@ sub MARCfindsubfieldid { return $res; } -sub MARCfind_itemtype { +sub MARCfind_frameworkcode { my ($dbh,$bibid) = @_; - my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.itemtype"); - my $sth = $dbh->prepare("select subfieldvalue from marc_subfield_table where bibid=? and tag=? and subfieldcode=?"); - $sth->execute($bibid,$tagfield,$tagsubfield); - my ($subfieldvalue) = $sth->fetchrow; - return $subfieldvalue; + my $sth = $dbh->prepare("select frameworkcode from marc_biblio where bibid=?"); + $sth->execute($bibid); + my ($frameworkcode) = $sth->fetchrow; + return $frameworkcode; } sub MARCdelsubfield { # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder @@ -989,26 +989,13 @@ adds an item in the db. =cut sub NEWnewbiblio { - my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_; - # note $oldbiblio and $oldbiblioitem are not mandatory. - # if not present, they will be builded from $record with MARCmarc2koha function - if (($oldbiblio) and not($oldbiblioitem)) { - print STDERR "NEWnewbiblio : missing parameter\n"; - print "NEWnewbiblio : missing parameter : contact koha development team\n"; - die; - } + my ($dbh, $record, $frameworkcode) = @_; my $oldbibnum; my $oldbibitemnum; - if ($oldbiblio) { - $oldbibnum = OLDnewbiblio($dbh,$oldbiblio); - $oldbiblioitem->{'biblionumber'} = $oldbibnum; - $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem); - } else { - my $olddata = MARCmarc2koha($dbh,$record); - $oldbibnum = OLDnewbiblio($dbh,$olddata); - $olddata->{'biblionumber'} = $oldbibnum; - $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata); - } + my $olddata = MARCmarc2koha($dbh,$record); + $oldbibnum = OLDnewbiblio($dbh,$olddata); + $olddata->{'biblionumber'} = $oldbibnum; + $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata); # search subtiles, addiauthors and subjects my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author"); my @addiauthfields = $record->field($tagfield); @@ -1059,12 +1046,13 @@ sub NEWnewbiblio { my $old_field = $record->field($tagfield1); $record->delete_field($old_field); $record->add_fields($newfield); - my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum); + my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum,$frameworkcode); return ($bibid,$oldbibnum,$oldbibitemnum ); } sub NEWmodbiblio { - my ($dbh,$record,$bibid) =@_; + my ($dbh,$record,$bibid,$frameworkcode) =@_; + $frameworkcode="" unless $frameworkcode; &MARCmodbiblio($dbh,$bibid,$record,0); my $oldbiblio = MARCmarc2koha($dbh,$record); my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio); @@ -2203,6 +2191,10 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.91 2004/06/03 10:03:01 tipaul +# * frameworks and itemtypes are independant +# * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable +# # Revision 1.90 2004/05/28 08:25:53 tipaul # hidding hidden & isurl constraints into MARC subfield structure # diff --git a/C4/Koha.pm b/C4/Koha.pm index b8cf506b72..e6da0640a0 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -58,6 +58,7 @@ Koha.pm provides many functions for Koha scripts. &getbranches &getbranch &getprinters &getprinter &getitemtypes &getitemtypeinfo + &getframeworks &getframeworkinfo &getauthtypes $DEBUG); @@ -321,6 +322,72 @@ sub getauthtypes { return (\%authtypes); } +=head2 getframework + + $frameworks = &getframework(); + +Returns information about existing frameworks + +build a HTML select with the following code : + +=head3 in PERL SCRIPT + +my $frameworks = frameworks(); +my @frameworkloop; +foreach my $thisframework (keys %$frameworks) { + my $selected = 1 if $thisframework eq $frameworkcode; + my %row =(value => $thisframework, + selected => $selected, + description => $frameworks->{$thisframework}->{'frameworktext'}, + ); + push @frameworksloop, \%row; +} +$template->param(frameworkloop => \@frameworksloop); + +=head3 in TEMPLATE + +
+ + "> + +
+ + +=cut + +sub getframeworks { +# returns a reference to a hash of references to branches... + my %itemtypes; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from biblio_framework"); + $sth->execute; + while (my $IT=$sth->fetchrow_hashref) { + $itemtypes{$IT->{'frameworkcode'}}=$IT; + } + return (\%itemtypes); +} +=head2 getframeworkinfo + + $frameworkinfo = &getframeworkinfo($frameworkcode); + +Returns information about an frameworkcode. + +=cut + +sub getframeworkinfo { + my ($frameworkcode) = @_; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?"); + $sth->execute($frameworkcode); + my $res = $sth->fetchrow_hashref; + return $res; +} + =head2 getitemtypeinfo diff --git a/acqui.simple/addbiblio.pl b/acqui.simple/addbiblio.pl index 105b26b0a3..f81d679f14 100755 --- a/acqui.simple/addbiblio.pl +++ b/acqui.simple/addbiblio.pl @@ -165,7 +165,7 @@ sub create_input () { my %subfield_data; $subfield_data{tag}=$tag; $subfield_data{subfield}=$subfield; - $subfield_data{marc_lib}="
".$tagslib->{$tag}->{$subfield}->{lib}."
"; + $subfield_data{marc_lib}="".$tagslib->{$tag}->{$subfield}->{lib}.""; $subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory}; $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; @@ -240,6 +240,7 @@ sub build_tabs ($$$$) { my %tag_data; $tag_data{tag} = $tag; $tag_data{tag_lib} = $tagslib->{$tag}->{lib}; + $tag_data{repeatable} = $tagslib->{$tag}->{repeatable}; $tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10); $tag_data{subfield_loop} = \@subfields_data; push (@loop_data, \%tag_data); @@ -295,6 +296,7 @@ sub build_hidden_data () { next if ($subfield eq 'lib'); next if ($subfield eq 'tab'); next if ($subfield eq 'mandatory'); + next if ($subfield eq 'repeatable'); next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "-1"); my %subfield_data; $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; @@ -307,22 +309,26 @@ sub build_hidden_data () { } } + +# ======================== +# MAIN +#========================= my $input = new CGI; my $error = $input->param('error'); my $oldbiblionumber=$input->param('oldbiblionumber'); # if bib exists, it's a modif, not a new biblio. my $breedingid = $input->param('breedingid'); my $z3950 = $input->param('z3950'); my $op = $input->param('op'); -$itemtype = $input->param('itemtype'); +my $frameworkcode = $input->param('frameworkcode'); my $dbh = C4::Context->dbh; my $bibid; if ($oldbiblionumber) { $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber); - # find itemtype - $itemtype = &MARCfind_itemtype($dbh,$bibid) if $bibid; + # find framework type + $frameworkcode = &MARCfind_frameworkcode($dbh,$bibid) if $bibid; }else { $bibid = $input->param('bibid'); - $itemtype = &MARCfind_itemtype($dbh,$bibid) if $bibid; + $frameworkcode = &MARCfind_frameworkcode($dbh,$bibid) if $bibid; } my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui.simple/addbiblio.tmpl", @@ -333,7 +339,7 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -$tagslib = &MARCgettagslib($dbh,1,$itemtype); +$tagslib = &MARCgettagslib($dbh,1,$frameworkcode); my $record=-1; my $encoding=""; $record = MARCgetbiblio($dbh,$bibid) if ($bibid); @@ -372,13 +378,12 @@ if ($op eq "addbiblio") { my $oldbibnum; my $oldbibitemnum; if ($is_a_modif) { - NEWmodbiblio($dbh,$record,$bibid); + NEWmodbiblio($dbh,$record,$bibid,$frameworkcode); } else { - ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record); + ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record,$frameworkcode); } # now, redirect to additem page - print $input->redirect("additem.pl?bibid=$bibid&itemtype=$itemtype"); - warn "redirect : $itemtype"; + print $input->redirect("additem.pl?bibid=$bibid&frameworkcode=$frameworkcode"); exit; #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "addfield") { @@ -456,6 +461,7 @@ if ($op eq "addbiblio") { oldbiblioitemnumber => $oldbiblioitemnumber ); } $template->param( - itemtype => $itemtype + frameworkcode => $frameworkcode, + itemtype => $frameworkcode # HINT: if the library has itemtype = framework, itemtype is auto filled ! ); output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index b5ed428461..52834fc535 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -57,18 +57,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -# get itemtype list -my $itemtypes = getitemtypes; -my @itemtypesloop; -foreach my $thisitemtype (keys %$itemtypes) { - my %row =(value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'description'}, +# get framework list +my $frameworks = getframeworks; +my @frameworkcodeloop; +foreach my $thisframeworkcode (keys %$frameworks) { + my %row =(value => $thisframeworkcode, + frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, ); - push @itemtypesloop, \%row; + push @frameworkcodeloop, \%row; } my $marc_p = C4::Context->boolean_preference("marc"); $template->param( NOTMARC => !$marc_p, - itemtypeloop => \@itemtypesloop ); + frameworkcodeloop => \@frameworkcodeloop ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/acqui.simple/additem.pl b/acqui.simple/additem.pl index 807e1c568d..35ce8afb6a 100755 --- a/acqui.simple/additem.pl +++ b/acqui.simple/additem.pl @@ -56,7 +56,7 @@ my $op = $input->param('op'); my $itemnum = $input->param('itemnum'); # find itemtype -my $itemtype = &MARCfind_itemtype($dbh,$bibid); +my $itemtype = &MARCfind_frameworkcode($dbh,$bibid); my $tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record = MARCgetbiblio($dbh,$bibid); diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 4bea4e6224..ebca9cd8a2 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -66,7 +66,7 @@ my $biblionumber=$query->param('bib'); my $bibid = $query->param('bibid'); $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber) unless $bibid; $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid) unless $biblionumber; -my $itemtype = &MARCfind_itemtype($dbh,$bibid); +my $itemtype = &MARCfind_frameworkcode($dbh,$bibid); my $tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record =MARCgetbiblio($dbh,$bibid); diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 49b29f03b1..8154ce3c49 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -66,7 +66,7 @@ my $biblionumber=$query->param('bib'); my $bibid = $query->param('bibid'); $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber) unless $bibid; $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid) unless $biblionumber; -my $itemtype = &MARCfind_itemtype($dbh,$bibid); +my $itemtype = &MARCfind_frameworkcode($dbh,$bibid); my $tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record =MARCgetbiblio($dbh,$bibid); -- 2.39.5