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
43 use C4
::AuthoritiesMarc
;
54 my ( $template, $record, $dbh, $encoding,$input ) = @_;
60 # in this array, we will push all the 10 tabs
61 # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
64 my @tab_data; # all tags to display
66 foreach my $used ( keys %$tagslib ){
67 push @tab_data,$used if not $seen{$used};
72 # loop through each tab 0 through 9
73 for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
74 my @loop_data = (); #innerloop in the template.
76 foreach my $tag (sort @tab_data) {
80 # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
81 # if MARC::Record is empty => use tab as master loop.
82 if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) {
84 if ( $tag ne '000' ) {
85 @fields = $record->field($tag);
88 push @fields, MARC
::Field
->new('000', $record->leader()); # if tag == 000
90 # loop through each field
91 foreach my $field (@fields) {
93 if ($field->tag()<10) {
96 $tagslib->{ $field->tag() }->{ '@' }->{tab
}
98 next if ($tagslib->{$field->tag()}->{'@'}->{hidden
});
100 $subfield_data{marc_lib
}=$tagslib->{$field->tag()}->{'@'}->{lib
};
101 $subfield_data{marc_value
}=$field->data();
102 $subfield_data{marc_subfield
}='@';
103 $subfield_data{marc_tag
}=$field->tag();
104 push(@subfields_data, \
%subfield_data);
106 my @subf=$field->subfields;
107 # loop through each subfield
108 for my $i (0..$#subf) {
109 $subf[$i][0] = "@" unless defined $subf[$i][0];
112 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab
}
115 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }
118 $subfield_data{marc_lib
}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib
};
119 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl
}) {
120 $subfield_data{marc_value
}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
122 $subfield_data{marc_value
}=$subf[$i][1];
124 $subfield_data{short_desc
} = substr(
125 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
},
128 $subfield_data{long_desc
} =
129 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
};
130 $subfield_data{marc_subfield
}=$subf[$i][0];
131 $subfield_data{marc_tag
}=$field->tag();
132 push(@subfields_data, \
%subfield_data);
135 if ($#subfields_data>=0) {
137 $tag_data{tag
}=$field->tag(). ' '
138 . C4
::Koha
::display_marc_indicators
($field)
140 . $tagslib->{$field->tag()}->{lib
};
141 $tag_data{subfield
} = \
@subfields_data;
142 push (@loop_data, \
%tag_data);
147 if ( $#loop_data >= 0 ) {
150 innerloop
=> \
@loop_data,
154 $template->param( singletab
=> (scalar(@BIG_LOOP)==1), BIG_LOOP
=> \
@BIG_LOOP );
161 my $dbh=C4
::Context
->dbh;
164 my ($template, $loggedinuser, $cookie) = get_template_and_user
(
166 template_name
=> "authorities/detail.tt",
169 authnotrequired
=> 0,
170 flagsrequired
=> { catalogue
=> 1 },
175 my $authid = $query->param('authid');
177 my $authtypecode = GetAuthTypeCode
($authid);
178 $tagslib = &GetTagsLabels
(1,$authtypecode);
180 # Build list of authtypes for showing them
181 my $authtypes = getauthtypes
;
184 foreach my $thisauthtype (sort { $authtypes->{$b} cmp $authtypes->{$a} } keys %$authtypes) {
185 my %row =(value
=> $thisauthtype,
186 selected
=> $thisauthtype eq $authtypecode,
187 authtypetext
=> $authtypes->{$thisauthtype}{'authtypetext'},
189 push @authtypesloop, \
%row;
192 my $record=GetAuthority
($authid);
194 if (not defined $record) {
196 $template->param ( errauthid
=> $authid,
198 authtypesloop
=> \
@authtypesloop );
199 output_html_with_http_headers
$query, $cookie, $template->output;
203 if (C4
::Context
->preference("AuthDisplayHierarchy")){
204 $template->{VARS
}->{'displayhierarchy'} = C4
::Context
->preference("AuthDisplayHierarchy");
205 $template->{VARS
}->{'loophierarchies'} = GenerateHierarchy
($authid);
208 my $count = CountUsage
($authid);
210 # find the marc field/subfield used in biblio by this authority
211 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
212 $sth->execute($authtypecode);
214 while (my ($tagfield) = $sth->fetchrow) {
215 $biblio_fields.= $tagfield."9,";
219 build_tabs
($template, $record, $dbh,"",$query);
221 $template->param(authid
=> $authid,
223 biblio_fields
=> $biblio_fields,
224 authtypetext
=> $authtypes->{$authtypecode}{'authtypetext'},
225 authtypesloop
=> \
@authtypesloop,
228 $template->{VARS
}->{marcflavour
} = C4
::Context
->preference("marcflavour");
229 output_html_with_http_headers
$query, $cookie, $template->output;