Koha 3.8.0 Translation Update
[koha.git] / opac / opac-authoritiesdetail.pl
blob6610dfda5c8e8662d985840b77b0a977183d3759
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
47 use MARC::Record;
48 use C4::Koha;
51 my $query = new CGI;
53 my $dbh = C4::Context->dbh;
55 my $authid = $query->param('authid');
56 my $authtypecode = &GetAuthTypeCode( $authid );
57 my $tagslib = &GetTagsLabels( 1, $authtypecode );
59 # open template
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "opac-authoritiesdetail.tmpl",
63 query => $query,
64 type => "opac",
65 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
66 debug => 1,
70 my $record;
71 if (C4::Context->preference("AuthDisplayHierarchy")){
72 my $trees=BuildUnimarcHierarchies($authid);
73 my @trees = split /;/,$trees ;
74 push @trees,$trees unless (@trees);
75 my @loophierarchies;
76 foreach my $tree (@trees){
77 my @tree=split /,/,$tree;
78 push @tree,$tree unless (@tree);
79 my $cnt=0;
80 my @loophierarchy;
81 foreach my $element (@tree){
82 my $cell;
83 my $elementdata = GetAuthority($element);
84 $record= $elementdata if ($authid==$element);
85 push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid);
86 $cnt++;
88 push @loophierarchies, { 'loopelement' =>\@loophierarchy};
90 $template->param(
91 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
92 'loophierarchies' =>\@loophierarchies,
95 else {
96 $record = GetAuthority( $authid );
98 my $count = CountUsage($authid);
100 # find the marc field/subfield used in biblio by this authority
101 my $sth =
102 $dbh->prepare(
103 "select distinct tagfield from marc_subfield_structure where authtypecode=?"
105 $sth->execute($authtypecode);
106 my $biblio_fields;
107 while ( my ($tagfield) = $sth->fetchrow ) {
108 $biblio_fields .= $tagfield . "9,";
110 chop $biblio_fields;
112 # fill arrays
113 my @loop_data = ();
114 my $tag;
116 # loop through each tab 0 through 9
117 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
118 # loop through each tag
119 my @fields = $record->fields();
120 foreach my $field (@fields) {
121 my @subfields_data;
123 # skip UNIMARC fields <200, they are useless for a patron
124 next if C4::Context->preference('MarcFlavour') eq 'UNIMARC' && $field->tag() <200;
126 # if tag <10, there's no subfield, use the "@" trick
127 if ( $field->tag() < 10 ) {
128 next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} );
129 my %subfield_data;
130 $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib};
131 $subfield_data{marc_value} = $field->data();
132 $subfield_data{marc_subfield} = '@';
133 $subfield_data{marc_tag} = $field->tag();
134 push( @subfields_data, \%subfield_data );
136 else {
137 my @subf = $field->subfields;
139 # loop through each subfield
140 for my $i ( 0 .. $#subf ) {
141 $subf[$i][0] = "@" unless $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 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
149 $subfield_data{marc_value} =
150 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
152 else {
153 $subfield_data{marc_value} = $subf[$i][1];
155 $subfield_data{marc_subfield} = $subf[$i][0];
156 $subfield_data{marc_tag} = $field->tag();
157 push( @subfields_data, \%subfield_data );
160 if ( $#subfields_data >= 0 ) {
161 my %tag_data;
162 $tag_data{tag} =
163 $field->tag()
164 . ' '
165 . C4::Koha::display_marc_indicators($field)
166 . ' - ' . $tagslib->{ $field->tag() }->{lib};
167 $tag_data{subfield} = \@subfields_data;
168 push( @loop_data, \%tag_data );
171 $template->param( "Tab0XX" => \@loop_data );
173 my $authtypes = getauthtypes();
174 my @authtypesloop = ();
175 foreach my $thisauthtype ( keys %{$authtypes} ) {
176 push @authtypesloop,
177 { value => $thisauthtype,
178 selected => $thisauthtype eq $authtypecode,
179 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
183 $template->param(
184 authid => $authid,
185 count => $count,
186 biblio_fields => $biblio_fields,
187 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
188 authtypesloop => \@authtypesloop,
189 LibraryName => C4::Context->preference("LibraryName"),
190 OpacNav => C4::Context->preference("OpacNav"),
191 opaccredits => C4::Context->preference("opaccredits"),
192 opacsmallimage => C4::Context->preference("opacsmallimage"),
193 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
194 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
196 output_html_with_http_headers $query, $cookie, $template->output;