Bug 8692: Authorities search form does not correspond to current search query
[koha.git] / authorities / blinddetail-biblio-search.pl
index 0f734b2..6b3d122 100755 (executable)
@@ -54,6 +54,7 @@ my $dbh = C4::Context->dbh;
 my $authid       = $query->param('authid');
 my $index        = $query->param('index');
 my $tagid        = $query->param('tagid');
+my $relationship = $query->param('relationship');
 my $authtypecode = &GetAuthTypeCode($authid);
 my $tagslib      = &GetTagsLabels( 1, $authtypecode );
 
@@ -80,22 +81,40 @@ if ($authid) {
     my @fields = $record->field( $auth_type->{auth_tag_to_report} );
     my $repet = ($query->param('repet') || 1) - 1;
     my $field = $fields[$repet];
+
+    # Get all values for each distinct subfield
+    my %subfields;
     for ( $field->subfields ) {
-        my ($letter, $value) = @$_;
-        $letter = '@' unless $letter;
-        push @subfield_loop, { marc_subfield => $letter, marc_value => $value };
+        next if $_->[0] == "9"; # $9 will be set with authid value
+        my $letter = $_->[0];
+        next if defined $subfields{$letter};
+        my @values = $field->subfield($letter);
+        $subfields{$letter} = \@values;
+    }
+
+    # Add all subfields to the subfield_loop
+    for( keys %subfields ) {
+        my $letter = $_ || '@';
+        push( @subfield_loop, {marc_subfield => $letter, marc_values => $subfields{$_}} );
     }
+
+    push( @subfield_loop, { marc_subfield => 'w', marc_values => $relationship } ) if ( $relationship );
 }
 else {
     # authid is empty => the user want to empty the entry.
     $template->param( "clear" => 1 );
 }
 
+# Extract the tag number from the index
+my $tag_number = $index;
+$tag_number =~ s/^tag_(\d*)_.*$/$1/;
+
 $template->param(
     authid          => $authid ? $authid : "",
     index           => $index,
     tagid           => $tagid,
     SUBFIELD_LOOP   => \@subfield_loop,
+    tag_number      => $tag_number,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;