3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 MARCdetail.pl : script to show a biblio in MARC format
30 This script needs a biblionumber as parameter
32 It shows the biblio in a (nice) MARC format depending on MARC
35 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
36 this template must be divided into 11 "tabs".
38 The first 10 tabs present the biblio, the 11th one presents
39 the items attached to the biblio
57 my $dbh = C4::Context->dbh;
59 my $biblionumber = $query->param('biblionumber');
60 my $itemtype = &GetFrameworkCode($biblionumber);
61 my $tagslib = &GetMarcStructure( 0, $itemtype );
62 my $biblio = GetBiblioData($biblionumber);
63 my $record = GetMarcBiblio($biblionumber);
65 print $query->redirect("/cgi-bin/koha/errors/404.pl");
69 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
71 template_name => "opac-MARCdetail.tmpl",
80 bibliotitle => $biblio->{title},
83 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
84 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
86 # adding the $RequestOnOpac param
88 if (C4::Context->preference("RequestOnOpac")) {
96 # loop through each tab 0 through 9
97 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
99 # loop through each tag
104 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
105 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
108 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
109 $subfield_data{marc_value} = $record->leader();
110 $subfield_data{marc_subfield} = '@';
111 $subfield_data{marc_tag} = '000';
112 push( @subfields_data, \%subfield_data );
114 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
115 my @tmp = @subfields_data;
116 $tag_data{subfield} = \@tmp;
117 push( @loop_data, \%tag_data );
118 undef @subfields_data;
120 my @fields = $record->fields();
121 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
123 # if tag <10, there's no subfield, use the "@" trick
124 if ( $fields[$x_i]->tag() < 10 ) {
127 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
128 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
130 $subfield_data{marc_lib} =
131 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
132 $subfield_data{marc_value} = $fields[$x_i]->data();
133 $subfield_data{marc_subfield} = '@';
134 $subfield_data{marc_tag} = $fields[$x_i]->tag();
135 push( @subfields_data, \%subfield_data );
138 my @subf = $fields[$x_i]->subfields;
140 # loop through each subfield
141 for my $i ( 0 .. $#subf ) {
142 $subf[$i][0] = "@" unless $subf[$i][0];
143 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
144 next if ( $sf_def->{tab} ne $tabloop );
145 next if ( $sf_def->{hidden} > 0 );
147 $subfield_data{marc_lib} = ($sf_def->{lib} eq $previous) ? '--' : $sf_def->{lib};
148 $previous = $sf_def->{lib};
149 $subfield_data{link} = $sf_def->{link};
150 $subf[$i][1] =~ s/\n/<br\/>/g;
151 if ( $sf_def->{isurl} ) {
152 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
154 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
155 $subfield_data{marc_value} = $subf[$i][1];
158 if ( $sf_def->{authtypecode} ) {
159 $subfield_data{authority} = $fields[$x_i]->subfield(9);
161 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
162 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
164 $subfield_data{marc_subfield} = $subf[$i][0];
165 $subfield_data{marc_tag} = $fields[$x_i]->tag();
166 push( @subfields_data, \%subfield_data );
169 if ( $#subfields_data >= 0 ) {
171 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
172 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
178 if ( C4::Context->preference('hide_marc') ) {
179 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
185 . C4::Koha::display_marc_indicators($fields[$x_i])
187 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
190 my @tmp = @subfields_data;
191 $tag_data{subfield} = \@tmp;
192 push( @loop_data, \%tag_data );
193 undef @subfields_data;
196 $template->param( $tabloop . "XX" => \@loop_data );
200 # now, build item tab !
201 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
202 # loop through each tag
203 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
204 # then construct template.
205 my @fields = $record->fields();
207 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
209 foreach my $field (@fields) {
210 next if ( $field->tag() < 10 );
211 my @subf = $field->subfields;
214 # loop through each subfield
215 for my $i ( 0 .. $#subf ) {
216 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
217 next if ( $sf_def->{tab} ne 10 );
218 next if ( $sf_def->{hidden} > 0 );
219 $witness{ $subf[$i][0] } = $sf_def->{lib};
221 if ( $sf_def->{isurl} ) {
222 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
224 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
225 $this_row{ $subf[$i][0] } = $subf[$i][1];
228 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
229 $subf[$i][1], '', $tagslib, '', 'opac' );
233 push( @big_array, \%this_row );
236 my ( $holdingbrtagf, $holdingbrtagsubf ) =
237 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
239 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
241 #fill big_row with missing datas
242 foreach my $subfield_code ( keys(%witness) ) {
243 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
244 $big_array[$i]{$subfield_code} = " "
245 unless ( $big_array[$i]{$subfield_code} );
249 # now, construct template !
251 my @header_value_loop;
252 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
254 foreach my $subfield_code ( keys(%witness) ) {
255 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
258 $row_data{item_value} = $items_data;
259 push( @item_value_loop, \%row_data );
262 foreach my $subfield_code ( keys(%witness) ) {
264 $header_value{header_value} = $witness{$subfield_code};
265 push( @header_value_loop, \%header_value );
268 if(C4::Context->preference("ISBD")) {
269 $template->param(ISBD => 1);
272 #Search for title in links
273 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
274 $biblio->{author} ? $search_for_title =~ s/{AUTHOR}/$biblio->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
275 $biblio->{title} =~ s/\/+$//; # remove trailing slash
276 $biblio->{title} =~ s/\s+$//; # remove trailing space
277 $biblio->{title} ? $search_for_title =~ s/{TITLE}/$biblio->{title}/g : $search_for_title =~ s/{TITLE}//g;
278 $biblio->{isbn} ? $search_for_title =~ s/{ISBN}/$biblio->{isbn}/g : $search_for_title =~ s/{ISBN}//g;
279 $template->param('OPACSearchForTitleIn' => $search_for_title);
283 item_loop => \@item_value_loop,
284 item_header_loop => \@header_value_loop,
285 biblionumber => $biblionumber,
288 output_html_with_http_headers $query, $cookie, $template->output;