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);
64 print $query->redirect("/cgi-bin/koha/errors/404.pl");
68 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
70 template_name
=> "opac-MARCdetail.tmpl",
79 bibliotitle
=> $biblio->{title
},
82 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
83 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
85 # adding the $RequestOnOpac param
87 if (C4
::Context
->preference("RequestOnOpac")) {
95 # loop through each tab 0 through 9
96 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
98 # loop through each tag
103 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
104 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
107 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
108 $subfield_data{marc_value
} = $record->leader();
109 $subfield_data{marc_subfield
} = '@';
110 $subfield_data{marc_tag
} = '000';
111 push( @subfields_data, \
%subfield_data );
113 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
114 my @tmp = @subfields_data;
115 $tag_data{subfield
} = \
@tmp;
116 push( @loop_data, \
%tag_data );
117 undef @subfields_data;
119 my @fields = $record->fields();
120 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
122 # if tag <10, there's no subfield, use the "@" trick
123 if ( $fields[$x_i]->tag() < 10 ) {
126 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
127 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
129 $subfield_data{marc_lib
} =
130 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
131 $subfield_data{marc_value
} = $fields[$x_i]->data();
132 $subfield_data{marc_subfield
} = '@';
133 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
134 push( @subfields_data, \
%subfield_data );
137 my @subf = $fields[$x_i]->subfields;
139 # loop through each subfield
140 for my $i ( 0 .. $#subf ) {
141 $subf[$i][0] = "@" unless $subf[$i][0];
142 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
143 next if ( $sf_def->{tab
} ne $tabloop );
144 next if ( $sf_def->{hidden
} > 0 );
146 $subfield_data{marc_lib
} = ($sf_def->{lib
} eq $previous) ?
'--' : $sf_def->{lib
};
147 $previous = $sf_def->{lib
};
148 $subfield_data{link} = $sf_def->{link};
149 $subf[$i][1] =~ s/\n/<br\/>/g
;
150 if ( $sf_def->{isurl
} ) {
151 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
153 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
154 $subfield_data{marc_value
} = $subf[$i][1];
157 if ( $sf_def->{authtypecode
} ) {
158 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
160 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
161 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
163 $subfield_data{marc_subfield
} = $subf[$i][0];
164 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
165 push( @subfields_data, \
%subfield_data );
168 if ( $#subfields_data >= 0 ) {
170 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
171 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
177 if ( C4
::Context
->preference('hide_marc') ) {
178 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
184 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
186 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
189 my @tmp = @subfields_data;
190 $tag_data{subfield
} = \
@tmp;
191 push( @loop_data, \
%tag_data );
192 undef @subfields_data;
195 $template->param( $tabloop . "XX" => \
@loop_data );
199 # now, build item tab !
200 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
201 # loop through each tag
202 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
203 # then construct template.
204 my @fields = $record->fields();
206 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
208 foreach my $field (@fields) {
209 next if ( $field->tag() < 10 );
210 my @subf = $field->subfields;
213 # loop through each subfield
214 for my $i ( 0 .. $#subf ) {
215 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
216 next if ( $sf_def->{tab
} ne 10 );
217 next if ( $sf_def->{hidden
} > 0 );
218 $witness{ $subf[$i][0] } = $sf_def->{lib
};
220 if ( $sf_def->{isurl
} ) {
221 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
223 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
224 $this_row{ $subf[$i][0] } = $subf[$i][1];
227 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
228 $subf[$i][1], '', $tagslib, '', 'opac' );
232 push( @big_array, \
%this_row );
235 my ( $holdingbrtagf, $holdingbrtagsubf ) =
236 &GetMarcFromKohaField
( "items.holdingbranch", $itemtype );
238 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
240 #fill big_row with missing datas
241 foreach my $subfield_code ( keys(%witness) ) {
242 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
243 $big_array[$i]{$subfield_code} = " "
244 unless ( $big_array[$i]{$subfield_code} );
248 # now, construct template !
250 my @header_value_loop;
251 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
253 foreach my $subfield_code ( keys(%witness) ) {
254 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
257 $row_data{item_value
} = $items_data;
258 push( @item_value_loop, \
%row_data );
261 foreach my $subfield_code ( keys(%witness) ) {
263 $header_value{header_value
} = $witness{$subfield_code};
264 push( @header_value_loop, \
%header_value );
267 if(C4
::Context
->preference("ISBD")) {
268 $template->param(ISBD
=> 1);
272 item_loop
=> \
@item_value_loop,
273 item_header_loop
=> \
@header_value_loop,
274 biblionumber
=> $biblionumber,
277 output_html_with_http_headers
$query, $cookie, $template->output;