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
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 etail.pl : script to show an authority in MARC format
29 This script needs an authid
31 It shows the authority in a (nice) MARC format depending on authority MARC
42 use C4::AuthoritiesMarc;
45 use C4::Interface::CGI::Output;
52 my $dbh=C4::Context->dbh;
54 my $authid = $query->param('authid');
55 my $index = $query->param('index');
56 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
57 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
59 my $record =XMLgetauthorityhash($dbh,$authid);
61 my ($template, $loggedinuser, $cookie)
62 = get_template_and_user({template_name => "authorities/detail-biblio-search.tmpl",
66 flagsrequired => {catalogue => 1},
74 # loop through each tab 0 through 9
75 my $author=$xmlhash->{'datafield'};
76 my $controlfields=$xmlhash->{'controlfield'};
77 my $leader=$xmlhash->{'leader'};
78 for (my $tabloop = 0; $tabloop<10;$tabloop++) {
79 # loop through each tag
84 unless (($tagslib->{'000'}->{'@'}->{tab} ne $tabloop) || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
87 $subfield_data{marc_value}=$leader->[0] ;
88 push(@subfields_data, \%subfield_data);
90 $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
91 my @tmp = @subfields_data;
92 $tag_data{subfield} = \@tmp;
93 push (@loop_data, \%tag_data);
94 undef @subfields_data;
98 foreach my $control (@$controlfields){
101 next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab} ne $tabloop);
102 next if (substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);
103 $subfield_data{marc_value}=$control->{'content'} ;
104 push(@subfields_data, \%subfield_data);
105 if (C4::Context->preference('hide_marc')) {
106 $tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
108 $tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib};
110 my @tmp = @subfields_data;
111 $tag_data{subfield} = \@tmp;
112 push (@loop_data, \%tag_data);
113 undef @subfields_data;
118 foreach my $data (@$author){
119 $datatags{$i++}=$data->{'tag'};
120 foreach my $subfield ( $data->{'subfield'}){
121 foreach my $code ( @$subfield){
122 next if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne $tabloop);
123 next if (substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
125 my $value=$code->{'content'};
126 $subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
127 $subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
128 if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
129 $subfield_data{marc_value}="<a href=\"$value]\">$value</a>";
131 $subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh);
133 $subfield_data{marc_subfield}=$code->{'code'};
134 $subfield_data{marc_tag}=$data->{'tag'};
135 push(@subfields_data, \%subfield_data);
139 if ($#subfields_data>=0) {
141 if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) {
144 if (C4::Context->preference('hide_marc')) {
145 $tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
147 $tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib};
150 my @tmp = @subfields_data;
151 $tag_data{subfield} = \@tmp;
152 push (@loop_data, \%tag_data);
153 undef @subfields_data;
158 $template->param($tabloop."XX" =>\@loop_data);
161 my $authtypes = getauthtypes;
163 foreach my $thisauthtype (keys %$authtypes) {
164 my $selected = 1 if $thisauthtype eq $authtypecode;
165 my %row =(value => $thisauthtype,
166 selected => $selected,
167 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
169 push @authtypesloop, \%row;
172 $template->param(authid => $authid,
173 authtypesloop => \@authtypesloop, index => $index);
175 output_html_with_http_headers $query, $cookie, $template->output;
177 sub get_authorised_value_desc ($$$$$) {
178 my($tag, $subfield, $value, $framework, $dbh) = @_;
181 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
182 return getbranchname($value);
186 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
187 return ItemType($value);
190 #---- "true" authorized value
191 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
193 if ($category ne "") {
194 my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
195 $sth->execute($category, $value);
196 my $data = $sth->fetchrow_hashref;
197 return $data->{'lib'};
199 return $value; # if nothing is found return the original value