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