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 );
62 use Koha
::RecordProcessor
;
66 my $dbh = C4
::Context
->dbh;
68 my $biblionumber = $query->param('biblionumber');
69 if ( ! $biblionumber ) {
70 print $query->redirect("/cgi-bin/koha/errors/404.pl");
74 my $record = GetMarcBiblio
($biblionumber, 1);
76 print $query->redirect("/cgi-bin/koha/errors/404.pl");
80 my @all_items = GetItemsInfo
($biblionumber);
82 if (scalar @all_items >= 1) {
83 push @items2hide, GetHiddenItemnumbers
(@all_items);
85 if (scalar @items2hide == scalar @all_items ) {
86 print $query->redirect("/cgi-bin/koha/errors/404.pl");
91 my $framework = &GetFrameworkCode
( $biblionumber );
92 my $tagslib = &GetMarcStructure
( 0, $framework );
93 my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField
('items.itemnumber',$framework);
94 my $biblio = Koha
::Biblios
->find( $biblionumber );
96 my $record_processor = Koha
::RecordProcessor
->new({
97 filters
=> 'ViewPolicy',
100 frameworkcode
=> $framework
103 $record_processor->process($record);
106 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
108 template_name
=> "opac-MARCdetail.tt",
111 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
116 my ($bt_tag,$bt_subtag) = GetMarcFromKohaField
('biblio.title',$framework);
118 bibliotitle
=> $biblio->title,
119 ) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden
} <= 0 && # <=0 OPAC visible.
120 $tagslib->{$bt_tag}->{$bt_subtag}->{hidden
} > -8; # except -8;
122 # get biblionumbers stored in the cart
123 if(my $cart_list = $query->cookie("bib_list")){
124 my @cart_list = split(/\//, $cart_list);
125 if ( grep {$_ eq $biblionumber} @cart_list) {
126 $template->param( incart
=> 1 );
130 my $allow_onshelf_holds;
131 my $patron = Koha
::Patrons
->find( $loggedinuser );
132 for my $itm (@all_items) {
133 $allow_onshelf_holds = C4
::Reserves
::OnShelfHoldsAllowed
( $itm, ( $patron ?
$patron->unblessed : {} ) );
134 last if $allow_onshelf_holds;
137 $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
138 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
140 # adding the $RequestOnOpac param
142 if (C4
::Context
->preference("RequestOnOpac")) {
150 # loop through each tab 0 through 9
151 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
153 # loop through each tag
158 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
159 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
162 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
163 $subfield_data{marc_value
} = $record->leader();
164 $subfield_data{marc_subfield
} = '@';
165 $subfield_data{marc_tag
} = '000';
166 push( @subfields_data, \
%subfield_data );
168 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
169 my @tmp = @subfields_data;
170 $tag_data{subfield
} = \
@tmp;
171 push( @loop_data, \
%tag_data );
172 undef @subfields_data;
174 my @fields = $record->fields();
175 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
177 # if tag <10, there's no subfield, use the "@" trick
178 if ( $fields[$x_i]->tag() < 10 ) {
181 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
182 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
184 $subfield_data{marc_lib
} =
185 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
186 $subfield_data{marc_value
} = $fields[$x_i]->data();
187 $subfield_data{marc_subfield
} = '@';
188 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
189 push( @subfields_data, \
%subfield_data );
192 my @subf = $fields[$x_i]->subfields;
194 # loop through each subfield
195 for my $i ( 0 .. $#subf ) {
196 $subf[$i][0] = "@" unless defined($subf[$i][0]);
197 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
198 $sf_def = $sf_def->{ $subf[$i][0] } if defined($sf_def);
199 my ($tab,$hidden,$lib);
200 $tab = $sf_def->{tab
} if defined($sf_def);
201 $tab = $tab // int($fields[$x_i]->tag()/100);
202 $hidden = $sf_def->{hidden
} if defined($sf_def);
203 $hidden = $hidden // 0;
204 next if ( $tab != $tabloop );
205 next if ( $hidden > 0 );
207 $lib = $sf_def->{lib
} if defined($sf_def);
209 $subfield_data{marc_lib
} = ($lib eq $previous) ?
'--' : $lib;
211 $subfield_data{link} = $sf_def->{link};
212 $subf[$i][1] =~ s/\n/<br\/>/g
;
213 if ( $sf_def->{isurl
} ) {
214 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
216 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
217 $subfield_data{marc_value
} = $subf[$i][1];
220 if ( $sf_def->{authtypecode
} ) {
221 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
223 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
224 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
226 $subfield_data{marc_subfield
} = $subf[$i][0];
227 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
228 push( @subfields_data, \
%subfield_data );
231 if ( $#subfields_data >= 0 ) {
233 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
234 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
240 if ( C4
::Context
->preference('hide_marc') ) {
241 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
244 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
246 $lib = $sf_def->{lib
} if defined($sf_def);
248 $tag_data{tag
} = $fields[$x_i]->tag() . ' '
249 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
253 my @tmp = @subfields_data;
254 $tag_data{subfield
} = \
@tmp;
255 push( @loop_data, \
%tag_data );
256 undef @subfields_data;
259 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
263 # now, build item tab !
264 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
265 # loop through each tag
266 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
267 # then construct template.
268 my @fields = $record->fields();
270 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
271 my @item_subfield_codes;
273 foreach my $field (@fields) {
274 next if ( $field->tag() < 10 );
275 next if ( ( $field->tag() eq $tag_itemnumber ) &&
276 ( any
{ $field->subfield($subtag_itemnumber) eq $_ }
278 my @subf = $field->subfields;
281 # loop through each subfield
282 for my $i ( 0 .. $#subf ) {
283 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
284 next if ( ($sf_def->{tab
}||0) != 10 );
285 next if ( ($sf_def->{hidden
}||0) > 0 );
286 push @item_subfield_codes, $subf[$i][0];
287 $witness{ $subf[$i][0] } = $sf_def->{lib
};
289 if ( $sf_def->{isurl
} ) {
290 $item->{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
292 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
293 $item->{ $subf[$i][0] } = $subf[$i][1];
296 $item->{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
297 $subf[$i][1], '', $tagslib, '', 'opac' );
300 push @item_loop, $item if $item;
302 my ( $holdingbrtagf, $holdingbrtagsubf ) =
303 &GetMarcFromKohaField
( "items.holdingbranch", $framework );
305 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @item_loop;
307 @item_subfield_codes = uniq
@item_subfield_codes;
309 my @item_header_loop;
310 for my $subfield_code ( @item_subfield_codes ) {
311 push @item_header_loop, $witness{$subfield_code};
312 for my $item_data ( @item_loop ) {
313 $item_data->{$subfield_code} ||= " "
317 if ( C4
::Context
->preference("OPACISBD") ) {
318 $template->param( ISBD
=> 1 );
321 #Search for title in links
322 my $marcflavour = C4
::Context
->preference("marcflavour");
323 my $dat = TransformMarcToKoha
( $record );
324 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
325 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
326 my $marcissns = GetMarcISSN
( $record, $marcflavour );
327 my $issn = $marcissns->[0] || '';
329 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
330 $dat->{title
} =~ s/\/+$//; # remove trailing slash
331 $dat->{title
} =~ s/\s+$//; # remove trailing space
332 $search_for_title = parametrized_url
(
335 TITLE
=> $dat->{title
},
336 AUTHOR
=> $dat->{author
},
339 CONTROLNUMBER
=> $marccontrolnumber,
340 BIBLIONUMBER
=> $biblionumber,
343 $template->param('OPACSearchForTitleIn' => $search_for_title);
347 item_loop
=> \
@item_loop,
348 item_header_loop
=> \
@item_header_loop,
349 item_subfield_codes
=> \
@item_subfield_codes,
350 biblionumber
=> $biblionumber,
353 output_html_with_http_headers
$query, $cookie, $template->output;