bug 4422: add AR (article) format icon to staff interface
[koha.git] / opac / opac-authoritiesdetail.pl
blobbe4beca2bc5460075854df9ef648bda02fb33b9b
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
27 =head1 DESCRIPTION
29 This script needs an authid
31 It shows the authority in a (nice) MARC format depending on authority MARC
32 parameters tables.
34 =head1 FUNCTIONS
36 =over 2
38 =cut
40 use strict;
41 use warnings;
43 use C4::AuthoritiesMarc;
44 use C4::Auth;
45 use C4::Context;
46 use C4::Output;
47 use CGI;
48 use MARC::Record;
49 use C4::Koha;
52 my $query = new CGI;
54 my $dbh = C4::Context->dbh;
56 my $authid = $query->param('authid');
57 my $authtypecode = &GetAuthTypeCode( $authid );
58 my $tagslib = &GetTagsLabels( 1, $authtypecode );
60 # open template
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => "opac-authoritiesdetail.tmpl",
64 query => $query,
65 type => "opac",
66 authnotrequired => 1,
67 debug => 1,
71 my $record;
72 if (C4::Context->preference("AuthDisplayHierarchy")){
73 my $trees=BuildUnimarcHierarchies($authid);
74 my @trees = split /;/,$trees ;
75 push @trees,$trees unless (@trees);
76 my @loophierarchies;
77 foreach my $tree (@trees){
78 my @tree=split /,/,$tree;
79 push @tree,$tree unless (@tree);
80 my $cnt=0;
81 my @loophierarchy;
82 foreach my $element (@tree){
83 my $cell;
84 my $elementdata = GetAuthority($element);
85 $record= $elementdata if ($authid==$element);
86 push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid);
87 $cnt++;
89 push @loophierarchies, { 'loopelement' =>\@loophierarchy};
91 $template->param(
92 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
93 'loophierarchies' =>\@loophierarchies,
96 else {
97 $record = GetAuthority( $authid );
99 my $count = CountUsage($authid);
101 # find the marc field/subfield used in biblio by this authority
102 my $sth =
103 $dbh->prepare(
104 "select distinct tagfield from marc_subfield_structure where authtypecode=?"
106 $sth->execute($authtypecode);
107 my $biblio_fields;
108 while ( my ($tagfield) = $sth->fetchrow ) {
109 $biblio_fields .= $tagfield . "9,";
111 chop $biblio_fields;
113 # fill arrays
114 my @loop_data = ();
115 my $tag;
117 # loop through each tab 0 through 9
118 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
119 # loop through each tag
120 my @fields = $record->fields();
121 foreach my $field (@fields) {
122 my @subfields_data;
124 # if tag <10, there's no subfield, use the "@" trick
125 if ( $field->tag() < 10 ) {
126 next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} );
127 my %subfield_data;
128 $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib};
129 $subfield_data{marc_value} = $field->data();
130 $subfield_data{marc_subfield} = '@';
131 $subfield_data{marc_tag} = $field->tag();
132 push( @subfields_data, \%subfield_data );
134 else {
135 my @subf = $field->subfields;
137 # loop through each subfield
138 for my $i ( 0 .. $#subf ) {
139 $subf[$i][0] = "@" unless $subf[$i][0];
140 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
141 my %subfield_data;
142 $subfield_data{marc_lib} =
143 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
144 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
145 $subfield_data{marc_value} =
146 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
148 else {
149 $subfield_data{marc_value} = $subf[$i][1];
151 $subfield_data{marc_subfield} = $subf[$i][0];
152 $subfield_data{marc_tag} = $field->tag();
153 push( @subfields_data, \%subfield_data );
156 if ( $#subfields_data >= 0 ) {
157 my %tag_data;
158 $tag_data{tag} =
159 $field->tag()
160 . ' '
161 . C4::Koha::display_marc_indicators($field)
162 . ' - ' . $tagslib->{ $field->tag() }->{lib};
163 $tag_data{subfield} = \@subfields_data;
164 push( @loop_data, \%tag_data );
167 $template->param( "0XX" => \@loop_data );
169 my $authtypes = getauthtypes;
170 my @authtypesloop;
171 foreach my $thisauthtype ( keys %$authtypes ) {
172 my $selected = 1 if $thisauthtype eq $authtypecode;
173 my %row = (
174 value => $thisauthtype,
175 selected => $selected,
176 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
178 push @authtypesloop, \%row;
181 $template->param(
182 authid => $authid,
183 count => $count,
184 biblio_fields => $biblio_fields,
185 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
186 authtypesloop => \@authtypesloop,
187 LibraryName => C4::Context->preference("LibraryName"),
188 OpacNav => C4::Context->preference("OpacNav"),
189 opaccredits => C4::Context->preference("opaccredits"),
190 opacsmallimage => C4::Context->preference("opacsmallimage"),
191 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
192 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
194 output_html_with_http_headers $query, $cookie, $template->output;