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 opac-authoritiesdetail.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::Authority::Types;
54 my $dbh = C4::Context->dbh;
56 my $display_hierarchy = C4::Context->preference("AuthDisplayHierarchy");
57 my $show_marc = $query->param('marc');
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => $show_marc ? "opac-auth-MARCdetail.tt" : "opac-auth-detail.tt",
65 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
70 my $authid = $query->param('authid');
71 $authid = int($authid);
72 my $record = GetAuthority( $authid );
74 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
78 my $authtypecode = $record->authtypecode;
80 if ($display_hierarchy){
81 $template->{VARS}->{'displayhierarchy'} = $display_hierarchy;
82 $template->{VARS}->{'loophierarchies'} = GenerateHierarchy($authid);
85 my $count = CountUsage($authid);
87 my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
89 authority_types => $authority_types,
90 authtypetext => $authority_types->find($authtypecode)->authtypetext,
95 # find the marc field/subfield used in biblio by this authority
97 my $tagslib = &GetTagsLabels( 0, $authtypecode );
100 "select distinct tagfield from marc_subfield_structure where authtypecode=?"
102 $sth->execute($authtypecode);
104 while ( my ($tagfield) = $sth->fetchrow ) {
105 $biblio_fields .= $tagfield . "9,";
113 # loop through each tag
114 my @fields = $record->fields();
115 foreach my $field (@fields) {
118 # skip UNIMARC fields <200, they are useless for a patron
119 next if C4::Context->preference('marcflavour') eq 'UNIMARC' && $field->tag() <200;
121 # if tag <10, there's no subfield, use the "@" trick
122 if ( $field->tag() < 10 ) {
123 next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} );
125 $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib};
126 $subfield_data{marc_value} = $field->data();
127 $subfield_data{marc_subfield} = '@';
128 $subfield_data{marc_tag} = $field->tag();
129 push( @subfields_data, \%subfield_data );
131 elsif ( C4::Context->preference('marcflavour') eq 'MARC21' && $field->tag() eq 667 ) {
132 # tagfield 667 is a nonpublic general note in MARC21, which shouldn't be shown in the OPAC
135 my @subf = $field->subfields;
137 # loop through each subfield
138 for my $i ( 0 .. $#subf ) {
139 $subf[$i][0] = "@" unless defined $subf[$i][0];
140 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
141 # skip useless subfields (for patrons)
142 next if $subf[$i][0] =~ /7|8|9/;
144 $subfield_data{marc_lib} =
145 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
146 $subfield_data{marc_subfield} = $subf[$i][0];
147 $subfield_data{marc_tag} = $field->tag();
148 $subfield_data{isurl} = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl};
149 $subfield_data{marc_value} = $subf[$i][1];
150 push( @subfields_data, \%subfield_data );
153 if ( $#subfields_data >= 0 ) {
158 . C4::Koha::display_marc_indicators($field)
159 . ' - ' . $tagslib->{ $field->tag() }->{lib};
160 $tag_data{subfield} = \@subfields_data;
161 push( @loop_data, \%tag_data );
164 $template->param( "Tab0XX" => \@loop_data );
166 my $summary = BuildSummary($record, $authid, $authtypecode);
167 $template->{VARS}->{'summary'} = $summary;
170 output_html_with_http_headers $query, $cookie, $template->output;