Bug 6316 - MARC21 files (split part)
[koha.git] / cataloguing / additem.pl
index c5dd7d9..faa9a0a 100755 (executable)
@@ -150,7 +150,7 @@ sub generate_subfield_form {
                 foreach my $thisbranch (@$branches) {
                     push @authorised_values, $thisbranch->{value};
                     $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
-                    $value = $thisbranch->{value} if $thisbranch->{selected};
+                    $value = $thisbranch->{value} if $thisbranch->{selected} && !$value;
                 }
             }
             elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
@@ -262,7 +262,6 @@ sub generate_subfield_form {
 
 
 my $input        = new CGI;
-my $dbh          = C4::Context->dbh;
 my $error        = $input->param('error');
 my $biblionumber = $input->param('biblionumber');
 my $itemnumber   = $input->param('itemnumber');
@@ -494,13 +493,14 @@ if ($op eq "additem") {
 
 # now, build existiing item list
 my $temp = GetMarcBiblio( $biblionumber );
-my @fields = $temp->fields();
 #my @fields = $record->fields();
 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
 my @big_array;
 #---- finds where items.itemnumber is stored
 my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
+C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber);
+my @fields = $temp->fields();
 
 foreach my $field (@fields) {
     next if ( $field->tag() < 10 );
@@ -570,10 +570,10 @@ my $onlymine = C4::Context->preference('IndependantBranches') &&
                C4::Context->userenv                           && 
                C4::Context->userenv->{flags}!=1               && 
                C4::Context->userenv->{branch};
-my $branches = GetBranchesLoop(undef,$onlymine);  # build once ahead of time, instead of multiple times later.
+my $branches = GetBranchesLoop(C4::Context->userenv->{branch},$onlymine);  # build once ahead of time, instead of multiple times later.
 
 # We generate form, from actuel record
-my @fields;
+@fields = ();
 if($itemrecord){
     foreach my $field ($itemrecord->fields()){
         my $tag = $field->{_tag};