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