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
51 use C4::Interface::CGI::Output;
57 use C4::Serials; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
59 #---- Internal function ---
60 sub get_authorised_value_desc ($$$$$$) {
61 my ( $tagslib, $tag, $subfield, $value, $framework, $dbh ) = @_;
64 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
66 # return GetBranchDetail($value)->{branchname};
70 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
72 # my $itemtypedef = getitemtypeinfo($itemtype);
73 # return $itemtypedef->{description};
76 #---- "true" authorized value
77 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
79 if ( $category ne "" ) {
82 "select lib from authorised_values where category = ? and authorised_value = ?"
84 $sth->execute( $category, $value );
85 my $data = $sth->fetchrow_hashref;
86 return $data->{'lib'};
89 return $value; # if nothing is found return the original value
96 my $dbh = C4::Context->dbh;
97 my $biblionumber = $query->param('biblionumber');
98 my $frameworkcode = GetFrameworkCode( $biblionumber );
100 $query->param('popup')
101 ; # if set to 1, then don't insert links, it's just to show the biblio
102 my $subscriptionid = $query->param('subscriptionid');
104 my $tagslib = &GetMarcStructure($dbh,1,$frameworkcode);
106 my $record = GetMarcBiblio($biblionumber);
109 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
111 template_name => "catalogue/MARCdetail.tmpl",
114 authnotrequired => 0,
115 flagsrequired => { catalogue => 1 },
120 #Getting the list of all frameworks
122 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
127 push @select_fwk, "Default";
128 $select_fwk{"Default"} = "Default";
130 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
131 push @select_fwk, $fwk;
132 $select_fwk{$fwk} = $description;
134 $curfwk=$frameworkcode;
135 my $framework=CGI::scrolling_list( -name => 'Frameworks',
138 -OnChange => 'Changefwk(this);',
139 -values => \@select_fwk,
140 -labels => \%select_fwk,
143 $template->param(framework => $framework);
148 # loop through each tab 0 through 9
149 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
151 # loop through each tag
152 my @fields = $record->fields();
157 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
158 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
160 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
161 $subfield_data{marc_value} = $record->leader();
162 $subfield_data{marc_subfield} = '@';
163 $subfield_data{marc_tag} = '000';
164 push( @subfields_data, \%subfield_data );
166 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
167 my @tmp = @subfields_data;
168 $tag_data{subfield} = \@tmp;
169 push( @loop_data, \%tag_data );
170 undef @subfields_data;
172 @fields = $record->fields();
173 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
175 # if tag <10, there's no subfield, use the "@" trick
176 if ( $fields[$x_i]->tag() < 10 ) {
179 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
180 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} );
182 $subfield_data{marc_lib} =
183 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
184 $subfield_data{marc_value} = $fields[$x_i]->data();
185 $subfield_data{marc_subfield} = '@';
186 $subfield_data{marc_tag} = $fields[$x_i]->tag();
187 push( @subfields_data, \%subfield_data );
190 my @subf = $fields[$x_i]->subfields;
192 # loop through each subfield
193 for my $i ( 0 .. $#subf ) {
194 $subf[$i][0] = "@" unless $subf[$i][0];
197 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
200 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
203 $subfield_data{short_desc} = substr(
204 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib},
207 $subfield_data{long_desc} =
208 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
209 $subfield_data{link} =
210 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
212 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
213 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
216 $subfield_data{marc_value} =
217 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
219 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
220 ->{kohafield} eq "biblioitems.isbn" )
223 # 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]);
224 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
227 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
230 $subfield_data{authority} = $fields[$x_i]->subfield(9);
232 $subfield_data{marc_value} =
233 get_authorised_value_desc( $tagslib, $fields[$x_i]->tag(),
234 $subf[$i][0], $subf[$i][1], '', $dbh );
236 $subfield_data{marc_subfield} = $subf[$i][0];
237 $subfield_data{marc_tag} = $fields[$x_i]->tag();
238 push( @subfields_data, \%subfield_data );
241 if ( $#subfields_data == 0 ) {
242 $subfields_data[0]->{marc_lib} = '';
243 $subfields_data[0]->{marc_subfield} = '';
245 if ( $#subfields_data >= 0 ) {
247 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() ) {
251 if ( C4::Context->preference('hide_marc') ) {
252 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
256 $fields[$x_i]->tag() . ' -'
257 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
260 my @tmp = @subfields_data;
261 $tag_data{subfield} = \@tmp;
262 push( @loop_data, \%tag_data );
263 undef @subfields_data;
266 $template->param( $tabloop . "XX" => \@loop_data );
269 # now, build item tab !
270 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
271 # loop through each tag
272 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
273 # then construct template.
274 my @fields = $record->fields();
276 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
278 foreach my $field (@fields) {
279 next if ( $field->tag() < 10 );
280 my @subf = $field->subfields;
283 # loop through each subfield
284 for my $i ( 0 .. $#subf ) {
285 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
286 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
287 $witness{ $subf[$i][0] } =
288 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
289 $this_row{ $subf[$i][0] } = $subf[$i][1];
292 push( @big_array, \%this_row );
295 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField($dbh,"items.holdingbranch",$frameworkcode);
296 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
298 #fill big_row with missing datas
299 foreach my $subfield_code ( keys(%witness) ) {
300 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
301 $big_array[$i]{$subfield_code} = " "
302 unless ( $big_array[$i]{$subfield_code} );
306 # now, construct template !
308 my @header_value_loop;
309 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
311 foreach my $subfield_code ( keys(%witness) ) {
312 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
315 $row_data{item_value} = $items_data;
316 push( @item_value_loop, \%row_data );
318 foreach my $subfield_code ( keys(%witness) ) {
320 $header_value{header_value} = $witness{$subfield_code};
321 push( @header_value_loop, \%header_value );
324 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
326 if ($subscriptionsnumber) {
327 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
328 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
330 subscriptiontitle => $subscriptiontitle,
331 subscriptionsnumber => $subscriptionsnumber,
336 item_loop => \@item_value_loop,
337 item_header_loop => \@header_value_loop,
338 biblionumber => $biblionumber,
340 hide_marc => C4::Context->preference('hide_marc'),
341 intranetcolorstylesheet =>
342 C4::Context->preference("intranetcolorstylesheet"),
343 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
344 IntranetNav => C4::Context->preference("IntranetNav"),
348 output_html_with_http_headers $query, $cookie, $template->output;