MT 2309, Follow-up : Display item location codes in item adding
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Thu, 19 Nov 2009 22:47:50 +0000 (23:47 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Thu, 19 Nov 2009 22:47:50 +0000 (23:47 +0100)
Conflicts solved cataloguing/additem.pl

cataloguing/additem.pl

index 20007da..d61892d 100755 (executable)
@@ -355,7 +355,6 @@ foreach my $subfield_code (sort keys(%witness)) {
 # now, build the item form for entering a new item
 my @loop_data =();
 my $i=0;
-my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
 
 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
@@ -461,15 +460,28 @@ foreach my $tag (sort keys %{$tagslib}) {
       }
       else {
           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
-          $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
+
+         # Are we dealing with item location ?
+          my $item_location = ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) ? 1 : 0;
+
+          # If so, we sort by authorised_value, else by libelle
+          my $orderby = $item_location ? 'authorised_value' : 'lib';
+
+          my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY $orderby");
+
+          $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value});
+
+
           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
-              push @authorised_values, $value;
-             
-             if ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) {
-                 $authorised_lib{$value} = $value . " - " . $lib;
-             } else {
-                 $authorised_lib{$value} = $lib;
-             }
+            push @authorised_values, $value;
+               if ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) {
+                               $authorised_lib{$value} = $value . " - " . $lib;
+               } else {
+                               $authorised_lib{$value} = $lib;
+               }
+
+               # For item location, we show the code and the libelle
+               $authorised_lib{$value} = ($item_location) ? $value . " - " . $lib : $lib;
           }
       }
       $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list