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;
53 my $dbh=C4::Context->dbh;
54 my $nonav = $query->param('nonav');
55 my $authid = $query->param('authid');
56 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
57 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
59 my $xmlhash =XMLgetauthorityhash($dbh,$authid);
61 my ($count) = AUTHcount_usage($authid);
66 my ($template, $loggedinuser, $cookie)
67 = get_template_and_user({template_name => "authorities/detail.tmpl",
71 flagsrequired => {catalogue => 1},
80 # loop through each tab 0 through 9
81 my $author=$xmlhash->{'datafield'};
82 my $controlfields=$xmlhash->{'controlfield'};
83 my $leader=$xmlhash->{'leader'};
84 for (my $tabloop = 0; $tabloop<10;$tabloop++) {
85 # loop through each tag
90 unless (($tagslib->{'000'}->{'@'}->{tab} ne $tabloop) || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
93 $subfield_data{marc_value}=$leader->[0] ;
94 push(@subfields_data, \%subfield_data);
96 $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
97 my @tmp = @subfields_data;
98 $tag_data{subfield} = \@tmp;
99 push (@loop_data, \%tag_data);
100 undef @subfields_data;
104 foreach my $control (@$controlfields){
107 next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab} ne $tabloop);
108 next if (substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);
109 $subfield_data{marc_value}=$control->{'content'} ;
110 push(@subfields_data, \%subfield_data);
111 if (C4::Context->preference('hide_marc')) {
112 $tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
114 $tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib};
116 my @tmp = @subfields_data;
117 $tag_data{subfield} = \@tmp;
118 push (@loop_data, \%tag_data);
119 undef @subfields_data;
124 foreach my $data (@$author){
125 $datatags{$i++}=$data->{'tag'};
126 foreach my $subfield ( $data->{'subfield'}){
127 foreach my $code ( @$subfield){
128 next if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne $tabloop);
129 next if (substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
131 my $value=$code->{'content'};
132 $subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
133 $subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
134 if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
135 $subfield_data{marc_value}="<a href=\"$value]\">$value</a>";
137 $subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh);
139 $subfield_data{marc_subfield}=$code->{'code'};
140 $subfield_data{marc_tag}=$data->{'tag'};
141 push(@subfields_data, \%subfield_data);
145 if ($#subfields_data>=0) {
147 if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) {
150 if (C4::Context->preference('hide_marc')) {
151 $tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
153 $tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib};
156 my @tmp = @subfields_data;
157 $tag_data{subfield} = \@tmp;
158 push (@loop_data, \%tag_data);
159 undef @subfields_data;
164 $template->param($tabloop."XX" =>\@loop_data);
166 my $authtypes = getauthtypes;
168 foreach my $thisauthtype (keys %$authtypes) {
169 my $selected = 1 if $thisauthtype eq $authtypecode;
170 my %row =(value => $thisauthtype,
171 selected => $selected,
172 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
174 push @authtypesloop, \%row;
177 $template->param(authid => $authid,
179 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
180 authtypecode => $authtypes->{$authtypecode}{'authtypecode'},
181 authtypesloop => \@authtypesloop);
182 $template->param(nonav =>$nonav);
183 }### if $xmlash exist
184 output_html_with_http_headers $query, $cookie, $template->output;
186 sub get_authorised_value_desc ($$$$$) {
187 my($tag, $subfield, $value, $framework, $dbh) = @_;
190 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
191 return getbranchname($value);
195 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
196 return ItemType($value);
199 #---- "true" authorized value
200 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
202 if ($category ne "") {
203 my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
204 $sth->execute($category, $value);
205 my $data = $sth->fetchrow_hashref;
206 return $data->{'lib'};
208 return $value; # if nothing is found return the original value