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
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
22 MARCdetail.pl : script to show a biblio in MARC format
29 This script needs a biblionumber as parameter
31 It shows the biblio in a (nice) MARC format depending on MARC
34 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
35 this template must be divided into 11 "tabs".
37 The first 10 tabs present the biblio, the 11th one presents
38 the items attached to the biblio
47 use C4::Interface::CGI::Output;
56 my $dbh = C4::Context->dbh;
58 my $biblionumber = $query->param('biblionumber');
59 my $itemtype = &MARCfind_frameworkcode($biblionumber);
60 my $tagslib = &MARCgettagslib( $dbh, 0, $itemtype );
62 my $record = GetMarcBiblio($biblionumber);
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
67 template_name => "opac-MARCdetail.tmpl",
74 # adding the $RequestOnOpac param
76 if (C4::Context->preference("RequestOnOpac")) {
84 # loop through each tab 0 through 9
85 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
87 # loop through each tag
92 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
93 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
96 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
97 $subfield_data{marc_value} = $record->leader();
98 $subfield_data{marc_subfield} = '@';
99 $subfield_data{marc_tag} = '000';
100 push( @subfields_data, \%subfield_data );
102 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
103 my @tmp = @subfields_data;
104 $tag_data{subfield} = \@tmp;
105 push( @loop_data, \%tag_data );
106 undef @subfields_data;
108 my @fields = $record->fields();
109 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
111 # if tag <10, there's no subfield, use the "@" trick
112 if ( $fields[$x_i]->tag() < 10 ) {
115 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
116 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
118 $subfield_data{marc_lib} =
119 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
120 $subfield_data{marc_value} = $fields[$x_i]->data();
121 $subfield_data{marc_subfield} = '@';
122 $subfield_data{marc_tag} = $fields[$x_i]->tag();
123 push( @subfields_data, \%subfield_data );
126 my @subf = $fields[$x_i]->subfields;
128 # loop through each subfield
129 for my $i ( 0 .. $#subf ) {
130 $subf[$i][0] = "@" unless $subf[$i][0];
133 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
136 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
139 $subfield_data{marc_lib} =
140 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
141 $subfield_data{link} =
142 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
143 $subf[$i][1] =~ s/\n/<br\/>/g;
144 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
147 $subfield_data{marc_value} =
148 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
150 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
151 ->{kohafield} eq "biblioitems.isbn" )
154 # warn " tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}. "ISBN : ".$subf[$i][1]."PosttraitementISBN :".DisplayISBN($subf[$i][1]);
155 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
158 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
161 $subfield_data{authority} = $fields[$x_i]->subfield(9);
163 $subfield_data{marc_value} =
164 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
165 $subf[$i][0], $subf[$i][1], '', $tagslib );
167 $subfield_data{marc_subfield} = $subf[$i][0];
168 $subfield_data{marc_tag} = $fields[$x_i]->tag();
169 push( @subfields_data, \%subfield_data );
172 if ( $#subfields_data >= 0 ) {
174 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
175 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
181 if ( C4::Context->preference('hide_marc') ) {
182 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
186 $fields[$x_i]->tag() . ' -'
187 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
190 my @tmp = @subfields_data;
191 $tag_data{subfield} = \@tmp;
192 push( @loop_data, \%tag_data );
193 undef @subfields_data;
196 $template->param( $tabloop . "XX" => \@loop_data );
200 # now, build item tab !
201 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
202 # loop through each tag
203 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
204 # then construct template.
205 my @fields = $record->fields();
207 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
209 foreach my $field (@fields) {
210 next if ( $field->tag() < 10 );
211 my @subf = $field->subfields;
214 # loop through each subfield
215 for my $i ( 0 .. $#subf ) {
216 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
217 $witness{ $subf[$i][0] } =
218 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
219 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
220 $this_row{ $subf[$i][0] } =
221 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
223 elsif ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq
226 $this_row{ $subf[$i][0] } = DisplayISBN( $subf[$i][1] );
229 $this_row{ $subf[$i][0] } =
230 GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
231 $subf[$i][1], '', $tagslib );
235 push( @big_array, \%this_row );
238 my ( $holdingbrtagf, $holdingbrtagsubf ) =
239 &MARCfind_marc_from_kohafield( $dbh, "items.holdingbranch", $itemtype );
241 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
243 #fill big_row with missing datas
244 foreach my $subfield_code ( keys(%witness) ) {
245 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
246 $big_array[$i]{$subfield_code} = " "
247 unless ( $big_array[$i]{$subfield_code} );
251 # now, construct template !
253 my @header_value_loop;
254 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
256 foreach my $subfield_code ( keys(%witness) ) {
257 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
260 $row_data{item_value} = $items_data;
261 push( @item_value_loop, \%row_data );
264 foreach my $subfield_code ( keys(%witness) ) {
266 $header_value{header_value} = $witness{$subfield_code};
267 push( @header_value_loop, \%header_value );
270 if(C4::Context->preference("ISBD")) {
271 $template->param(ISBD => 1);
275 item_loop => \@item_value_loop,
276 item_header_loop => \@header_value_loop,
277 biblionumber => $biblionumber,
280 output_html_with_http_headers $query, $cookie, $template->output;