3 # This file is part of Koha.
5 # Copyright (C) 2000-2002 Katipo Communications
6 # Parts Copyright (C) 2010 BibLibre
7 # Parts Copyright (C) 2013 Mark Tompsett
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 opac-MARCdetail.pl : script to show a biblio in MARC format
33 This script needs a biblionumber as parameter
35 It shows the biblio in a (nice) MARC format depending on MARC
38 The template is in <templates_dir>/catalogue/MARCdetail.tt.
39 this template must be divided into 11 "tabs".
41 The first 10 tabs present the biblio, the 11th one presents
42 the items attached to the biblio
57 use List
::MoreUtils qw
/any/;
61 my $dbh = C4
::Context
->dbh;
63 my $biblionumber = $query->param('biblionumber');
64 if ( ! $biblionumber ) {
65 print $query->redirect("/cgi-bin/koha/errors/404.pl");
69 my @all_items = GetItemsInfo
($biblionumber);
71 if (scalar @all_items >= 1) {
72 push @items2hide, GetHiddenItemnumbers
(@all_items);
74 if (scalar @items2hide == scalar @all_items ) {
75 print $query->redirect("/cgi-bin/koha/errors/404.pl");
80 my $itemtype = &GetFrameworkCode
($biblionumber);
81 my $tagslib = &GetMarcStructure
( 0, $itemtype );
82 my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField
('items.itemnumber',$itemtype);
83 my $biblio = GetBiblioData
($biblionumber);
84 $biblionumber = $biblio->{biblionumber
};
85 my $record = GetMarcBiblio
($biblionumber, 1);
87 print $query->redirect("/cgi-bin/koha/errors/404.pl");
91 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
93 template_name
=> "opac-MARCdetail.tt",
96 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
102 bibliotitle
=> $biblio->{title
},
105 # get biblionumbers stored in the cart
108 if($query->cookie("bib_list")){
109 my $cart_list = $query->cookie("bib_list");
110 @cart_list = split(/\//, $cart_list);
111 if ( grep {$_ eq $biblionumber} @cart_list) {
112 $template->param( incart
=> 1 );
116 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
117 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
119 # adding the $RequestOnOpac param
121 if (C4
::Context
->preference("RequestOnOpac")) {
129 # loop through each tab 0 through 9
130 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
132 # loop through each tag
137 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
138 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
141 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
142 $subfield_data{marc_value
} = $record->leader();
143 $subfield_data{marc_subfield
} = '@';
144 $subfield_data{marc_tag
} = '000';
145 push( @subfields_data, \
%subfield_data );
147 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
148 my @tmp = @subfields_data;
149 $tag_data{subfield
} = \
@tmp;
150 push( @loop_data, \
%tag_data );
151 undef @subfields_data;
153 my @fields = $record->fields();
154 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
156 # if tag <10, there's no subfield, use the "@" trick
157 if ( $fields[$x_i]->tag() < 10 ) {
160 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
161 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
163 $subfield_data{marc_lib
} =
164 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
165 $subfield_data{marc_value
} = $fields[$x_i]->data();
166 $subfield_data{marc_subfield
} = '@';
167 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
168 push( @subfields_data, \
%subfield_data );
171 my @subf = $fields[$x_i]->subfields;
173 # loop through each subfield
174 for my $i ( 0 .. $#subf ) {
175 $subf[$i][0] = "@" unless defined($subf[$i][0]);
176 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
177 $sf_def = $sf_def->{ $subf[$i][0] } if defined($sf_def);
178 my ($tab,$hidden,$lib);
179 $tab = $sf_def->{tab
} if defined($sf_def);
180 $tab = $tab // int($fields[$x_i]->tag()/100);
181 $hidden = $sf_def->{hidden
} if defined($sf_def);
182 $hidden = $hidden // 0;
183 next if ( $tab != $tabloop );
184 next if ( $hidden > 0 );
186 $lib = $sf_def->{lib
} if defined($sf_def);
188 $subfield_data{marc_lib
} = ($lib eq $previous) ?
'--' : $lib;
190 $subfield_data{link} = $sf_def->{link};
191 $subf[$i][1] =~ s/\n/<br\/>/g
;
192 if ( $sf_def->{isurl
} ) {
193 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
195 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
196 $subfield_data{marc_value
} = $subf[$i][1];
199 if ( $sf_def->{authtypecode
} ) {
200 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
202 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
203 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
205 $subfield_data{marc_subfield
} = $subf[$i][0];
206 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
207 push( @subfields_data, \
%subfield_data );
210 if ( $#subfields_data >= 0 ) {
212 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
213 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
219 if ( C4
::Context
->preference('hide_marc') ) {
220 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
223 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
225 $lib = $sf_def->{lib
} if defined($sf_def);
227 $tag_data{tag
} = $fields[$x_i]->tag() . ' '
228 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
232 my @tmp = @subfields_data;
233 $tag_data{subfield
} = \
@tmp;
234 push( @loop_data, \
%tag_data );
235 undef @subfields_data;
238 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
242 # now, build item tab !
243 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
244 # loop through each tag
245 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
246 # then construct template.
247 my @fields = $record->fields();
249 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
251 foreach my $field (@fields) {
252 next if ( $field->tag() < 10 );
253 next if ( ( $field->tag() eq $tag_itemnumber ) &&
254 ( any
{ $field->subfield($subtag_itemnumber) eq $_ }
256 my @subf = $field->subfields;
259 # loop through each subfield
260 for my $i ( 0 .. $#subf ) {
261 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
262 next if ( ($sf_def->{tab
}||0) != 10 );
263 next if ( ($sf_def->{hidden
}||0) > 0 );
264 $witness{ $subf[$i][0] } = $sf_def->{lib
};
266 if ( $sf_def->{isurl
} ) {
267 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
269 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
270 $this_row{ $subf[$i][0] } = $subf[$i][1];
273 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
274 $subf[$i][1], '', $tagslib, '', 'opac' );
278 push( @big_array, \
%this_row );
281 my ( $holdingbrtagf, $holdingbrtagsubf ) =
282 &GetMarcFromKohaField
( "items.holdingbranch", $itemtype );
284 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
286 #fill big_row with missing datas
287 foreach my $subfield_code ( keys(%witness) ) {
288 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
289 $big_array[$i]{$subfield_code} = " "
290 unless ( $big_array[$i]{$subfield_code} );
294 # now, construct template !
296 my @header_value_loop;
297 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
299 foreach my $subfield_code ( keys(%witness) ) {
300 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
303 $row_data{item_value
} = $items_data;
304 push( @item_value_loop, \
%row_data );
307 foreach my $subfield_code ( keys(%witness) ) {
309 $header_value{header_value
} = $witness{$subfield_code};
310 push( @header_value_loop, \
%header_value );
313 if(C4
::Context
->preference("ISBD")) {
314 $template->param(ISBD
=> 1);
318 my $OpacExportOptions=C4
::Context
->preference("OpacExportOptions");
319 my @export_options = split(/\|/,$OpacExportOptions);
320 $template->{VARS
}->{'export_options'} = \
@export_options;
322 #Search for title in links
323 my $marcflavour = C4
::Context
->preference("marcflavour");
324 my $dat = TransformMarcToKoha
( $dbh, $record );
325 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
326 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
327 my $marcissns = GetMarcISSN
( $record, $marcflavour );
328 my $issn = $marcissns->[0] || '';
330 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
331 $dat->{title
} =~ s/\/+$//; # remove trailing slash
332 $dat->{title
} =~ s/\s+$//; # remove trailing space
333 $search_for_title = parametrized_url
(
336 TITLE
=> $dat->{title
},
337 AUTHOR
=> $dat->{author
},
340 CONTROLNUMBER
=> $marccontrolnumber,
341 BIBLIONUMBER
=> $biblionumber,
344 $template->param('OPACSearchForTitleIn' => $search_for_title);
348 item_loop
=> \
@item_value_loop,
349 item_header_loop
=> \
@header_value_loop,
350 biblionumber
=> $biblionumber,
353 output_html_with_http_headers
$query, $cookie, $template->output;