rel_3_0 moved to HEAD
[koha.git] / 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 require Exporter;
43 use C4::AuthoritiesMarc;
44 use C4::Auth;
45 use C4::Context;
46 use C4::Output;
47 use C4::Interface::CGI::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Koha;
51 # use C4::Biblio;
52 # use C4::Catalogue;
53
54
55 my $query=new CGI;
56
57 my $dbh=C4::Context->dbh;
58
59 # open template
60 my ($template, $loggedinuser, $cookie)
61                 = get_template_and_user({template_name => "authorities/detail.tmpl",
62                              query => $query,
63                              type => "intranet",
64                              authnotrequired => 0,
65                              flagsrequired => {catalogue => 1},
66                              debug => 1,
67                              });
68
69 my $authid = $query->param('authid');
70
71
72
73 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
74 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
75
76 my $record;
77 if (C4::Context->preference("AuthDisplayHierarchy")){
78   my $trees=BuildUnimarcHierarchies($authid);
79   my @trees = split /;/,$trees ;
80   push @trees,$trees unless (@trees);
81   my @loophierarchies;
82   foreach my $tree (@trees){
83     my @tree=split /,/,$tree;
84     push @tree,$tree unless (@tree);
85     my $cnt=0;
86     my @loophierarchy;
87     foreach my $element (@tree){
88       my %cell;
89       my $elementdata = AUTHgetauthority($dbh,$element);
90       $record= $elementdata if ($authid==$element);
91       push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid);
92       $cnt++;
93     }
94     push @loophierarchies, { 'loopelement' =>\@loophierarchy};
95   }
96   $template->param(
97     'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
98     'loophierarchies' =>\@loophierarchies,
99   );
100 } else {
101   $record=AUTHgetauthority($dbh,$authid);
102 }
103 my $count = AUTHcount_usage($authid);
104
105 # find the marc field/subfield used in biblio by this authority
106 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
107 $sth->execute($authtypecode);
108 my $biblio_fields;
109 while (my ($tagfield) = $sth->fetchrow) {
110         $biblio_fields.= $tagfield."9,";
111 }
112 chop $biblio_fields;
113
114
115 # fill arrays
116 my @loop_data =();
117 my $tag;
118 # loop through each tab 0 through 9
119 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
120 # loop through each tag
121 my @fields = $record->fields();
122 my @loop_data =();
123 foreach my $field (@fields) {
124                 my @subfields_data;
125         # if tag <10, there's no subfield, use the "@" trick
126         if ($field->tag()<10) {
127                 next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
128                 my %subfield_data;
129                 $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
130                 $subfield_data{marc_value}=$field->data();
131                 $subfield_data{marc_subfield}='@';
132                 $subfield_data{marc_tag}=$field->tag();
133                 push(@subfields_data, \%subfield_data);
134         } else {
135                 my @subf=$field->subfields;
136 # loop through each subfield
137                 for my $i (0..$#subf) {
138                         $subf[$i][0] = "@" unless $subf[$i][0];
139                         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
140                         my %subfield_data;
141                         $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
142                         if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
143                                 $subfield_data{marc_value}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
144                         } else {
145                                 $subfield_data{marc_value}=$subf[$i][1];
146                         }
147             $subfield_data{short_desc} = substr(
148                 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib},
149                 0, 20
150             );
151             $subfield_data{long_desc} =
152               $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
153                         $subfield_data{marc_subfield}=$subf[$i][0];
154                         $subfield_data{marc_tag}=$field->tag();
155                         push(@subfields_data, \%subfield_data);
156                 }
157         }
158         if ($#subfields_data>=0) {
159                 my %tag_data;
160                 $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
161                 $tag_data{subfield} = \@subfields_data;
162                 push (@loop_data, \%tag_data);
163         }
164 }
165 $template->param("0XX" =>\@loop_data);
166
167 my $authtypes = getauthtypes;
168 my @authtypesloop;
169 foreach my $thisauthtype (keys %$authtypes) {
170         my $selected = 1 if $thisauthtype eq $authtypecode;
171         my %row =(value => $thisauthtype,
172                                 selected => $selected,
173                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
174                         );
175         push @authtypesloop, \%row;
176 }
177
178 $template->param(authid => $authid,
179                 count => $count,
180                 biblio_fields => $biblio_fields,
181                 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
182                 authtypesloop => \@authtypesloop,
183                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
184                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
185                 IntranetNav => C4::Context->preference("IntranetNav"),
186                 );
187 output_html_with_http_headers $query, $cookie, $template->output;
188