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
59 my $dbh = C4::Context->dbh;
61 my $biblionumber = $query->param('biblionumber');
62 if ( ! $biblionumber ) {
63 print $query->redirect("/cgi-bin/koha/errors/404.pl");
67 my @all_items = GetItemsInfo($biblionumber);
69 if (scalar @all_items >= 1) {
70 push @items2hide, GetHiddenItemnumbers(@all_items);
72 if (scalar @items2hide == scalar @all_items ) {
73 print $query->redirect("/cgi-bin/koha/errors/404.pl");
78 my $itemtype = &GetFrameworkCode($biblionumber);
79 my $tagslib = &GetMarcStructure( 0, $itemtype );
80 my $biblio = GetBiblioData($biblionumber);
81 $biblionumber = $biblio->{biblionumber};
82 my $record = GetMarcBiblio($biblionumber, 1);
84 print $query->redirect("/cgi-bin/koha/errors/404.pl");
88 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
90 template_name => "opac-MARCdetail.tmpl",
93 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
99 bibliotitle => $biblio->{title},
102 # get biblionumbers stored in the cart
105 if($query->cookie("bib_list")){
106 my $cart_list = $query->cookie("bib_list");
107 @cart_list = split(/\//, $cart_list);
108 if ( grep {$_ eq $biblionumber} @cart_list) {
109 $template->param( incart => 1 );
113 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
114 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
116 # adding the $RequestOnOpac param
118 if (C4::Context->preference("RequestOnOpac")) {
126 # loop through each tab 0 through 9
127 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
129 # loop through each tag
134 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
135 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
138 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
139 $subfield_data{marc_value} = $record->leader();
140 $subfield_data{marc_subfield} = '@';
141 $subfield_data{marc_tag} = '000';
142 push( @subfields_data, \%subfield_data );
144 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
145 my @tmp = @subfields_data;
146 $tag_data{subfield} = \@tmp;
147 push( @loop_data, \%tag_data );
148 undef @subfields_data;
150 my @fields = $record->fields();
151 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
153 # if tag <10, there's no subfield, use the "@" trick
154 if ( $fields[$x_i]->tag() < 10 ) {
157 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
158 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
160 $subfield_data{marc_lib} =
161 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
162 $subfield_data{marc_value} = $fields[$x_i]->data();
163 $subfield_data{marc_subfield} = '@';
164 $subfield_data{marc_tag} = $fields[$x_i]->tag();
165 push( @subfields_data, \%subfield_data );
168 my @subf = $fields[$x_i]->subfields;
170 # loop through each subfield
171 for my $i ( 0 .. $#subf ) {
172 $subf[$i][0] = "@" unless defined($subf[$i][0]);
173 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
174 next if ( ($sf_def->{tab}||0) != $tabloop );
175 next if ( ($sf_def->{hidden}||0) > 0 );
177 $subfield_data{marc_lib} = ($sf_def->{lib} eq $previous) ? '--' : $sf_def->{lib};
178 $previous = $sf_def->{lib};
179 $subfield_data{link} = $sf_def->{link};
180 $subf[$i][1] =~ s/\n/<br\/>/g;
181 if ( $sf_def->{isurl} ) {
182 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
184 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
185 $subfield_data{marc_value} = $subf[$i][1];
188 if ( $sf_def->{authtypecode} ) {
189 $subfield_data{authority} = $fields[$x_i]->subfield(9);
191 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
192 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
194 $subfield_data{marc_subfield} = $subf[$i][0];
195 $subfield_data{marc_tag} = $fields[$x_i]->tag();
196 push( @subfields_data, \%subfield_data );
199 if ( $#subfields_data >= 0 ) {
201 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
202 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
208 if ( C4::Context->preference('hide_marc') ) {
209 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
215 . C4::Koha::display_marc_indicators($fields[$x_i])
217 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
220 my @tmp = @subfields_data;
221 $tag_data{subfield} = \@tmp;
222 push( @loop_data, \%tag_data );
223 undef @subfields_data;
226 $template->param( "tab" . $tabloop . "XX" => \@loop_data );
230 # now, build item tab !
231 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
232 # loop through each tag
233 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
234 # then construct template.
235 my @fields = $record->fields();
237 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
239 foreach my $field (@fields) {
240 next if ( $field->tag() < 10 );
241 my @subf = $field->subfields;
244 # loop through each subfield
245 for my $i ( 0 .. $#subf ) {
246 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
247 next if ( ($sf_def->{tab}||0) != 10 );
248 next if ( ($sf_def->{hidden}||0) > 0 );
249 $witness{ $subf[$i][0] } = $sf_def->{lib};
251 if ( $sf_def->{isurl} ) {
252 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
254 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
255 $this_row{ $subf[$i][0] } = $subf[$i][1];
258 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
259 $subf[$i][1], '', $tagslib, '', 'opac' );
263 push( @big_array, \%this_row );
266 my ( $holdingbrtagf, $holdingbrtagsubf ) =
267 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
269 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
271 #fill big_row with missing datas
272 foreach my $subfield_code ( keys(%witness) ) {
273 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
274 $big_array[$i]{$subfield_code} = " "
275 unless ( $big_array[$i]{$subfield_code} );
279 # now, construct template !
281 my @header_value_loop;
282 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
284 foreach my $subfield_code ( keys(%witness) ) {
285 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
288 $row_data{item_value} = $items_data;
289 push( @item_value_loop, \%row_data );
292 foreach my $subfield_code ( keys(%witness) ) {
294 $header_value{header_value} = $witness{$subfield_code};
295 push( @header_value_loop, \%header_value );
298 if(C4::Context->preference("ISBD")) {
299 $template->param(ISBD => 1);
303 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
304 my @export_options = split(/\|/,$OpacExportOptions);
305 $template->{VARS}->{'export_options'} = \@export_options;
307 #Search for title in links
308 my $marcflavour = C4::Context->preference("marcflavour");
309 my $dat = TransformMarcToKoha( $dbh, $record );
310 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
311 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
312 my $marcissns = GetMarcISSN( $record, $marcflavour );
313 my $issn = $marcissns->[0] || '';
315 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
316 $dat->{title} =~ s/\/+$//; # remove trailing slash
317 $dat->{title} =~ s/\s+$//; # remove trailing space
318 $search_for_title = parametrized_url(
321 TITLE => $dat->{title},
322 AUTHOR => $dat->{author},
325 CONTROLNUMBER => $marccontrolnumber,
326 BIBLIONUMBER => $biblionumber,
329 $template->param('OPACSearchForTitleIn' => $search_for_title);
333 item_loop => \@item_value_loop,
334 item_header_loop => \@header_value_loop,
335 biblionumber => $biblionumber,
338 output_html_with_http_headers $query, $cookie, $template->output;