Head & rel_2_2 merged
[koha.git] / authorities / detail-biblio-search.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 $index = $query->param('index');
62 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
63 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
64
65 my $record =AUTHgetauthority($dbh,$authid);
66 # open template
67 my ($template, $loggedinuser, $cookie)
68                 = get_template_and_user({template_name => "authorities/detail-biblio-search.tmpl",
69                              query => $query,
70                              type => "intranet",
71                              authnotrequired => 0,
72                              flagsrequired => {catalogue => 1},
73                              debug => 1,
74                              });
75
76 # fill arrays
77 my @loop_data =();
78 my $tag;
79 # loop through each tab 0 through 9
80 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
81 # loop through each tag
82         my @fields = $record->fields();
83         my @loop_data =();
84         foreach my $field (@fields) {
85                         my @subfields_data;
86                 # if tag <10, there's no subfield, use the "@" trick
87                 if ($field->tag()<10) {
88 #                       next if ($tagslib->{$field->tag()}->{'@'}->{tab}  ne $tabloop);
89                         next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
90                         my %subfield_data;
91                         $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
92                         $subfield_data{marc_value}=$field->data();
93                         $subfield_data{marc_subfield}='@';
94                         $subfield_data{marc_tag}=$field->tag();
95                         push(@subfields_data, \%subfield_data);
96                 } else {
97                         my @subf=$field->subfields;
98         # loop through each subfield
99                         for my $i (0..$#subf) {
100                                 $subf[$i][0] = "@" unless $subf[$i][0];
101 #                               next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne $tabloop);
102                                 next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
103                                 my %subfield_data;
104                                 $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
105                                 if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
106                                         $subfield_data{marc_value}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
107                                 } else {
108                                         $subfield_data{marc_value}=$subf[$i][1];
109                                 }
110                                 $subfield_data{marc_subfield}=$subf[$i][0];
111                                 $subfield_data{marc_tag}=$field->tag();
112                                 push(@subfields_data, \%subfield_data);
113                         }
114                 }
115                 if ($#subfields_data>=0) {
116                         my %tag_data;
117                         $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
118                         $tag_data{subfield} = \@subfields_data;
119                         push (@loop_data, \%tag_data);
120                 }
121         }
122         $template->param("0XX" =>\@loop_data);
123 # }
124 # now, build item tab !
125 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
126 # loop through each tag
127 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
128 # then construct template.
129 # my @fields = $record->fields();
130 # my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
131 # my @big_array;
132 # foreach my $field (@fields) {
133 #       next if ($field->tag()<10);
134 #       my @subf=$field->subfields;
135 #       my %this_row;
136 # # loop through each subfield
137 #       for my $i (0..$#subf) {
138 #               next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne 10);
139 #               $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
140 #               $this_row{$subf[$i][0]} =$subf[$i][1];
141 #       }
142 #       if (%this_row) {
143 #               push(@big_array, \%this_row);
144 #       }
145 # }
146 # #fill big_row with missing datas
147 # foreach my $subfield_code  (keys(%witness)) {
148 #       for (my $i=0;$i<=$#big_array;$i++) {
149 #               $big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
150 #       }
151 # }
152 # # now, construct template !
153 # my @item_value_loop;
154 # my @header_value_loop;
155 # for (my $i=0;$i<=$#big_array; $i++) {
156 #       my $items_data;
157 #       foreach my $subfield_code (keys(%witness)) {
158 #               $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
159 #       }
160 #       my %row_data;
161 #       $row_data{item_value} = $items_data;
162 #       push(@item_value_loop,\%row_data);
163 # }
164 # foreach my $subfield_code (keys(%witness)) {
165 #       my %header_value;
166 #       $header_value{header_value} = $witness{$subfield_code};
167 #       push(@header_value_loop, \%header_value);
168 # }
169
170 my $authtypes = getauthtypes;
171 my @authtypesloop;
172 foreach my $thisauthtype (keys %$authtypes) {
173         my $selected = 1 if $thisauthtype eq $authtypecode;
174         my %row =(value => $thisauthtype,
175                                 selected => $selected,
176                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
177                         );
178         push @authtypesloop, \%row;
179 }
180
181 $template->param(authid => $authid,
182                 authtypesloop => \@authtypesloop, index => $index,
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