3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 blinddetail-biblio-search.pl : script to show an authority in MARC format
30 This script needs an authid
32 It shows the authority in a (nice) MARC format depending on authority MARC
42 use C4::AuthoritiesMarc;
50 use Koha::Authorities;
51 use Koha::Authority::Types;
55 my $dbh = C4::Context->dbh;
57 my $authid = $query->param('authid');
58 my $index = $query->param('index');
59 my $tagid = $query->param('tagid');
60 my $relationship = $query->param('relationship');
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "authorities/blinddetail-biblio-search.tt",
69 flagsrequired => { editcatalogue => 'edit_catalogue' },
73 # Extract the tag number from the index
74 my $tag_number = $index;
75 $tag_number =~ s/^tag_(\d*)_.*$/$1/;
79 my ($indicator1, $indicator2);
81 my $auth = Koha::Authorities->find( $authid );
82 my $authtypecode = $auth ? $auth->authtypecode : q{};
83 my $auth_type = Koha::Authority::Types->find($authtypecode);
84 my $record = GetAuthority($authid);
85 my @fields = $record->field( $auth_type->auth_tag_to_report );
86 my $repet = ($query->param('repet') || 1) - 1;
87 my $field = $fields[$repet];
89 # Get all values for each distinct subfield
91 for ( $field->subfields ) {
92 next if $_->[0] eq '9'; # $9 will be set with authid value
94 next if defined $subfields{$letter};
95 my @values = $field->subfield($letter);
96 $subfields{$letter} = \@values;
99 # Add all subfields to the subfield_loop
100 for( keys %subfields ) {
101 my $letter = $_ || '@';
102 push( @subfield_loop, {marc_subfield => $letter, marc_values => $subfields{$_}} );
105 push( @subfield_loop, { marc_subfield => 'w', marc_values => $relationship } ) if ( $relationship );
107 my $controlled_ind = $auth->controlled_indicators({ record => $record, biblio_tag => $tag_number });
108 $indicator1 = $controlled_ind->{ind1} // q{};
109 $indicator2 = $controlled_ind->{ind2} // q{};
110 if( defined $controlled_ind->{sub2} ) {
111 my $v = $controlled_ind->{sub2};
112 push @subfield_loop, { marc_subfield => '2', marc_values => [ $v ] };
115 # authid is empty => the user want to empty the entry.
116 $template->param( "clear" => 1 );
119 # Remove spaces in indicators
120 $indicator1 =~ s/\s//g;
121 $indicator2 =~ s/\s//g;
124 authid => $authid ? $authid : "",
127 indicator1 => $indicator1,
128 indicator2 => $indicator2,
129 SUBFIELD_LOOP => \@subfield_loop,
130 tag_number => $tag_number,
133 output_html_with_http_headers $query, $cookie, $template->output;