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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
56 my $dbh = C4::Context->dbh;
58 my $biblionumber = $query->param('biblionumber');
59 my $itemtype = &GetFrameworkCode($biblionumber);
60 my $tagslib = &GetMarcStructure( 0, $itemtype );
61 my $biblio = GetBiblioData($biblionumber);
62 my $record = GetMarcBiblio($biblionumber);
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
67 template_name => "opac-MARCdetail.tmpl",
76 bibliotitle => $biblio->{title},
79 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
80 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
82 # adding the $RequestOnOpac param
84 if (C4::Context->preference("RequestOnOpac")) {
92 # loop through each tab 0 through 9
93 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
95 # loop through each tag
100 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
101 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
104 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
105 $subfield_data{marc_value} = $record->leader();
106 $subfield_data{marc_subfield} = '@';
107 $subfield_data{marc_tag} = '000';
108 push( @subfields_data, \%subfield_data );
110 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
111 my @tmp = @subfields_data;
112 $tag_data{subfield} = \@tmp;
113 push( @loop_data, \%tag_data );
114 undef @subfields_data;
116 my @fields = $record->fields();
117 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
119 # if tag <10, there's no subfield, use the "@" trick
120 if ( $fields[$x_i]->tag() < 10 ) {
123 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
124 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
126 $subfield_data{marc_lib} =
127 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
128 $subfield_data{marc_value} = $fields[$x_i]->data();
129 $subfield_data{marc_subfield} = '@';
130 $subfield_data{marc_tag} = $fields[$x_i]->tag();
131 push( @subfields_data, \%subfield_data );
134 my @subf = $fields[$x_i]->subfields;
136 # loop through each subfield
137 for my $i ( 0 .. $#subf ) {
138 $subf[$i][0] = "@" unless $subf[$i][0];
139 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
140 next if ( $sf_def->{tab} ne $tabloop );
141 next if ( $sf_def->{hidden} > 0 );
143 $subfield_data{marc_lib} = ($sf_def->{lib} eq $previous) ? '--' : $sf_def->{lib};
144 $previous = $sf_def->{lib};
145 $subfield_data{link} = $sf_def->{link};
146 $subf[$i][1] =~ s/\n/<br\/>/g;
147 if ( $sf_def->{isurl} ) {
148 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
150 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
151 $subfield_data{marc_value} = $subf[$i][1];
154 if ( $sf_def->{authtypecode} ) {
155 $subfield_data{authority} = $fields[$x_i]->subfield(9);
157 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
158 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
160 $subfield_data{marc_subfield} = $subf[$i][0];
161 $subfield_data{marc_tag} = $fields[$x_i]->tag();
162 push( @subfields_data, \%subfield_data );
165 if ( $#subfields_data >= 0 ) {
167 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
168 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
174 if ( C4::Context->preference('hide_marc') ) {
175 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
181 . C4::Koha::display_marc_indicators($fields[$x_i])
183 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
186 my @tmp = @subfields_data;
187 $tag_data{subfield} = \@tmp;
188 push( @loop_data, \%tag_data );
189 undef @subfields_data;
192 $template->param( $tabloop . "XX" => \@loop_data );
196 # now, build item tab !
197 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
198 # loop through each tag
199 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
200 # then construct template.
201 my @fields = $record->fields();
203 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
205 foreach my $field (@fields) {
206 next if ( $field->tag() < 10 );
207 my @subf = $field->subfields;
210 # loop through each subfield
211 for my $i ( 0 .. $#subf ) {
212 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
213 next if ( $sf_def->{tab} ne 10 );
214 next if ( $sf_def->{hidden} > 0 );
215 $witness{ $subf[$i][0] } = $sf_def->{lib};
217 if ( $sf_def->{isurl} ) {
218 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
220 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
221 $this_row{ $subf[$i][0] } = $subf[$i][1];
224 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
225 $subf[$i][1], '', $tagslib, '', 'opac' );
229 push( @big_array, \%this_row );
232 my ( $holdingbrtagf, $holdingbrtagsubf ) =
233 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
235 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
237 #fill big_row with missing datas
238 foreach my $subfield_code ( keys(%witness) ) {
239 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
240 $big_array[$i]{$subfield_code} = " "
241 unless ( $big_array[$i]{$subfield_code} );
245 # now, construct template !
247 my @header_value_loop;
248 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
250 foreach my $subfield_code ( keys(%witness) ) {
251 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
254 $row_data{item_value} = $items_data;
255 push( @item_value_loop, \%row_data );
258 foreach my $subfield_code ( keys(%witness) ) {
260 $header_value{header_value} = $witness{$subfield_code};
261 push( @header_value_loop, \%header_value );
264 if(C4::Context->preference("ISBD")) {
265 $template->param(ISBD => 1);
269 item_loop => \@item_value_loop,
270 item_header_loop => \@header_value_loop,
271 biblionumber => $biblionumber,
274 output_html_with_http_headers $query, $cookie, $template->output;