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
58 #---- Internal function ---
59 sub get_authorised_value_desc ($$$$$$) {
60 my ( $tagslib, $tag, $subfield, $value, $framework, $dbh ) = @_;
63 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
65 # return GetBranchDetail($value)->{branchname};
69 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
71 # my $itemtypedef = getitemtypeinfo($itemtype);
72 # return $itemtypedef->{description};
75 #---- "true" authorized value
76 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
78 if ( $category ne "" ) {
81 "select lib from authorised_values where category = ? and authorised_value = ?"
83 $sth->execute( $category, $value );
84 my $data = $sth->fetchrow_hashref;
85 return $data->{'lib'};
88 return $value; # if nothing is found return the original value
95 my $dbh = C4::Context->dbh;
96 my $biblionumber = $query->param('biblionumber');
97 my $frameworkcode = GetFrameworkCode( $biblionumber );
99 $query->param('popup')
100 ; # if set to 1, then don't insert links, it's just to show the biblio
101 my $subscriptionid = $query->param('subscriptionid');
103 my $tagslib = &GetMarcStructure($dbh,1,$frameworkcode);
105 my $record = GetMarcBiblio($biblionumber);
108 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
110 template_name => "catalogue/MARCdetail.tmpl",
113 authnotrequired => 0,
114 flagsrequired => { catalogue => 1 },
119 #count of item linked
120 my $itemcount = GetItemsCount($biblionumber);
121 $template->param( count => $itemcount);
123 #Getting the list of all frameworks
125 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
130 push @select_fwk, "Default";
131 $select_fwk{"Default"} = "Default";
133 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
134 push @select_fwk, $fwk;
135 $select_fwk{$fwk} = $description;
137 $curfwk=$frameworkcode;
138 my $framework=CGI::scrolling_list( -name => 'Frameworks',
141 -OnChange => 'Changefwk(this);',
142 -values => \@select_fwk,
143 -labels => \%select_fwk,
146 $template->param(framework => $framework);
151 # loop through each tab 0 through 9
152 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
154 # loop through each tag
155 my @fields = $record->fields();
160 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
161 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
163 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
164 $subfield_data{marc_value} = $record->leader();
165 $subfield_data{marc_subfield} = '@';
166 $subfield_data{marc_tag} = '000';
167 push( @subfields_data, \%subfield_data );
169 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
170 my @tmp = @subfields_data;
171 $tag_data{subfield} = \@tmp;
172 push( @loop_data, \%tag_data );
173 undef @subfields_data;
175 @fields = $record->fields();
176 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
178 # if tag <10, there's no subfield, use the "@" trick
179 if ( $fields[$x_i]->tag() < 10 ) {
182 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
183 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} );
185 $subfield_data{marc_lib} =
186 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
187 $subfield_data{marc_value} = $fields[$x_i]->data();
188 $subfield_data{marc_subfield} = '@';
189 $subfield_data{marc_tag} = $fields[$x_i]->tag();
190 push( @subfields_data, \%subfield_data );
193 my @subf = $fields[$x_i]->subfields;
195 # loop through each subfield
196 for my $i ( 0 .. $#subf ) {
197 $subf[$i][0] = "@" unless $subf[$i][0];
200 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
203 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
206 $subfield_data{short_desc} = substr(
207 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib},
210 $subfield_data{long_desc} =
211 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
212 $subfield_data{link} =
213 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
215 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
216 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
219 $subfield_data{marc_value} =
220 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
222 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
223 ->{kohafield} eq "biblioitems.isbn" )
226 # 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]);
227 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
230 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
233 $subfield_data{authority} = $fields[$x_i]->subfield(9);
235 $subfield_data{marc_value} =
236 get_authorised_value_desc( $tagslib, $fields[$x_i]->tag(),
237 $subf[$i][0], $subf[$i][1], '', $dbh );
239 $subfield_data{marc_subfield} = $subf[$i][0];
240 $subfield_data{marc_tag} = $fields[$x_i]->tag();
241 push( @subfields_data, \%subfield_data );
244 if ( $#subfields_data == 0 ) {
245 $subfields_data[0]->{marc_lib} = '';
246 $subfields_data[0]->{marc_subfield} = '';
248 if ( $#subfields_data >= 0 ) {
250 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() ) {
254 if ( C4::Context->preference('hide_marc') ) {
255 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
259 $fields[$x_i]->tag() . ' -'
260 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
263 my @tmp = @subfields_data;
264 $tag_data{subfield} = \@tmp;
265 push( @loop_data, \%tag_data );
266 undef @subfields_data;
269 $template->param( $tabloop . "XX" => \@loop_data );
272 # now, build item tab !
273 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
274 # loop through each tag
275 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
276 # then construct template.
277 my @fields = $record->fields();
279 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
281 foreach my $field (@fields) {
282 next if ( $field->tag() < 10 );
283 my @subf = $field->subfields;
286 # loop through each subfield
287 for my $i ( 0 .. $#subf ) {
288 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
289 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
290 $witness{ $subf[$i][0] } =
291 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
292 $this_row{ $subf[$i][0] } = $subf[$i][1];
295 push( @big_array, \%this_row );
298 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField($dbh,"items.holdingbranch",$frameworkcode);
299 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
301 #fill big_row with missing datas
302 foreach my $subfield_code ( keys(%witness) ) {
303 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
304 $big_array[$i]{$subfield_code} = " "
305 unless ( $big_array[$i]{$subfield_code} );
309 # now, construct template !
311 my @header_value_loop;
312 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
314 foreach my $subfield_code ( keys(%witness) ) {
315 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
318 $row_data{item_value} = $items_data;
319 push( @item_value_loop, \%row_data );
321 foreach my $subfield_code ( keys(%witness) ) {
323 $header_value{header_value} = $witness{$subfield_code};
324 push( @header_value_loop, \%header_value );
327 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
329 if ($subscriptionsnumber) {
330 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
331 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
333 subscriptiontitle => $subscriptiontitle,
334 subscriptionsnumber => $subscriptionsnumber,
339 item_loop => \@item_value_loop,
340 item_header_loop => \@header_value_loop,
341 biblionumber => $biblionumber,
343 hide_marc => C4::Context->preference('hide_marc'),
344 intranetcolorstylesheet =>
345 C4::Context->preference("intranetcolorstylesheet"),
346 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
347 IntranetNav => C4::Context->preference("IntranetNav"),
351 output_html_with_http_headers $query, $cookie, $template->output;