# Copyright 2000-2002 Katipo Communications
+# Copyright 2004-2010 BibLibre
#
# This file is part of Koha.
#
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" ) {
my $input = new CGI;
-my $dbh = C4::Context->dbh;
my $error = $input->param('error');
my $biblionumber = $input->param('biblionumber');
my $itemnumber = $input->param('itemnumber');
# 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 );
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};
next if ($tagslib->{$tag}->{$subtag}->{'tab'} ne "10");
next if any { /^$tag$subtag$/ } @fields;
- my $value = "";
- my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);
-
- push (@loop_data, $subfield_data);
- $i++;
- }
+ my @values = (undef);
+ @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)->subfield($subtag)));
+ for my $value (@values){
+ my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);
+ push (@loop_data, $subfield_data);
+ $i++;
+ }
}
+}
+@loop_data = sort {$a->{subfield} cmp $b->{subfield} } @loop_data;
+
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
$template->param( title => $record->title() ) if ($record ne "-1");
$template->param(