Bug 17785: Fix OAI-PMH's XSLT-generated URLs under Plack
[koha.git] / opac / opac-authoritiesdetail.pl
blobf46c5111f4b97fc5842fe378b4fa9aeb9c17fcc8
1 #!/usr/bin/perl
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>.
20 =head1 NAME
22 opac-authoritiesdetail.pl : script to show an authority in MARC format
24 =head1 SYNOPSIS
26 =cut
28 =head1 DESCRIPTION
30 This script needs an authid
32 It shows the authority in a (nice) MARC format depending on authority MARC
33 parameters tables.
35 =head1 FUNCTIONS
37 =cut
39 use strict;
40 use warnings;
42 use C4::AuthoritiesMarc;
43 use C4::Auth;
44 use C4::Context;
45 use C4::Output;
46 use CGI qw ( -utf8 );
47 use MARC::Record;
48 use C4::Koha;
50 use Koha::Authorities;
51 use Koha::Authority::Types;
53 my $query = new CGI;
55 my $dbh = C4::Context->dbh;
57 my $display_hierarchy = C4::Context->preference("AuthDisplayHierarchy");
58 my $show_marc = $query->param('marc');
60 # open template
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => $show_marc ? "opac-auth-MARCdetail.tt" : "opac-auth-detail.tt",
64 query => $query,
65 type => "opac",
66 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
67 debug => 1,
71 my $authid = $query->param('authid');
72 $authid = int($authid);
73 my $record = GetAuthority( $authid );
74 if ( ! $record ) {
75 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
76 exit;
79 my $authority = Koha::Authorities->find( $authid );
80 my $authtypecode = $authority->authtypecode;
82 if ($display_hierarchy){
83 $template->{VARS}->{'displayhierarchy'} = $display_hierarchy;
84 $template->{VARS}->{'loophierarchies'} = GenerateHierarchy($authid);
87 my $count = CountUsage($authid);
89 my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
90 $template->param(
91 authority_types => $authority_types,
92 authtypetext => $authority_types->find($authtypecode)->authtypetext,
93 authid => $authid,
94 count => $count,
97 # find the marc field/subfield used in biblio by this authority
98 if ($show_marc) {
99 my $tagslib = &GetTagsLabels( 0, $authtypecode );
100 my $sth =
101 $dbh->prepare(
102 "select distinct tagfield from marc_subfield_structure where authtypecode=?"
104 $sth->execute($authtypecode);
105 my $biblio_fields;
106 while ( my ($tagfield) = $sth->fetchrow ) {
107 $biblio_fields .= $tagfield . "9,";
109 chop $biblio_fields;
111 # fill arrays
112 my @loop_data = ();
113 my $tag;
115 # loop through each tag
116 my @fields = $record->fields();
117 foreach my $field (@fields) {
118 my @subfields_data;
120 # skip UNIMARC fields <200, they are useless for a patron
121 next if C4::Context->preference('marcflavour') eq 'UNIMARC' && $field->tag() <200;
123 # if tag <10, there's no subfield, use the "@" trick
124 if ( $field->tag() < 10 ) {
125 next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} );
126 my %subfield_data;
127 $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib};
128 $subfield_data{marc_value} = $field->data();
129 $subfield_data{marc_subfield} = '@';
130 $subfield_data{marc_tag} = $field->tag();
131 push( @subfields_data, \%subfield_data );
133 elsif ( C4::Context->preference('marcflavour') eq 'MARC21' && $field->tag() eq 667 ) {
134 # tagfield 667 is a nonpublic general note in MARC21, which shouldn't be shown in the OPAC
136 else {
137 my @subf = $field->subfields;
139 # loop through each subfield
140 for my $i ( 0 .. $#subf ) {
141 $subf[$i][0] = "@" unless defined $subf[$i][0];
142 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
143 # skip useless subfields (for patrons)
144 next if $subf[$i][0] =~ /7|8|9/;
145 my %subfield_data;
146 $subfield_data{marc_lib} =
147 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
148 $subfield_data{marc_subfield} = $subf[$i][0];
149 $subfield_data{marc_tag} = $field->tag();
150 $subfield_data{isurl} = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl};
151 $subfield_data{marc_value} = $subf[$i][1];
152 push( @subfields_data, \%subfield_data );
155 if ( $#subfields_data >= 0 ) {
156 my %tag_data;
157 $tag_data{tag} =
158 $field->tag()
159 . ' '
160 . C4::Koha::display_marc_indicators($field)
161 . ' - ' . $tagslib->{ $field->tag() }->{lib};
162 $tag_data{subfield} = \@subfields_data;
163 push( @loop_data, \%tag_data );
166 $template->param( "Tab0XX" => \@loop_data );
167 } else {
168 my $summary = BuildSummary($record, $authid, $authtypecode);
169 $template->{VARS}->{'summary'} = $summary;
172 output_html_with_http_headers $query, $cookie, $template->output;