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 $biblionumber = $biblio->{biblionumber
};
65 my $record = GetMarcBiblio
($biblionumber, 1);
67 print $query->redirect("/cgi-bin/koha/errors/404.pl");
71 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
73 template_name
=> "opac-MARCdetail.tmpl",
76 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
82 bibliotitle
=> $biblio->{title
},
85 # get biblionumbers stored in the cart
88 if($query->cookie("bib_list")){
89 my $cart_list = $query->cookie("bib_list");
90 @cart_list = split(/\//, $cart_list);
91 if ( grep {$_ eq $biblionumber} @cart_list) {
92 $template->param( incart
=> 1 );
96 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
97 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
99 # adding the $RequestOnOpac param
101 if (C4
::Context
->preference("RequestOnOpac")) {
109 # loop through each tab 0 through 9
110 for ( my $tabloop = 0 ; $tabloop <= 9 ; $tabloop++ ) {
112 # loop through each tag
117 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop
118 or $tagslib->{'000'}->{'@'}->{hidden
} > 0 )
121 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
122 $subfield_data{marc_value
} = $record->leader();
123 $subfield_data{marc_subfield
} = '@';
124 $subfield_data{marc_tag
} = '000';
125 push( @subfields_data, \
%subfield_data );
127 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
128 my @tmp = @subfields_data;
129 $tag_data{subfield
} = \
@tmp;
130 push( @loop_data, \
%tag_data );
131 undef @subfields_data;
133 my @fields = $record->fields();
134 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
136 # if tag <10, there's no subfield, use the "@" trick
137 if ( $fields[$x_i]->tag() < 10 ) {
140 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
141 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} > 0 );
143 $subfield_data{marc_lib
} =
144 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
145 $subfield_data{marc_value
} = $fields[$x_i]->data();
146 $subfield_data{marc_subfield
} = '@';
147 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
148 push( @subfields_data, \
%subfield_data );
151 my @subf = $fields[$x_i]->subfields;
153 # loop through each subfield
154 for my $i ( 0 .. $#subf ) {
155 $subf[$i][0] = "@" unless defined($subf[$i][0]);
156 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
157 next if ( ($sf_def->{tab
}||0) != $tabloop );
158 next if ( ($sf_def->{hidden
}||0) > 0 );
160 $subfield_data{marc_lib
} = ($sf_def->{lib
} eq $previous) ?
'--' : $sf_def->{lib
};
161 $previous = $sf_def->{lib
};
162 $subfield_data{link} = $sf_def->{link};
163 $subf[$i][1] =~ s/\n/<br\/>/g
;
164 if ( $sf_def->{isurl
} ) {
165 $subfield_data{marc_value
} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
167 elsif ( defined($sf_def->{kohafield
}) && $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
168 $subfield_data{marc_value
} = $subf[$i][1];
171 if ( $sf_def->{authtypecode
} ) {
172 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
174 $subfield_data{marc_value
} = GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
175 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
177 $subfield_data{marc_subfield
} = $subf[$i][0];
178 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
179 push( @subfields_data, \
%subfield_data );
182 if ( $#subfields_data >= 0 ) {
184 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
185 && ( C4
::Context
->preference('LabelMARCView') eq 'economical' )
191 if ( C4
::Context
->preference('hide_marc') ) {
192 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
198 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
200 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
203 my @tmp = @subfields_data;
204 $tag_data{subfield
} = \
@tmp;
205 push( @loop_data, \
%tag_data );
206 undef @subfields_data;
209 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
213 # now, build item tab !
214 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
215 # loop through each tag
216 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
217 # then construct template.
218 my @fields = $record->fields();
220 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
222 foreach my $field (@fields) {
223 next if ( $field->tag() < 10 );
224 my @subf = $field->subfields;
227 # loop through each subfield
228 for my $i ( 0 .. $#subf ) {
229 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
230 next if ( ($sf_def->{tab
}||0) != 10 );
231 next if ( ($sf_def->{hidden
}||0) > 0 );
232 $witness{ $subf[$i][0] } = $sf_def->{lib
};
234 if ( $sf_def->{isurl
} ) {
235 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
237 elsif ( $sf_def->{kohafield
} eq "biblioitems.isbn" ) {
238 $this_row{ $subf[$i][0] } = $subf[$i][1];
241 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(), $subf[$i][0],
242 $subf[$i][1], '', $tagslib, '', 'opac' );
246 push( @big_array, \
%this_row );
249 my ( $holdingbrtagf, $holdingbrtagsubf ) =
250 &GetMarcFromKohaField
( "items.holdingbranch", $itemtype );
252 sort { ($a->{$holdingbrtagsubf}||'') cmp ($b->{$holdingbrtagsubf}||'') } @big_array;
254 #fill big_row with missing datas
255 foreach my $subfield_code ( keys(%witness) ) {
256 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
257 $big_array[$i]{$subfield_code} = " "
258 unless ( $big_array[$i]{$subfield_code} );
262 # now, construct template !
264 my @header_value_loop;
265 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
267 foreach my $subfield_code ( keys(%witness) ) {
268 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
271 $row_data{item_value
} = $items_data;
272 push( @item_value_loop, \
%row_data );
275 foreach my $subfield_code ( keys(%witness) ) {
277 $header_value{header_value
} = $witness{$subfield_code};
278 push( @header_value_loop, \
%header_value );
281 if(C4
::Context
->preference("ISBD")) {
282 $template->param(ISBD
=> 1);
286 my $OpacExportOptions=C4
::Context
->preference("OpacExportOptions");
287 my @export_options = split(/\|/,$OpacExportOptions);
288 $template->{VARS
}->{'export_options'} = \
@export_options;
290 #Search for title in links
291 my $marcflavour = C4
::Context
->preference("marcflavour");
292 my $dat = TransformMarcToKoha
( $dbh, $record );
293 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
294 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
295 my $marcissns = GetMarcISSN
( $record, $marcflavour );
296 my $issn = $marcissns->[0] || '';
298 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
299 $dat->{title
} =~ s/\/+$//; # remove trailing slash
300 $dat->{title
} =~ s/\s+$//; # remove trailing space
301 $search_for_title = parametrized_url
(
304 TITLE
=> $dat->{title
},
305 AUTHOR
=> $dat->{author
},
308 CONTROLNUMBER
=> $marccontrolnumber,
309 BIBLIONUMBER
=> $biblionumber,
312 $template->param('OPACSearchForTitleIn' => $search_for_title);
316 item_loop
=> \
@item_value_loop,
317 item_header_loop
=> \
@header_value_loop,
318 biblionumber
=> $biblionumber,
321 output_html_with_http_headers
$query, $cookie, $template->output;