Several changes: - add check in link to circulation checkouts listing
[koha.git] / opac / opac-authoritiesdetail.pl
blobaa39e0532880400c0cc543c5bf062cf4b30dfe2f
1 #!/usr/bin/perl
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
10 # version.
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
20 =head1 NAME
22 opac-authoritiesdetail.pl : script to show an authority in MARC format
24 =head1 SYNOPSIS
27 =head1 DESCRIPTION
29 This script needs an authid
31 It shows the authority in a (nice) MARC format depending on authority MARC
32 parameters tables.
34 =head1 FUNCTIONS
36 =over 2
38 =cut
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;
51 my $query = new CGI;
53 my $dbh = C4::Context->dbh;
55 my $authid = $query->param('authid');
56 my $authtypecode = &GetAuthTypeCode( $authid );
57 my $tagslib = &GetTagsLabels( 1, $authtypecode );
59 # open template
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "opac-authoritiesdetail.tmpl",
63 query => $query,
64 type => "opac",
65 authnotrequired => 1,
66 debug => 1,
70 my $record;
71 if (C4::Context->preference("AuthDisplayHierarchy")){
72 my $trees=BuildUnimarcHierarchies($authid);
73 my @trees = split /;/,$trees ;
74 push @trees,$trees unless (@trees);
75 my @loophierarchies;
76 foreach my $tree (@trees){
77 my @tree=split /,/,$tree;
78 push @tree,$tree unless (@tree);
79 my $cnt=0;
80 my @loophierarchy;
81 foreach my $element (@tree){
82 my $cell;
83 my $elementdata = GetAuthority($element);
84 $record= $elementdata if ($authid==$element);
85 push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid);
86 $cnt++;
88 push @loophierarchies, { 'loopelement' =>\@loophierarchy};
90 $template->param(
91 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
92 'loophierarchies' =>\@loophierarchies,
95 else {
96 $record = GetAuthority( $authid );
98 my $count = CountUsage($authid);
100 # find the marc field/subfield used in biblio by this authority
101 my $sth =
102 $dbh->prepare(
103 "select distinct tagfield from marc_subfield_structure where authtypecode=?"
105 $sth->execute($authtypecode);
106 my $biblio_fields;
107 while ( my ($tagfield) = $sth->fetchrow ) {
108 $biblio_fields .= $tagfield . "9,";
110 chop $biblio_fields;
112 # fill arrays
113 my @loop_data = ();
114 my $tag;
116 # loop through each tab 0 through 9
117 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
118 # loop through each tag
119 my @fields = $record->fields();
120 foreach my $field (@fields) {
121 my @subfields_data;
123 # if tag <10, there's no subfield, use the "@" trick
124 if ( $field->tag() < 10 ) {
125 next if ( $tagslib->{ $field->tag() }->{'@'}->{hidden} );
126 my %subfield_data;
127 $subfield_data{marc_lib} = $tagslib->{ $field->tag() }->{'@'}->{lib};
128 $subfield_data{marc_value} = $field->data();
129 $subfield_data{marc_subfield} = '@';
130 $subfield_data{marc_tag} = $field->tag();
131 push( @subfields_data, \%subfield_data );
133 else {
134 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} =
142 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
143 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
144 $subfield_data{marc_value} =
145 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
147 else {
148 $subfield_data{marc_value} = $subf[$i][1];
150 $subfield_data{marc_subfield} = $subf[$i][0];
151 $subfield_data{marc_tag} = $field->tag();
152 push( @subfields_data, \%subfield_data );
155 if ( $#subfields_data >= 0 ) {
156 my %tag_data;
157 $tag_data{tag} =
158 $field->tag() . ' -' . $tagslib->{ $field->tag() }->{lib};
159 $tag_data{subfield} = \@subfields_data;
160 push( @loop_data, \%tag_data );
163 $template->param( "0XX" => \@loop_data );
165 my $authtypes = getauthtypes;
166 my @authtypesloop;
167 foreach my $thisauthtype ( keys %$authtypes ) {
168 my $selected = 1 if $thisauthtype eq $authtypecode;
169 my %row = (
170 value => $thisauthtype,
171 selected => $selected,
172 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
174 push @authtypesloop, \%row;
177 $template->param(
178 authid => $authid,
179 count => $count,
180 biblio_fields => $biblio_fields,
181 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
182 authtypesloop => \@authtypesloop,
183 LibraryName => C4::Context->preference("LibraryName"),
184 OpacNav => C4::Context->preference("OpacNav"),
185 opaccredits => C4::Context->preference("opaccredits"),
186 opacsmallimage => C4::Context->preference("opacsmallimage"),
187 opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
188 opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
190 output_html_with_http_headers $query, $cookie, $template->output;