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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 MARCdetail.pl : script to show a biblio in MARC format
29 This script needs a biblionumber as parameter
31 It shows the biblio in a (nice) MARC format depending on MARC
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
56 use C4
::Serials
; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60 my $dbh = C4
::Context
->dbh;
61 my $biblionumber = $query->param('biblionumber');
62 my $frameworkcode = $query->param('frameworkcode');
63 $frameworkcode = GetFrameworkCode
( $biblionumber ) unless ($frameworkcode);
65 $query->param('popup')
66 ; # if set to 1, then don't insert links, it's just to show the biblio
67 my $subscriptionid = $query->param('subscriptionid');
69 my $tagslib = &GetMarcStructure
(1,$frameworkcode);
71 my $record = GetMarcBiblio
($biblionumber);
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
76 template_name
=> "catalogue/MARCdetail.tmpl",
80 flagsrequired
=> { catalogue
=> 1 },
86 my $itemcount = GetItemsCount
($biblionumber);
87 $template->param( count
=> $itemcount);
89 #Getting the list of all frameworks
91 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
96 push @select_fwk, "Default";
97 $select_fwk{"Default"} = "Default";
99 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
100 push @select_fwk, $fwk;
101 $select_fwk{$fwk} = $description;
103 $curfwk=$frameworkcode;
104 my $framework=CGI
::scrolling_list
( -name
=> 'Frameworks',
107 -OnChange
=> 'Changefwk(this);',
108 -values => \
@select_fwk,
109 -labels
=> \
%select_fwk,
112 $template->param(framework
=> $framework);
117 # loop through each tab 0 through 9
118 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
120 # loop through each tag
121 my @fields = $record->fields();
126 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop )
127 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
129 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
130 $subfield_data{marc_value
} = $record->leader();
131 $subfield_data{marc_subfield
} = '@';
132 $subfield_data{marc_tag
} = '000';
133 push( @subfields_data, \
%subfield_data );
135 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
136 my @tmp = @subfields_data;
137 $tag_data{subfield
} = \
@tmp;
138 push( @loop_data, \
%tag_data );
139 undef @subfields_data;
141 @fields = $record->fields();
142 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
144 # if tag <10, there's no subfield, use the "@" trick
145 if ( $fields[$x_i]->tag() < 10 ) {
148 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
149 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} );
151 $subfield_data{marc_lib
} =
152 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
153 $subfield_data{marc_value
} = $fields[$x_i]->data();
154 $subfield_data{marc_subfield
} = '@';
155 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
156 push( @subfields_data, \
%subfield_data );
159 my @subf = $fields[$x_i]->subfields;
161 # loop through each subfield
162 for my $i ( 0 .. $#subf ) {
163 $subf[$i][0] = "@" unless $subf[$i][0];
166 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab
}
169 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
172 $subfield_data{short_desc
} = substr(
173 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
},
176 $subfield_data{long_desc
} =
177 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
178 $subfield_data{link} =
179 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
181 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
182 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
185 $subfield_data{marc_value
} =
186 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
188 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
189 ->{kohafield
} eq "biblioitems.isbn" )
192 # warn " tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}. "ISBN : ".$subf[$i][1]."PosttraitementISBN :".DisplayISBN($subf[$i][1]);
193 $subfield_data{marc_value
} = DisplayISBN
( $subf[$i][1] );
196 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
199 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
201 $subfield_data{marc_value
} =
202 GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
203 $subf[$i][0], $subf[$i][1], '', $tagslib);
206 $subfield_data{marc_subfield
} = $subf[$i][0];
207 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
208 push( @subfields_data, \
%subfield_data );
211 if ( $#subfields_data == 0 ) {
212 $subfields_data[0]->{marc_lib
} = '';
213 # $subfields_data[0]->{marc_subfield} = '';
215 if ( $#subfields_data >= 0) {
217 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4
::Context
->preference('LabelMARCView') eq 'economical')) {
221 if ( C4
::Context
->preference('hide_marc') ) {
222 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
226 $fields[$x_i]->tag() . ' -'
227 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
230 my @tmp = @subfields_data;
231 $tag_data{subfield
} = \
@tmp;
232 push( @loop_data, \
%tag_data );
233 undef @subfields_data;
236 $template->param( $tabloop . "XX" => \
@loop_data );
239 # now, build item tab !
240 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
241 # loop through each tag
242 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
243 # then construct template.
244 my @fields = $record->fields();
246 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
248 foreach my $field (@fields) {
249 next if ( $field->tag() < 10 );
250 my @subf = $field->subfields;
253 # loop through each subfield
254 for my $i ( 0 .. $#subf ) {
255 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab
} ne 10 );
256 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden
} );
257 $witness{ $subf[$i][0] } =
258 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
};
259 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(),
260 $subf[$i][0], $subf[$i][1], '', $tagslib);
263 push( @big_array, \
%this_row );
266 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField
("items.holdingbranch",$frameworkcode);
267 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
269 #fill big_row with missing datas
270 foreach my $subfield_code ( keys(%witness) ) {
271 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
272 $big_array[$i]{$subfield_code} = " "
273 unless ( $big_array[$i]{$subfield_code} );
277 # now, construct template !
279 my @header_value_loop;
280 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
282 foreach my $subfield_code ( keys(%witness) ) {
283 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
286 $row_data{item_value
} = $items_data;
287 push( @item_value_loop, \
%row_data );
289 foreach my $subfield_code ( keys(%witness) ) {
291 $header_value{header_value
} = $witness{$subfield_code};
292 push( @header_value_loop, \
%header_value );
295 my $subscriptionscount = CountSubscriptionFromBiblionumber
($biblionumber);
297 if ($subscriptionscount) {
298 my $subscriptions = GetSubscriptionsFromBiblionumber
($biblionumber);
299 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
301 subscriptiontitle
=> $subscriptiontitle,
302 subscriptionsnumber
=> $subscriptionscount,
307 item_loop
=> \
@item_value_loop,
308 item_header_loop
=> \
@header_value_loop,
309 biblionumber
=> $biblionumber,
311 hide_marc
=> C4
::Context
->preference('hide_marc'),
315 output_html_with_http_headers
$query, $cookie, $template->output;