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
55 my $dbh = C4::Context->dbh;
57 my $biblionumber = $query->param('biblionumber');
58 my $itemtype = &GetFrameworkCode($biblionumber);
59 my $tagslib = &GetMarcStructure( 0, $itemtype );
60 my $biblio = GetBiblioData($biblionumber);
61 my $record = GetMarcBiblio($biblionumber);
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 template_name => "opac-MARCdetail.tmpl",
75 bibliotitle => $biblio->{title},
78 # adding the $RequestOnOpac param
80 if (C4::Context->preference("RequestOnOpac")) {
88 # loop through each tab 0 through 9
89 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
91 # loop through each tag
96 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
97 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
100 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
101 $subfield_data{marc_value} = $record->leader();
102 $subfield_data{marc_subfield} = '@';
103 $subfield_data{marc_tag} = '000';
104 push( @subfields_data, \%subfield_data );
106 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
107 my @tmp = @subfields_data;
108 $tag_data{subfield} = \@tmp;
109 push( @loop_data, \%tag_data );
110 undef @subfields_data;
112 my @fields = $record->fields();
113 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
115 # if tag <10, there's no subfield, use the "@" trick
116 if ( $fields[$x_i]->tag() < 10 ) {
119 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
120 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
122 $subfield_data{marc_lib} =
123 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
124 $subfield_data{marc_value} = $fields[$x_i]->data();
125 $subfield_data{marc_subfield} = '@';
126 $subfield_data{marc_tag} = $fields[$x_i]->tag();
127 push( @subfields_data, \%subfield_data );
130 my @subf = $fields[$x_i]->subfields;
132 # loop through each subfield
133 for my $i ( 0 .. $#subf ) {
134 $subf[$i][0] = "@" unless $subf[$i][0];
137 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
140 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
143 $subfield_data{marc_lib} =
144 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
145 $subfield_data{link} =
146 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
147 $subf[$i][1] =~ s/\n/<br\/>/g;
148 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
151 $subfield_data{marc_value} =
152 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
154 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
155 ->{kohafield} eq "biblioitems.isbn" )
158 # 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]);
159 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
162 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
165 $subfield_data{authority} = $fields[$x_i]->subfield(9);
167 $subfield_data{marc_value} =
168 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
169 $subf[$i][0], $subf[$i][1], '', $tagslib );
171 $subfield_data{marc_subfield} = $subf[$i][0];
172 $subfield_data{marc_tag} = $fields[$x_i]->tag();
173 push( @subfields_data, \%subfield_data );
176 if ( $#subfields_data >= 0 ) {
178 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
179 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
185 if ( C4::Context->preference('hide_marc') ) {
186 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
190 $fields[$x_i]->tag() . ' -'
191 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
194 my @tmp = @subfields_data;
195 $tag_data{subfield} = \@tmp;
196 push( @loop_data, \%tag_data );
197 undef @subfields_data;
200 $template->param( $tabloop . "XX" => \@loop_data );
204 # now, build item tab !
205 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
206 # loop through each tag
207 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
208 # then construct template.
209 my @fields = $record->fields();
211 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
213 foreach my $field (@fields) {
214 next if ( $field->tag() < 10 );
215 my @subf = $field->subfields;
218 # loop through each subfield
219 for my $i ( 0 .. $#subf ) {
220 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
221 $witness{ $subf[$i][0] } =
222 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
223 if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{isurl} ) {
224 $this_row{ $subf[$i][0] } =
225 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
227 elsif ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq
230 $this_row{ $subf[$i][0] } = DisplayISBN( $subf[$i][1] );
233 $this_row{ $subf[$i][0] } =
234 GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
235 $subf[$i][1], '', $tagslib );
239 push( @big_array, \%this_row );
242 my ( $holdingbrtagf, $holdingbrtagsubf ) =
243 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
245 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
247 #fill big_row with missing datas
248 foreach my $subfield_code ( keys(%witness) ) {
249 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
250 $big_array[$i]{$subfield_code} = " "
251 unless ( $big_array[$i]{$subfield_code} );
255 # now, construct template !
257 my @header_value_loop;
258 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
260 foreach my $subfield_code ( keys(%witness) ) {
261 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
264 $row_data{item_value} = $items_data;
265 push( @item_value_loop, \%row_data );
268 foreach my $subfield_code ( keys(%witness) ) {
270 $header_value{header_value} = $witness{$subfield_code};
271 push( @header_value_loop, \%header_value );
274 if(C4::Context->preference("ISBD")) {
275 $template->param(ISBD => 1);
279 item_loop => \@item_value_loop,
280 item_header_loop => \@header_value_loop,
281 biblionumber => $biblionumber,
284 output_html_with_http_headers $query, $cookie, $template->output;