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
59 use List::MoreUtils qw( any uniq );
61 use Koha::IssuingRules;
65 use Koha::RecordProcessor;
69 my $dbh = C4::Context->dbh;
71 my $biblionumber = $query->param('biblionumber');
72 if ( ! $biblionumber ) {
73 print $query->redirect("/cgi-bin/koha/errors/404.pl");
77 my $record = GetMarcBiblio({
78 biblionumber => $biblionumber,
81 print $query->redirect("/cgi-bin/koha/errors/404.pl");
85 my @all_items = GetItemsInfo($biblionumber);
87 if (scalar @all_items >= 1) {
89 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
91 # we need to fetch the borrower info here, so we can pass the category
92 my $borrower = GetMember( borrowernumber => $borrowernumber );
93 $borcat = $borrower->{categorycode};
95 push @items2hide, GetHiddenItemnumbers({ items => \@all_items, borcat => $botcat });
97 if (scalar @items2hide == scalar @all_items ) {
98 print $query->redirect("/cgi-bin/koha/errors/404.pl");
103 my $framework = &GetFrameworkCode( $biblionumber );
104 my $tagslib = &GetMarcStructure( 0, $framework );
105 my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
106 my $biblio = Koha::Biblios->find( $biblionumber );
108 my $record_processor = Koha::RecordProcessor->new({
109 filters => 'ViewPolicy',
112 frameworkcode => $framework
115 $record_processor->process($record);
118 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
120 template_name => "opac-MARCdetail.tt",
123 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
128 my ($bt_tag,$bt_subtag) = GetMarcFromKohaField('biblio.title',$framework);
130 bibliotitle => $biblio->title,
131 ) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
132 $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8;
134 # get biblionumbers stored in the cart
135 if(my $cart_list = $query->cookie("bib_list")){
136 my @cart_list = split(/\//, $cart_list);
137 if ( grep {$_ eq $biblionumber} @cart_list) {
138 $template->param( incart => 1 );
142 my $allow_onshelf_holds;
143 my $patron = Koha::Patrons->find( $loggedinuser );
144 for my $itm (@all_items) {
145 my $item = Koha::Items->find( $itm->{itemnumber} );
146 $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
147 last if $allow_onshelf_holds;
150 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
151 $template->param( ReservableItems => 1 );
154 # adding the $RequestOnOpac param
156 if (C4::Context->preference("RequestOnOpac")) {
164 # loop through each tab 0 through 9
165 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
167 # loop through each tag
172 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
173 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
176 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
177 $subfield_data{marc_value} = $record->leader();
178 $subfield_data{marc_subfield} = '@';
179 $subfield_data{marc_tag} = '000';
180 push( @subfields_data, \%subfield_data );
182 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
183 my @tmp = @subfields_data;
184 $tag_data{subfield} = \@tmp;
185 push( @loop_data, \%tag_data );
186 undef @subfields_data;
188 my @fields = $record->fields();
189 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
191 # if tag <10, there's no subfield, use the "@" trick
192 if ( $fields[$x_i]->tag() < 10 ) {
195 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
196 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
198 $subfield_data{marc_lib} =
199 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
200 $subfield_data{marc_value} = $fields[$x_i]->data();
201 $subfield_data{marc_subfield} = '@';
202 $subfield_data{marc_tag} = $fields[$x_i]->tag();
203 push( @subfields_data, \%subfield_data );
206 my @subf = $fields[$x_i]->subfields;
208 # loop through each subfield
209 for my $i ( 0 .. $#subf ) {
210 $subf[$i][0] = "@" unless defined($subf[$i][0]);
211 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
212 $sf_def = $sf_def->{ $subf[$i][0] } if defined($sf_def);
213 my ($tab,$hidden,$lib);
214 $tab = $sf_def->{tab} if defined($sf_def);
215 $tab = $tab // int($fields[$x_i]->tag()/100);
216 $hidden = $sf_def->{hidden} if defined($sf_def);
217 $hidden = $hidden // 0;
218 next if ( $tab != $tabloop );
219 next if ( $hidden > 0 );
221 $lib = $sf_def->{lib} if defined($sf_def);
223 $subfield_data{marc_lib} = ($lib eq $previous) ? '--' : $lib;
225 $subfield_data{link} = $sf_def->{link};
226 $subf[$i][1] =~ s/\n/<br\/>/g;
227 if ( $sf_def->{isurl} ) {
228 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
230 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
231 $subfield_data{marc_value} = $subf[$i][1];
234 if ( $sf_def->{authtypecode} ) {
235 $subfield_data{authority} = $fields[$x_i]->subfield(9);
237 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
238 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
240 $subfield_data{marc_subfield} = $subf[$i][0];
241 $subfield_data{marc_tag} = $fields[$x_i]->tag();
242 push( @subfields_data, \%subfield_data );
245 if ( $#subfields_data >= 0 ) {
247 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
248 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
254 if ( C4::Context->preference('hide_marc') ) {
255 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
258 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
260 $lib = $sf_def->{lib} if defined($sf_def);
262 $tag_data{tag} = $fields[$x_i]->tag() . ' '
263 . C4::Koha::display_marc_indicators($fields[$x_i])
267 my @tmp = @subfields_data;
268 $tag_data{subfield} = \@tmp;
269 push( @loop_data, \%tag_data );
270 undef @subfields_data;
273 $template->param( "tab" . $tabloop . "XX" => \@loop_data );
277 # now, build item tab !
278 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
279 # loop through each tag
280 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
281 # then construct template.
282 my @fields = $record->fields();
284 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
285 my @item_subfield_codes;
287 foreach my $field (@fields) {
288 next if ( $field->tag() < 10 );
289 next if ( ( $field->tag() eq $tag_itemnumber ) &&
290 ( any { $field->subfield($subtag_itemnumber) eq $_ }
292 my @subf = $field->subfields;
295 # loop through each subfield
296 for my $i ( 0 .. $#subf ) {
297 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
298 next if ( ($sf_def->{tab}||0) != 10 );
299 next if ( ($sf_def->{hidden}||0) > 0 );
300 push @item_subfield_codes, $subf[$i][0];
301 $witness{ $subf[$i][0] } = $sf_def->{lib};
303 if ( $sf_def->{isurl} ) {
304 $item->{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
306 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
307 $item->{ $subf[$i][0] } = $subf[$i][1];
310 $item->{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
311 $subf[$i][1], '', $tagslib, '', 'opac' );
314 push @item_loop, $item if $item;
316 my ( $holdingbrtagf, $holdingbrtagsubf ) =
317 &GetMarcFromKohaField( "items.holdingbranch", $framework );
319 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @item_loop;
321 @item_subfield_codes = uniq @item_subfield_codes;
323 my @item_header_loop;
324 for my $subfield_code ( @item_subfield_codes ) {
325 push @item_header_loop, $witness{$subfield_code};
326 for my $item_data ( @item_loop ) {
327 $item_data->{$subfield_code} ||= " "
331 if ( C4::Context->preference("OPACISBD") ) {
332 $template->param( ISBD => 1 );
335 #Search for title in links
336 my $marcflavour = C4::Context->preference("marcflavour");
337 my $dat = TransformMarcToKoha( $record );
338 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
339 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
340 my $marcissns = GetMarcISSN( $record, $marcflavour );
341 my $issn = $marcissns->[0] || '';
343 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
344 $dat->{title} =~ s/\/+$//; # remove trailing slash
345 $dat->{title} =~ s/\s+$//; # remove trailing space
346 $search_for_title = parametrized_url(
349 TITLE => $dat->{title},
350 AUTHOR => $dat->{author},
353 CONTROLNUMBER => $marccontrolnumber,
354 BIBLIONUMBER => $biblionumber,
357 $template->param('OPACSearchForTitleIn' => $search_for_title);
360 if( C4::Context->preference('ArticleRequests') ) {
361 my $artreqpossible = $patron
362 ? $biblio->can_article_request( $patron )
363 : Koha::ItemTypes->find($biblio->itemtype)->may_article_request;
364 $template->param( artreqpossible => $artreqpossible );
368 item_loop => \@item_loop,
369 item_header_loop => \@item_header_loop,
370 item_subfield_codes => \@item_subfield_codes,
374 output_html_with_http_headers $query, $cookie, $template->output;