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
54 my $dbh = C4::Context->dbh;
56 my $biblionumber = $query->param('biblionumber');
57 my $itemtype = &GetFrameworkCode($biblionumber);
58 my $tagslib = &GetMarcStructure( 0, $itemtype );
59 my $biblio = GetBiblioData($biblionumber);
60 my $record = GetMarcBiblio($biblionumber);
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "opac-MARCdetail.tmpl",
74 bibliotitle => $biblio->{title},
77 # adding the $RequestOnOpac param
79 if (C4::Context->preference("RequestOnOpac")) {
87 # loop through each tab 0 through 9
88 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
90 # loop through each tag
95 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
96 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
99 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
100 $subfield_data{marc_value} = $record->leader();
101 $subfield_data{marc_subfield} = '@';
102 $subfield_data{marc_tag} = '000';
103 push( @subfields_data, \%subfield_data );
105 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
106 my @tmp = @subfields_data;
107 $tag_data{subfield} = \@tmp;
108 push( @loop_data, \%tag_data );
109 undef @subfields_data;
111 my @fields = $record->fields();
112 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
114 # if tag <10, there's no subfield, use the "@" trick
115 if ( $fields[$x_i]->tag() < 10 ) {
118 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
119 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
121 $subfield_data{marc_lib} =
122 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
123 $subfield_data{marc_value} = $fields[$x_i]->data();
124 $subfield_data{marc_subfield} = '@';
125 $subfield_data{marc_tag} = $fields[$x_i]->tag();
126 push( @subfields_data, \%subfield_data );
129 my @subf = $fields[$x_i]->subfields;
131 # loop through each subfield
132 for my $i ( 0 .. $#subf ) {
133 $subf[$i][0] = "@" unless $subf[$i][0];
136 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
139 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{hidden} > 0 );
141 $subfield_data{marc_lib} =
142 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
143 $subfield_data{link} =
144 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
145 $subf[$i][1] =~ s/\n/<br\/>/g;
146 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
149 $subfield_data{marc_value} =
150 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
152 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
153 ->{kohafield} eq "biblioitems.isbn" )
156 # 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]);
157 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
160 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
163 $subfield_data{authority} = $fields[$x_i]->subfield(9);
165 $subfield_data{marc_value} =
166 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
167 $subf[$i][0], $subf[$i][1], '', $tagslib );
169 $subfield_data{marc_subfield} = $subf[$i][0];
170 $subfield_data{marc_tag} = $fields[$x_i]->tag();
171 push( @subfields_data, \%subfield_data );
174 if ( $#subfields_data >= 0 ) {
176 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
177 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
183 if ( C4::Context->preference('hide_marc') ) {
184 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
190 . C4::Koha::display_marc_indicators($fields[$x_i])
192 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
195 my @tmp = @subfields_data;
196 $tag_data{subfield} = \@tmp;
197 push( @loop_data, \%tag_data );
198 undef @subfields_data;
201 $template->param( $tabloop . "XX" => \@loop_data );
205 # now, build item tab !
206 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
207 # loop through each tag
208 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
209 # then construct template.
210 my @fields = $record->fields();
212 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
214 foreach my $field (@fields) {
215 next if ( $field->tag() < 10 );
216 my @subf = $field->subfields;
219 # loop through each subfield
220 for my $i ( 0 .. $#subf ) {
221 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
222 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} > 0 );
223 $witness{ $subf[$i][0] } =
224 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
226 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
227 $this_row{ $subf[$i][0] } =
228 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
230 elsif ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq
233 $this_row{ $subf[$i][0] } = DisplayISBN( $subf[$i][1] );
236 $this_row{ $subf[$i][0] } =
237 GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
238 $subf[$i][1], '', $tagslib );
242 push( @big_array, \%this_row );
245 my ( $holdingbrtagf, $holdingbrtagsubf ) =
246 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
248 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
250 #fill big_row with missing datas
251 foreach my $subfield_code ( keys(%witness) ) {
252 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
253 $big_array[$i]{$subfield_code} = " "
254 unless ( $big_array[$i]{$subfield_code} );
258 # now, construct template !
260 my @header_value_loop;
261 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
263 foreach my $subfield_code ( keys(%witness) ) {
264 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
267 $row_data{item_value} = $items_data;
268 push( @item_value_loop, \%row_data );
271 foreach my $subfield_code ( keys(%witness) ) {
273 $header_value{header_value} = $witness{$subfield_code};
274 push( @header_value_loop, \%header_value );
277 if(C4::Context->preference("ISBD")) {
278 $template->param(ISBD => 1);
282 item_loop => \@item_value_loop,
283 item_header_loop => \@header_value_loop,
284 biblionumber => $biblionumber,
287 output_html_with_http_headers $query, $cookie, $template->output;