updated links to Git usage wiki page
[koha.git] / opac / opac-MARCdetail.pl
blob132d5a66424355017077d2fa3b292c9e6be22144
1 #!/usr/bin/perl
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
10 # version.
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.
20 =head1 NAME
22 MARCdetail.pl : script to show a biblio in MARC format
24 =head1 SYNOPSIS
27 =head1 DESCRIPTION
29 This script needs a biblionumber as parameter
31 It shows the biblio in a (nice) MARC format depending on MARC
32 parameters tables.
34 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
35 this template must be divided into 11 "tabs".
37 The first 10 tabs present the biblio, the 11th one presents
38 the items attached to the biblio
40 =cut
42 use strict;
43 use warnings;
45 use C4::Auth;
46 use C4::Context;
47 use C4::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Biblio;
51 use C4::Acquisition;
52 use C4::Koha;
54 my $query = new CGI;
56 my $dbh = C4::Context->dbh;
58 my $biblionumber = $query->param('biblionumber');
59 my $itemtype = &GetFrameworkCode($biblionumber);
60 my $tagslib = &GetMarcStructure( 0, $itemtype );
61 my $biblio = GetBiblioData($biblionumber);
62 my $record = GetMarcBiblio($biblionumber);
64 # open template
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
67 template_name => "opac-MARCdetail.tmpl",
68 query => $query,
69 type => "opac",
70 authnotrequired => 1,
71 debug => 1,
75 $template->param(
76 bibliotitle => $biblio->{title},
79 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
80 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
82 # adding the $RequestOnOpac param
83 my $RequestOnOpac;
84 if (C4::Context->preference("RequestOnOpac")) {
85 $RequestOnOpac = 1;
88 # fill arrays
89 my @loop_data = ();
90 my $tag;
92 # loop through each tab 0 through 9
93 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
95 # loop through each tag
96 my @loop_data = ();
97 my @subfields_data;
99 # deal with leader
100 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop
101 or $tagslib->{'000'}->{'@'}->{hidden} > 0 )
103 my %subfield_data;
104 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
105 $subfield_data{marc_value} = $record->leader();
106 $subfield_data{marc_subfield} = '@';
107 $subfield_data{marc_tag} = '000';
108 push( @subfields_data, \%subfield_data );
109 my %tag_data;
110 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
111 my @tmp = @subfields_data;
112 $tag_data{subfield} = \@tmp;
113 push( @loop_data, \%tag_data );
114 undef @subfields_data;
116 my @fields = $record->fields();
117 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
119 # if tag <10, there's no subfield, use the "@" trick
120 if ( $fields[$x_i]->tag() < 10 ) {
121 next
122 if (
123 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
124 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} > 0 );
125 my %subfield_data;
126 $subfield_data{marc_lib} =
127 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
128 $subfield_data{marc_value} = $fields[$x_i]->data();
129 $subfield_data{marc_subfield} = '@';
130 $subfield_data{marc_tag} = $fields[$x_i]->tag();
131 push( @subfields_data, \%subfield_data );
133 else {
134 my @subf = $fields[$x_i]->subfields;
135 my $previous = '';
136 # loop through each subfield
137 for my $i ( 0 .. $#subf ) {
138 $subf[$i][0] = "@" unless $subf[$i][0];
139 my $sf_def = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] };
140 next if ( $sf_def->{tab} ne $tabloop );
141 next if ( $sf_def->{hidden} > 0 );
142 my %subfield_data;
143 $subfield_data{marc_lib} = ($sf_def->{lib} eq $previous) ? '--' : $sf_def->{lib};
144 $previous = $sf_def->{lib};
145 $subfield_data{link} = $sf_def->{link};
146 $subf[$i][1] =~ s/\n/<br\/>/g;
147 if ( $sf_def->{isurl} ) {
148 $subfield_data{marc_value} = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
150 elsif ( defined($sf_def->{kohafield}) && $sf_def->{kohafield} eq "biblioitems.isbn" ) {
151 $subfield_data{marc_value} = $subf[$i][1];
153 else {
154 if ( $sf_def->{authtypecode} ) {
155 $subfield_data{authority} = $fields[$x_i]->subfield(9);
157 $subfield_data{marc_value} = GetAuthorisedValueDesc( $fields[$x_i]->tag(),
158 $subf[$i][0], $subf[$i][1], '', $tagslib, '', 'opac' );
160 $subfield_data{marc_subfield} = $subf[$i][0];
161 $subfield_data{marc_tag} = $fields[$x_i]->tag();
162 push( @subfields_data, \%subfield_data );
165 if ( $#subfields_data >= 0 ) {
166 my %tag_data;
167 if ( ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() )
168 && ( C4::Context->preference('LabelMARCView') eq 'economical' )
171 $tag_data{tag} = "";
173 else {
174 if ( C4::Context->preference('hide_marc') ) {
175 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
177 else {
178 $tag_data{tag} =
179 $fields[$x_i]->tag()
180 . ' '
181 . C4::Koha::display_marc_indicators($fields[$x_i])
182 . ' - '
183 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
186 my @tmp = @subfields_data;
187 $tag_data{subfield} = \@tmp;
188 push( @loop_data, \%tag_data );
189 undef @subfields_data;
192 $template->param( $tabloop . "XX" => \@loop_data );
196 # now, build item tab !
197 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
198 # loop through each tag
199 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
200 # then construct template.
201 my @fields = $record->fields();
202 my %witness
203 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
204 my @big_array;
205 foreach my $field (@fields) {
206 next if ( $field->tag() < 10 );
207 my @subf = $field->subfields;
208 my %this_row;
210 # loop through each subfield
211 for my $i ( 0 .. $#subf ) {
212 my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
213 next if ( $sf_def->{tab} ne 10 );
214 next if ( $sf_def->{hidden} > 0 );
215 $witness{ $subf[$i][0] } = $sf_def->{lib};
217 if ( $sf_def->{isurl} ) {
218 $this_row{ $subf[$i][0] } = "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
220 elsif ( $sf_def->{kohafield} eq "biblioitems.isbn" ) {
221 $this_row{ $subf[$i][0] } = $subf[$i][1];
223 else {
224 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
225 $subf[$i][1], '', $tagslib, '', 'opac' );
228 if (%this_row) {
229 push( @big_array, \%this_row );
232 my ( $holdingbrtagf, $holdingbrtagsubf ) =
233 &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
234 @big_array =
235 sort { $a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf} } @big_array;
237 #fill big_row with missing datas
238 foreach my $subfield_code ( keys(%witness) ) {
239 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
240 $big_array[$i]{$subfield_code} = "&nbsp;"
241 unless ( $big_array[$i]{$subfield_code} );
245 # now, construct template !
246 my @item_value_loop;
247 my @header_value_loop;
248 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
249 my $items_data;
250 foreach my $subfield_code ( keys(%witness) ) {
251 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
253 my %row_data;
254 $row_data{item_value} = $items_data;
255 push( @item_value_loop, \%row_data );
258 foreach my $subfield_code ( keys(%witness) ) {
259 my %header_value;
260 $header_value{header_value} = $witness{$subfield_code};
261 push( @header_value_loop, \%header_value );
264 if(C4::Context->preference("ISBD")) {
265 $template->param(ISBD => 1);
268 $template->param(
269 item_loop => \@item_value_loop,
270 item_header_loop => \@header_value_loop,
271 biblionumber => $biblionumber,
274 output_html_with_http_headers $query, $cookie, $template->output;