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
58 my $dbh = C4
::Context
->dbh;
60 my $biblionumber = $query->param('biblionumber');
61 my $itemtype = &GetFrameworkCode
($biblionumber);
62 my $tagslib = &GetMarcStructure
( 0, $itemtype );
63 my $biblio = GetBiblioData
($biblionumber);
64 my $record = GetMarcBiblio
($biblionumber, 1);
66 print $query->redirect("/cgi-bin/koha/errors/404.pl");
70 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
72 template_name
=> "opac-MARCdetail.tmpl",
75 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
81 bibliotitle
=> $biblio->{title
},
84 # get biblionumbers stored in the cart
87 if($query->cookie("bib_list")){
88 my $cart_list = $query->cookie("bib_list");
89 @cart_list = split(/\//, $cart_list);
90 if ( grep {$_ eq $biblionumber} @cart_list) {
91 $template->param( incart
=> 1 );
95 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
96 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
98 # adding the $RequestOnOpac param
100 if (C4
::Context
->preference("RequestOnOpac")) {
108 # loop through each tab 0 through 9
109 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
111 # loop through each tag
116 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
117 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
120 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
121 $subfield_data{marc_value
} = $record->leader();
122 $subfield_data{marc_subfield
} = '@';
123 $subfield_data{marc_tag
} = '000';
124 push( @subfields_data, \
%subfield_data );
126 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
127 my @tmp = @subfields_data;
128 $tag_data{subfield
} = \
@tmp;
129 push( @loop_data, \
%tag_data );
130 undef @subfields_data;
132 my @fields = $record->fields();
133 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
135 # if tag <10, there's no subfield, use the "@" trick
136 if ( $fields[$x_i]->tag() < 10 ) {
139 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
140 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
142 $subfield_data{marc_lib
} =
143 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
144 $subfield_data{marc_value
} = $fields[$x_i]->data();
145 $subfield_data{marc_subfield
} = '@';
146 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
147 push( @subfields_data, \
%subfield_data );
150 my @subf = $fields[$x_i]->subfields;
152 # loop through each subfield
153 for my $i ( 0 .. $#subf ) {
154 $subf[$i][0] = "@" unless defined($subf[$i][0]);
155 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
156 next if ( ($sf_def->{tab
}||0) != $tabloop );
157 next if ( ($sf_def->{hidden
}||0) > 0 );
159 $subfield_data{marc_lib
} = ($sf_def->{lib
} eq $previous) ?
'--' : $sf_def->{lib
};
160 $previous = $sf_def->{lib
};
161 $subfield_data{link} = $sf_def->{link};
162 $subf[$i][1] =~ s/\n/<br\/>/g
;
163 if ( $sf_def->{isurl
} ) {
164 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
166 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
167 $subfield_data{marc_value
} = $subf[$i][1];
170 if ( $sf_def->{authtypecode
} ) {
171 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
173 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
174 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
176 $subfield_data{marc_subfield
} = $subf[$i][0];
177 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
178 push( @subfields_data, \
%subfield_data );
181 if ( $#subfields_data >= 0 ) {
183 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
184 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
190 if ( C4
::Context
->preference('hide_marc') ) {
191 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
197 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
199 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
202 my @tmp = @subfields_data;
203 $tag_data{subfield
} = \
@tmp;
204 push( @loop_data, \
%tag_data );
205 undef @subfields_data;
208 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
212 # now, build item tab !
213 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
214 # loop through each tag
215 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
216 # then construct template.
217 my @fields = $record->fields();
219 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
221 foreach my $field (@fields) {
222 next if ( $field->tag() < 10 );
223 my @subf = $field->subfields;
226 # loop through each subfield
227 for my $i ( 0 .. $#subf ) {
228 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
229 next if ( ($sf_def->{tab
}||0) != 10 );
230 next if ( ($sf_def->{hidden
}||0) > 0 );
231 $witness{ $subf[$i][0] } = $sf_def->{lib
};
233 if ( $sf_def->{isurl
} ) {
234 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
236 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
237 $this_row{ $subf[$i][0] } = $subf[$i][1];
240 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
241 $subf[$i][1], '', $tagslib, '', 'opac' );
245 push( @big_array, \
%this_row );
248 my ( $holdingbrtagf, $holdingbrtagsubf ) =
249 &GetMarcFromKohaField
( "items.holdingbranch", $itemtype );
251 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
253 #fill big_row with missing datas
254 foreach my $subfield_code ( keys(%witness) ) {
255 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
256 $big_array[$i]{$subfield_code} = " "
257 unless ( $big_array[$i]{$subfield_code} );
261 # now, construct template !
263 my @header_value_loop;
264 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
266 foreach my $subfield_code ( keys(%witness) ) {
267 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
270 $row_data{item_value
} = $items_data;
271 push( @item_value_loop, \
%row_data );
274 foreach my $subfield_code ( keys(%witness) ) {
276 $header_value{header_value
} = $witness{$subfield_code};
277 push( @header_value_loop, \
%header_value );
280 if(C4
::Context
->preference("ISBD")) {
281 $template->param(ISBD
=> 1);
285 my $OpacExportOptions=C4
::Context
->preference("OpacExportOptions");
286 my @export_options = split(/\|/,$OpacExportOptions);
287 $template->{VARS
}->{'export_options'} = \
@export_options;
289 #Search for title in links
290 my $marcflavour = C4
::Context
->preference("marcflavour");
291 my $dat = TransformMarcToKoha
( $dbh, $record );
292 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
293 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
294 my $marcissns = GetMarcISSN
( $record, $marcflavour );
295 my $issn = $marcissns->[0] || '';
297 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
298 $dat->{author
} ?
$search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
299 $dat->{title
} =~ s/\/+$//; # remove trailing slash
300 $dat->{title
} =~ s/\s+$//; # remove trailing space
301 $dat->{title
} ?
$search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
302 $isbn ?
$search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
303 $issn ?
$search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g;
304 $marccontrolnumber ?
$search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
305 $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
306 $template->param('OPACSearchForTitleIn' => $search_for_title);
310 item_loop
=> \
@item_value_loop,
311 item_header_loop
=> \
@header_value_loop,
312 biblionumber
=> $biblionumber,
315 output_html_with_http_headers
$query, $cookie, $template->output;