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 detail.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
41 use C4::Auth qw( get_template_and_user );
42 use C4::AuthoritiesMarc qw( GetAuthority GenerateHierarchy GetTagsLabels );
44 use C4::Output qw( output_html_with_http_headers );
47 use Koha::Authorities;
49 use Koha::Authority::Types;
51 use Koha::Z3950Servers;
56 my ( $template, $record, $dbh, $encoding,$input ) = @_;
62 # in this array, we will push all the 10 tabs
63 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
66 my @tab_data; # all tags to display
68 foreach my $used ( keys %$tagslib ){
69 push @tab_data,$used if not $seen{$used};
74 # loop through each tab 0 through 9
75 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
76 my @loop_data = (); #innerloop in the template.
78 foreach my $tag (sort @tab_data) {
82 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
83 # if MARC::Record is empty => use tab as master loop.
84 if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) {
86 if ( $tag ne '000' ) {
87 @fields = $record->field($tag);
90 push @fields, MARC::Field->new('000', $record->leader()); # if tag == 000
92 # loop through each field
93 foreach my $field (@fields) {
95 if ($field->tag()<10) {
98 $tagslib->{ $field->tag() }->{ '@' }->{tab}
100 next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
102 $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
103 $subfield_data{marc_value}=$field->data();
104 $subfield_data{marc_subfield}='@';
105 $subfield_data{marc_tag}=$field->tag();
106 push(@subfields_data, \%subfield_data);
108 my @subf=$field->subfields;
109 # loop through each subfield
110 for my $i (0..$#subf) {
111 $subf[$i][0] = "@" unless defined $subf[$i][0];
114 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab}
117 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }
120 $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
121 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
122 $subfield_data{marc_value} = $subf[$i][1];
123 $subfield_data{is_url} = 1;
125 $subfield_data{marc_value}=$subf[$i][1];
127 $subfield_data{short_desc} = substr(
128 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib},
131 $subfield_data{long_desc} =
132 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
133 $subfield_data{marc_subfield}=$subf[$i][0];
134 $subfield_data{marc_tag}=$field->tag();
135 push(@subfields_data, \%subfield_data);
138 if ($#subfields_data>=0) {
140 $tag_data{tag_number} = $tag;
141 $tag_data{tag_desc} = $tagslib->{$field->tag()}->{lib};
142 $tag_data{subfield} = \@subfields_data;
143 my $indicators = C4::Koha::display_marc_indicators($field);
145 $tag_data{ind1} = substr $indicators, 0, 1;
146 $tag_data{ind2} = substr $indicators, 1, 1;
149 push (@loop_data, \%tag_data);
154 if ( $#loop_data >= 0 ) {
157 innerloop => \@loop_data,
161 $template->param( singletab => (scalar(@BIG_LOOP)==1), BIG_LOOP => \@BIG_LOOP );
168 my $dbh=C4::Context->dbh;
171 my ($template, $loggedinuser, $cookie) = get_template_and_user(
173 template_name => "authorities/detail.tt",
176 flagsrequired => { catalogue => 1 },
180 my $authid = $query->param('authid');
182 my $authobj = Koha::Authorities->find($authid);
183 my $authtypecode = $authobj ? $authobj->authtypecode : q{};
184 $tagslib = GetTagsLabels(1,$authtypecode);
186 # Build list of authtypes for showing them
187 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
189 my $record=GetAuthority($authid);
191 if (not defined $record) {
193 $template->param ( errauthid => $authid,
195 authority_types => $authority_types, );
196 output_html_with_http_headers $query, $cookie, $template->output;
200 if (C4::Context->preference("AuthDisplayHierarchy")){
201 $template->{VARS}->{'displayhierarchy'} = C4::Context->preference("AuthDisplayHierarchy");
202 $template->{VARS}->{'loophierarchies'} = GenerateHierarchy($authid);
205 my $count = $authobj ? $authobj->get_usage_count : 0;
207 # find the marc field/subfield used in biblio by this authority
208 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
209 $sth->execute($authtypecode);
211 while (my ($tagfield) = $sth->fetchrow) {
212 $biblio_fields.= $tagfield."9,";
214 chop $biblio_fields if $biblio_fields;
216 build_tabs ($template, $record, $dbh,"",$query);
218 my $servers = Koha::Z3950Servers->search(
220 recordtype => 'authority',
221 servertype => ['zed', 'sru'],
225 my $type = $authority_types->find($authtypecode);
229 biblio_fields => $biblio_fields,
230 authtypetext => $type ? $type->authtypetext: "",
231 authtypecode => $authtypecode,
232 authority_types => $authority_types,
233 csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $query->cookie('CGISESSID') }),
237 $template->{VARS}->{marcflavour} = C4::Context->preference("marcflavour");
238 output_html_with_http_headers $query, $cookie, $template->output;