From 34d339914982a11b2b72191d0362dbf38c7c31dd Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Fri, 12 Sep 2008 13:16:58 -0600 Subject: [PATCH] Use biblioitems.itemtype as a default for items.itype This correct the html select default in additem.pl, and enforces use of biblioitems.itemtype as the default in Items::AddItem. The code in Items is to catch items added through MARC record staging. Thanks to Joe Atzberger for suggestion. [RM note: this patch means that an item's item-level item type, once that item is added or updated via additem.pl, now cannot be blank or NULL unless the biblio-level item type is blank.] Signed-off-by: Galen Charlton --- C4/Items.pm | 6 ++++++ cataloguing/additem.pl | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/C4/Items.pm b/C4/Items.pm index dcac099833..0f7d6a30f3 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -224,6 +224,12 @@ sub AddItem { _set_derived_columns_for_add($item); $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields); # FIXME - checks here + unless ( $item->{itype} ) { # default to biblioitem.itemtype if no itype + my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); + $itype_sth->execute( $item->{'biblionumber'} ); + ( $item->{'itype'} ) = $itype_sth->fetchrow_array; + } + my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} ); $item->{'itemnumber'} = $itemnumber; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 62885d2ae0..f2f192236b 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -333,7 +333,16 @@ foreach my $tag (sort keys %{$tagslib}) { push @authorised_values, $itemtype; $authorised_lib{$itemtype} = $description; } - $value = $itemtype unless ($value); + + unless ( $value ) { + my $default_itemtype; + my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); + $itype_sth->execute( $biblionumber ); + ( $default_itemtype ) = $itype_sth->fetchrow_array; + $value = $default_itemtype; + } + + #---- class_sources } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); -- 2.39.5