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.tmpl.
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 my $dbh = C4::Context->dbh;
61 my $biblionumber = $query->param('biblionumber');
62 my $itemtype = &GetFrameworkCode($biblionumber);
63 my $tagslib = &GetMarcStructure( 0, $itemtype );
64 my $biblio = GetBiblioData($biblionumber);
65 $biblionumber = $biblio->{biblionumber};
66 my $record = GetMarcBiblio($biblionumber, 1);
68 print $query->redirect("/cgi-bin/koha/errors/404.pl");
72 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74 template_name => "opac-MARCdetail.tmpl",
77 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
83 bibliotitle => $biblio->{title},
86 # get biblionumbers stored in the cart
89 if($query->cookie("bib_list")){
90 my $cart_list = $query->cookie("bib_list");
91 @cart_list = split(/\//, $cart_list);
92 if ( grep {$_ eq $biblionumber} @cart_list) {
93 $template->param( incart => 1 );
97 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
98 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
100 # adding the $RequestOnOpac param
102 if (C4::Context->preference("RequestOnOpac")) {
110 # loop through each tab 0 through 9
111 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
113 # loop through each tag
118 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
119 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
122 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
123 $subfield_data{marc_value} = $record->leader();
124 $subfield_data{marc_subfield} = '@';
125 $subfield_data{marc_tag} = '000';
126 push( @subfields_data, \%subfield_data );
128 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
129 my @tmp = @subfields_data;
130 $tag_data{subfield} = \@tmp;
131 push( @loop_data, \%tag_data );
132 undef @subfields_data;
134 my @fields = $record->fields();
135 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
137 # if tag <10, there's no subfield, use the "@" trick
138 if ( $fields[$x_i]->tag() < 10 ) {
141 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
142 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
144 $subfield_data{marc_lib} =
145 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
146 $subfield_data{marc_value} = $fields[$x_i]->data();
147 $subfield_data{marc_subfield} = '@';
148 $subfield_data{marc_tag} = $fields[$x_i]->tag();
149 push( @subfields_data, \%subfield_data );
152 my @subf = $fields[$x_i]->subfields;
154 # loop through each subfield
155 for my $i ( 0 .. $#subf ) {
156 $subf[$i][0] = "@" unless defined($subf[$i][0]);
157 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
158 $sf_def = $sf_def->{ $subf[$i][0] } if defined($sf_def);
159 my ($tab,$hidden,$lib);
160 $tab = $sf_def->{tab} if defined($sf_def);
161 $tab = $tab // int($fields[$x_i]->tag()/100);
162 $hidden = $sf_def->{hidden} if defined($sf_def);
163 $hidden = $hidden // 0;
164 next if ( $tab != $tabloop );
165 next if ( $hidden > 0 );
167 $lib = $sf_def->{lib} if defined($sf_def);
169 $subfield_data{marc_lib} = ($lib eq $previous) ? '--' : $lib;
171 $subfield_data{link} = $sf_def->{link};
172 $subf[$i][1] =~ s/\n/<br\/>/g;
173 if ( $sf_def->{isurl} ) {
174 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
176 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
177 $subfield_data{marc_value} = $subf[$i][1];
180 if ( $sf_def->{authtypecode} ) {
181 $subfield_data{authority} = $fields[$x_i]->subfield(9);
183 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
184 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
186 $subfield_data{marc_subfield} = $subf[$i][0];
187 $subfield_data{marc_tag} = $fields[$x_i]->tag();
188 push( @subfields_data, \%subfield_data );
191 if ( $#subfields_data >= 0 ) {
193 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
194 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
200 if ( C4::Context->preference('hide_marc') ) {
201 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
204 my $sf_def = $tagslib->{ $fields[$x_i]->tag() };
206 $lib = $sf_def->{lib} if defined($sf_def);
208 $tag_data{tag} = $fields[$x_i]->tag() . ' '
209 . C4::Koha::display_marc_indicators($fields[$x_i])
213 my @tmp = @subfields_data;
214 $tag_data{subfield} = \@tmp;
215 push( @loop_data, \%tag_data );
216 undef @subfields_data;
219 $template->param( "tab" . $tabloop . "XX" => \@loop_data );
223 # now, build item tab !
224 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
225 # loop through each tag
226 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
227 # then construct template.
228 my @fields = $record->fields();
230 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
232 foreach my $field (@fields) {
233 next if ( $field->tag() < 10 );
234 my @subf = $field->subfields;
237 # loop through each subfield
238 for my $i ( 0 .. $#subf ) {
239 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
240 next if ( ($sf_def->{tab}||0) != 10 );
241 next if ( ($sf_def->{hidden}||0) > 0 );
242 $witness{ $subf[$i][0] } = $sf_def->{lib};
244 if ( $sf_def->{isurl} ) {
245 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
247 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
248 $this_row{ $subf[$i][0] } = $subf[$i][1];
251 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
252 $subf[$i][1], '', $tagslib, '', 'opac' );
256 push( @big_array, \%this_row );
259 my ( $holdingbrtagf, $holdingbrtagsubf ) =
260 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
262 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
264 #fill big_row with missing datas
265 foreach my $subfield_code ( keys(%witness) ) {
266 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
267 $big_array[$i]{$subfield_code} = " "
268 unless ( $big_array[$i]{$subfield_code} );
272 # now, construct template !
274 my @header_value_loop;
275 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
277 foreach my $subfield_code ( keys(%witness) ) {
278 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
281 $row_data{item_value} = $items_data;
282 push( @item_value_loop, \%row_data );
285 foreach my $subfield_code ( keys(%witness) ) {
287 $header_value{header_value} = $witness{$subfield_code};
288 push( @header_value_loop, \%header_value );
291 if(C4::Context->preference("ISBD")) {
292 $template->param(ISBD => 1);
296 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
297 my @export_options = split(/\|/,$OpacExportOptions);
298 $template->{VARS}->{'export_options'} = \@export_options;
300 #Search for title in links
301 my $marcflavour = C4::Context->preference("marcflavour");
302 my $dat = TransformMarcToKoha( $dbh, $record );
303 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
304 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
305 my $marcissns = GetMarcISSN( $record, $marcflavour );
306 my $issn = $marcissns->[0] || '';
308 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
309 $dat->{title} =~ s/\/+$//; # remove trailing slash
310 $dat->{title} =~ s/\s+$//; # remove trailing space
311 $search_for_title = parametrized_url(
314 TITLE => $dat->{title},
315 AUTHOR => $dat->{author},
318 CONTROLNUMBER => $marccontrolnumber,
319 BIBLIONUMBER => $biblionumber,
322 $template->param('OPACSearchForTitleIn' => $search_for_title);
326 item_loop => \@item_value_loop,
327 item_header_loop => \@header_value_loop,
328 biblionumber => $biblionumber,
331 output_html_with_http_headers $query, $cookie, $template->output;