3 # Copyright 2000-2002 Katipo Communications
4 # Parts copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 MARCdetail.pl : script to show a biblio in MARC format
31 This script needs a biblionumber as parameter
33 It shows the biblio in a (nice) MARC format depending on MARC
36 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
37 this template must be divided into 11 "tabs".
39 The first 10 tabs present the biblio, the 11th one presents
40 the items attached to the biblio
56 use List
::MoreUtils qw
/any/;
60 my $dbh = C4
::Context
->dbh;
62 my $biblionumber = $query->param('biblionumber');
63 if ( ! $biblionumber ) {
64 print $query->redirect("/cgi-bin/koha/errors/404.pl");
68 my @all_items = GetItemsInfo
($biblionumber);
70 if (scalar @all_items >= 1) {
71 push @items2hide, GetHiddenItemnumbers
(@all_items);
73 if (scalar @items2hide == scalar @all_items ) {
74 print $query->redirect("/cgi-bin/koha/errors/404.pl");
79 my $itemtype = &GetFrameworkCode
($biblionumber);
80 my $tagslib = &GetMarcStructure
( 0, $itemtype );
81 my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField
('items.itemnumber',$itemtype);
82 my $biblio = GetBiblioData
($biblionumber);
83 $biblionumber = $biblio->{biblionumber
};
84 my $record = GetMarcBiblio
($biblionumber, 1);
86 print $query->redirect("/cgi-bin/koha/errors/404.pl");
90 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
92 template_name
=> "opac-MARCdetail.tmpl",
95 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
101 bibliotitle
=> $biblio->{title
},
104 # get biblionumbers stored in the cart
107 if($query->cookie("bib_list")){
108 my $cart_list = $query->cookie("bib_list");
109 @cart_list = split(/\//, $cart_list);
110 if ( grep {$_ eq $biblionumber} @cart_list) {
111 $template->param( incart
=> 1 );
115 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
116 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
118 # adding the $RequestOnOpac param
120 if (C4
::Context
->preference("RequestOnOpac")) {
128 # loop through each tab 0 through 9
129 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
131 # loop through each tag
136 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
137 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
140 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
141 $subfield_data{marc_value
} = $record->leader();
142 $subfield_data{marc_subfield
} = '@';
143 $subfield_data{marc_tag
} = '000';
144 push( @subfields_data, \
%subfield_data );
146 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
147 my @tmp = @subfields_data;
148 $tag_data{subfield
} = \
@tmp;
149 push( @loop_data, \
%tag_data );
150 undef @subfields_data;
152 my @fields = $record->fields();
153 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
155 # if tag <10, there's no subfield, use the "@" trick
156 if ( $fields[$x_i]->tag() < 10 ) {
159 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
160 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
162 $subfield_data{marc_lib
} =
163 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
164 $subfield_data{marc_value
} = $fields[$x_i]->data();
165 $subfield_data{marc_subfield
} = '@';
166 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
167 push( @subfields_data, \
%subfield_data );
170 my @subf = $fields[$x_i]->subfields;
172 # loop through each subfield
173 for my $i ( 0 .. $#subf ) {
174 $subf[$i][0] = "@" unless defined($subf[$i][0]);
175 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
176 next if ( ($sf_def->{tab
}||0) != $tabloop );
177 next if ( ($sf_def->{hidden
}||0) > 0 );
179 $subfield_data{marc_lib
} = ($sf_def->{lib
} eq $previous) ?
'--' : $sf_def->{lib
};
180 $previous = $sf_def->{lib
};
181 $subfield_data{link} = $sf_def->{link};
182 $subf[$i][1] =~ s/\n/<br\/>/g
;
183 if ( $sf_def->{isurl
} ) {
184 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
186 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
187 $subfield_data{marc_value
} = $subf[$i][1];
190 if ( $sf_def->{authtypecode
} ) {
191 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
193 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
194 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
196 $subfield_data{marc_subfield
} = $subf[$i][0];
197 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
198 push( @subfields_data, \
%subfield_data );
201 if ( $#subfields_data >= 0 ) {
203 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
204 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
210 if ( C4
::Context
->preference('hide_marc') ) {
211 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
217 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
219 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
222 my @tmp = @subfields_data;
223 $tag_data{subfield
} = \
@tmp;
224 push( @loop_data, \
%tag_data );
225 undef @subfields_data;
228 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
232 # now, build item tab !
233 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
234 # loop through each tag
235 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
236 # then construct template.
237 my @fields = $record->fields();
239 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
241 foreach my $field (@fields) {
242 next if ( $field->tag() < 10 );
243 next if ( ( $field->tag() eq $tag_itemnumber ) &&
244 ( any
{ $field->subfield($subtag_itemnumber) eq $_ }
246 my @subf = $field->subfields;
249 # loop through each subfield
250 for my $i ( 0 .. $#subf ) {
251 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
252 next if ( ($sf_def->{tab
}||0) != 10 );
253 next if ( ($sf_def->{hidden
}||0) > 0 );
254 $witness{ $subf[$i][0] } = $sf_def->{lib
};
256 if ( $sf_def->{isurl
} ) {
257 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
259 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
260 $this_row{ $subf[$i][0] } = $subf[$i][1];
263 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
264 $subf[$i][1], '', $tagslib, '', 'opac' );
268 push( @big_array, \
%this_row );
271 my ( $holdingbrtagf, $holdingbrtagsubf ) =
272 &GetMarcFromKohaField
( "items.holdingbranch", $itemtype );
274 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
276 #fill big_row with missing datas
277 foreach my $subfield_code ( keys(%witness) ) {
278 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
279 $big_array[$i]{$subfield_code} = " "
280 unless ( $big_array[$i]{$subfield_code} );
284 # now, construct template !
286 my @header_value_loop;
287 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
289 foreach my $subfield_code ( keys(%witness) ) {
290 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
293 $row_data{item_value
} = $items_data;
294 push( @item_value_loop, \
%row_data );
297 foreach my $subfield_code ( keys(%witness) ) {
299 $header_value{header_value
} = $witness{$subfield_code};
300 push( @header_value_loop, \
%header_value );
303 if(C4
::Context
->preference("ISBD")) {
304 $template->param(ISBD
=> 1);
308 my $OpacExportOptions=C4
::Context
->preference("OpacExportOptions");
309 my @export_options = split(/\|/,$OpacExportOptions);
310 $template->{VARS
}->{'export_options'} = \
@export_options;
312 #Search for title in links
313 my $marcflavour = C4
::Context
->preference("marcflavour");
314 my $dat = TransformMarcToKoha
( $dbh, $record );
315 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
316 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
317 my $marcissns = GetMarcISSN
( $record, $marcflavour );
318 my $issn = $marcissns->[0] || '';
320 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
321 $dat->{title
} =~ s/\/+$//; # remove trailing slash
322 $dat->{title
} =~ s/\s+$//; # remove trailing space
323 $search_for_title = parametrized_url
(
326 TITLE
=> $dat->{title
},
327 AUTHOR
=> $dat->{author
},
330 CONTROLNUMBER
=> $marccontrolnumber,
331 BIBLIONUMBER
=> $biblionumber,
334 $template->param('OPACSearchForTitleIn' => $search_for_title);
338 item_loop
=> \
@item_value_loop,
339 item_header_loop
=> \
@header_value_loop,
340 biblionumber
=> $biblionumber,
343 output_html_with_http_headers
$query, $cookie, $template->output;