Clean up before final commits
[srvgit] / authorities / detail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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
19
20 =head1 NAME
21
22 etail.pl : script to show an authority in MARC format
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 This script needs an authid
30
31 It shows the authority in a (nice) MARC format depending on authority MARC
32 parameters tables.
33
34 =head1 FUNCTIONS
35
36 =over 2
37
38 =cut
39
40
41 use strict;
42 use C4::AuthoritiesMarc;
43 use C4::Auth;
44 use C4::Context;
45 use C4::Interface::CGI::Output;
46 use CGI;
47 use C4::Search;
48 use C4::Koha;
49
50
51 my $query=new CGI;
52
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);
58
59 my $xmlhash =XMLgetauthorityhash($dbh,$authid);
60
61 my ($count) = AUTHcount_usage($authid);
62
63 #chop;
64
65 # open template
66 my ($template, $loggedinuser, $cookie)
67                 = get_template_and_user({template_name => "authorities/detail.tmpl",
68                              query => $query,
69                              type => "intranet",
70                              authnotrequired => 0,
71                              flagsrequired => {catalogue => 1},
72                              debug => 1,
73                              });
74
75
76 # fill arrays
77 my @loop_data =();
78 my $tag;
79 if ($xmlhash){
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
86         my @loop_data =();
87         my @subfields_data;
88
89         # deal with leader 
90         unless (($tagslib->{'000'}->{'@'}->{tab}  ne $tabloop)  || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
91                 
92                 my %subfield_data;
93                 $subfield_data{marc_value}=$leader->[0] ;
94                 push(@subfields_data, \%subfield_data);
95                 my %tag_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;
101         }
102         ##Controlfields
103                 
104                  foreach my $control (@$controlfields){
105                         my %subfield_data;
106                         my %tag_data;
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};
113                                 } else {
114                                         $tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib};
115                                 }                       
116                         my @tmp = @subfields_data;
117                         $tag_data{subfield} = \@tmp;
118                         push (@loop_data, \%tag_data);
119                         undef @subfields_data;
120                 }
121         my $previoustag;
122         my %datatags;
123         my $i=0;
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);
130                         my %subfield_data;
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>";
136                         } else {
137                         $subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh);
138                         }
139                         $subfield_data{marc_subfield}=$code->{'code'};
140                         $subfield_data{marc_tag}=$data->{'tag'};
141                         push(@subfields_data, \%subfield_data);
142                      }### $code
143                 
144                 
145                 if ($#subfields_data>=0) {
146                         my %tag_data;
147                         if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) {
148                                 $tag_data{tag}="";
149                         } else {
150                                 if (C4::Context->preference('hide_marc')) {
151                                         $tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
152                                 } else {
153                                         $tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib};
154                                 }
155                         }
156                         my @tmp = @subfields_data;
157                         $tag_data{subfield} = \@tmp;
158                         push (@loop_data, \%tag_data);
159                         undef @subfields_data;
160                 }
161               }### each $subfield
162         }
163
164         $template->param($tabloop."XX" =>\@loop_data);
165 }
166 my $authtypes = getauthtypes;
167 my @authtypesloop;
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'},
173                         );
174         push @authtypesloop, \%row;
175 }
176
177 $template->param(authid => $authid,
178                                 count => $count,
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;
185
186 sub get_authorised_value_desc ($$$$$) {
187    my($tag, $subfield, $value, $framework, $dbh) = @_;
188
189    #---- branch
190     if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
191        return getbranchname($value);
192     }
193
194    #---- itemtypes
195    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
196        return ItemType($value);
197     }
198
199    #---- "true" authorized value
200    my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
201
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'};
207    } else {
208        return $value; # if nothing is found return the original value
209    }
210 }