Khk updates
[koha.git] / cataloguing / additem.pl
index 7988475..5af5399 100755 (executable)
@@ -149,7 +149,7 @@ if ($op eq "additem") {
         my $items = &GetItemsByBiblioitemnumber($biblioitem->{biblioitemnumber});
 
         foreach my $item (@$items){
-            &DelItem($dbh,$biblionumber,$item->{itemnumber});
+            &DelItemCheck($dbh,$biblionumber,$item->{itemnumber});
         }
     }
     print $input->redirect("/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=$biblionumber");
@@ -198,8 +198,7 @@ my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebran
 
 foreach my $field (@fields) {
     next if ($field->tag()<10);
-    my @subf = $field->subfields;
-    (defined @subf) or @subf = ();
+    my @subf = $field->subfields or (); # don't use ||, as that forces $field->subfelds to be interpreted in scalar context
     my %this_row;
 # loop through each subfield
     for my $i (0..$#subf) {
@@ -227,12 +226,7 @@ foreach my $field (@fields) {
         push(@big_array, \%this_row);
     }
 }
-#fill big_row with missing data
-foreach my $subfield_code  (keys(%witness)) {
-    for (my $i=0;$i<=$#big_array;$i++) {
-        $big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
-    }
-}
+
 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
 
@@ -240,17 +234,13 @@ my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbran
 # First, the existing items for display
 my @item_value_loop;
 my @header_value_loop;
-for (my $i=0;$i<=$#big_array; $i++) {
-    my $items_data;
-    foreach my $subfield_code (sort keys(%witness)) {
-        $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
-    }
+for my $row ( @big_array ) {
     my %row_data;
-    $items_data =~ s/"/&quot;/g;
-    $row_data{item_value} = $items_data;
-    $row_data{itemnumber} = $big_array[$i]->{itemnumber};
+    my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) };
+    $row_data{item_value} = [ @item_fields ];
+    $row_data{itemnumber} = $row->{itemnumber};
     #reporting this_row values
-    $row_data{'nomod'}    = $big_array[$i]{'nomod'};
+    $row_data{'nomod'} = $row->{'nomod'};
     push(@item_value_loop,\%row_data);
 }
 foreach my $subfield_code (sort keys(%witness)) {
@@ -268,7 +258,7 @@ my $onlymine = C4::Context->preference('IndependantBranches') &&
                C4::Context->userenv                           && 
                C4::Context->userenv->{flags}!=1               && 
                C4::Context->userenv->{branch};
-my $branches = GetBranches($onlymine);  # build once ahead of time, instead of multiple times later.
+my $branches = GetBranchesLoop(undef,$onlymine);  # build once ahead of time, instead of multiple times later.
 
 foreach my $tag (sort keys %{$tagslib}) {
 # loop through each subfield
@@ -296,7 +286,7 @@ foreach my $tag (sort keys %{$tagslib}) {
     unless ($value) {
         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
         # get today date & replace YYYY, MM, DD if provided in the default value
-        my ( $year, $month, $day ) = split ',', $today_iso;
+        my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
         $value =~ s/YYYY/$year/g;
         $value =~ s/MM/$month/g;
         $value =~ s/DD/$day/g;
@@ -329,21 +319,28 @@ foreach my $tag (sort keys %{$tagslib}) {
       # builds list, depending on authorised value...
   
       if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
-          foreach my $thisbranch ( sort keys %$branches ) {
-              push @authorised_values, $thisbranch;
-              $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
+          foreach my $thisbranch (@$branches) {
+              push @authorised_values, $thisbranch->{value};
+              $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
+              $value = $thisbranch->{value} if $thisbranch->{selected};
           }
       }
       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
           my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
           $sth->execute;
-          my $itemtype;     # FIXME: double declaration of $itemtype
           while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
               push @authorised_values, $itemtype;
               $authorised_lib{$itemtype} = $description;
           }
-          $value = $itemtype unless ($value);
+
+          unless ( $value ) {
+              my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
+              $itype_sth->execute( $biblionumber );
+              ( $value ) = $itype_sth->fetchrow_array;
+          }
+  
+          #---- class_sources
       }
       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
@@ -370,7 +367,7 @@ foreach my $tag (sort keys %{$tagslib}) {
               $authorised_lib{$value} = $lib;
           }
       }
-      $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list
+      $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
           -name     => "field_value",
           -values   => \@authorised_values,
           -default  => $value,