added ability for the popup to close and the opening page to refresh once subscriptio...
[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 C4::Search;
50 use MARC::Record;
51 use C4::Koha;
52 # use C4::Biblio;
53 # use C4::Catalogue;
54 use HTML::Template;
55
56 my $query=new CGI;
57
58 my $dbh=C4::Context->dbh;
59
60 my $authid = $query->param('authid');
61 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
62 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
63
64 my $record =AUTHgetauthority($dbh,$authid);
65 my $count = AUTHcount_usage($authid);
66
67 # find the marc field/subfield used in biblio by this authority
68 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
69 $sth->execute($authtypecode);
70 my $biblio_fields;
71 while (my ($tagfield) = $sth->fetchrow) {
72         $biblio_fields.= $tagfield."9,";
73 }
74 chop $biblio_fields;
75
76 # open template
77 my ($template, $loggedinuser, $cookie)
78                 = get_template_and_user({template_name => "authorities/detail.tmpl",
79                              query => $query,
80                              type => "intranet",
81                              authnotrequired => 0,
82                              flagsrequired => {catalogue => 1},
83                              debug => 1,
84                              });
85
86 # fill arrays
87 my @loop_data =();
88 my $tag;
89 # loop through each tab 0 through 9
90 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
91 # loop through each tag
92 my @fields = $record->fields();
93 my @loop_data =();
94 foreach my $field (@fields) {
95                 my @subfields_data;
96         # if tag <10, there's no subfield, use the "@" trick
97         if ($field->tag()<10) {
98                 next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
99                 my %subfield_data;
100                 $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
101                 $subfield_data{marc_value}=$field->data();
102                 $subfield_data{marc_subfield}='@';
103                 $subfield_data{marc_tag}=$field->tag();
104                 push(@subfields_data, \%subfield_data);
105         } else {
106                 my @subf=$field->subfields;
107 # loop through each subfield
108                 for my $i (0..$#subf) {
109                         $subf[$i][0] = "@" unless $subf[$i][0];
110                         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
111                         my %subfield_data;
112                         $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
113                         if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
114                                 $subfield_data{marc_value}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
115                         } else {
116                                 $subfield_data{marc_value}=$subf[$i][1];
117                         }
118                         $subfield_data{marc_subfield}=$subf[$i][0];
119                         $subfield_data{marc_tag}=$field->tag();
120                         push(@subfields_data, \%subfield_data);
121                 }
122         }
123         if ($#subfields_data>=0) {
124                 my %tag_data;
125                 $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
126                 $tag_data{subfield} = \@subfields_data;
127                 push (@loop_data, \%tag_data);
128         }
129 }
130 $template->param("0XX" =>\@loop_data);
131
132 my $authtypes = getauthtypes;
133 my @authtypesloop;
134 foreach my $thisauthtype (keys %$authtypes) {
135         my $selected = 1 if $thisauthtype eq $authtypecode;
136         my %row =(value => $thisauthtype,
137                                 selected => $selected,
138                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
139                         );
140         push @authtypesloop, \%row;
141 }
142
143 $template->param(authid => $authid,
144                 count => $count,
145                 biblio_fields => $biblio_fields,
146                 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
147                 authtypesloop => \@authtypesloop,
148                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
149                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
150                 IntranetNav => C4::Context->preference("IntranetNav"),
151                 );
152 output_html_with_http_headers $query, $cookie, $template->output;
153