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 #Getting the list of all frameworks
121 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
126 push @select_fwk, "Default";
127 $select_fwk{"Default"} = "Default";
129 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
130 push @select_fwk, $fwk;
131 $select_fwk{$fwk} = $description;
133 $curfwk=$frameworkcode;
134 my $framework=CGI::scrolling_list( -name => 'Frameworks',
137 -OnChange => 'Changefwk(this);',
138 -values => \@select_fwk,
139 -labels => \%select_fwk,
142 $template->param(framework => $framework);
147 # loop through each tab 0 through 9
148 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
150 # loop through each tag
151 my @fields = $record->fields();
156 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
157 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
159 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
160 $subfield_data{marc_value} = $record->leader();
161 $subfield_data{marc_subfield} = '@';
162 $subfield_data{marc_tag} = '000';
163 push( @subfields_data, \%subfield_data );
165 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
166 my @tmp = @subfields_data;
167 $tag_data{subfield} = \@tmp;
168 push( @loop_data, \%tag_data );
169 undef @subfields_data;
171 @fields = $record->fields();
172 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
174 # if tag <10, there's no subfield, use the "@" trick
175 if ( $fields[$x_i]->tag() < 10 ) {
178 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
179 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} );
181 $subfield_data{marc_lib} =
182 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
183 $subfield_data{marc_value} = $fields[$x_i]->data();
184 $subfield_data{marc_subfield} = '@';
185 $subfield_data{marc_tag} = $fields[$x_i]->tag();
186 push( @subfields_data, \%subfield_data );
189 my @subf = $fields[$x_i]->subfields;
191 # loop through each subfield
192 for my $i ( 0 .. $#subf ) {
193 $subf[$i][0] = "@" unless $subf[$i][0];
196 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
199 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
202 $subfield_data{short_desc} = substr(
203 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib},
206 $subfield_data{long_desc} =
207 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
208 $subfield_data{link} =
209 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
211 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
212 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
215 $subfield_data{marc_value} =
216 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
218 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
219 ->{kohafield} eq "biblioitems.isbn" )
222 # 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]);
223 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
226 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
229 $subfield_data{authority} = $fields[$x_i]->subfield(9);
231 $subfield_data{marc_value} =
232 get_authorised_value_desc( $tagslib, $fields[$x_i]->tag(),
233 $subf[$i][0], $subf[$i][1], '', $dbh );
235 $subfield_data{marc_subfield} = $subf[$i][0];
236 $subfield_data{marc_tag} = $fields[$x_i]->tag();
237 push( @subfields_data, \%subfield_data );
240 if ( $#subfields_data == 0 ) {
241 $subfields_data[0]->{marc_lib} = '';
242 $subfields_data[0]->{marc_subfield} = '';
244 if ( $#subfields_data >= 0 ) {
246 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() ) {
250 if ( C4::Context->preference('hide_marc') ) {
251 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
255 $fields[$x_i]->tag() . ' -'
256 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
259 my @tmp = @subfields_data;
260 $tag_data{subfield} = \@tmp;
261 push( @loop_data, \%tag_data );
262 undef @subfields_data;
265 $template->param( $tabloop . "XX" => \@loop_data );
268 # now, build item tab !
269 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
270 # loop through each tag
271 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
272 # then construct template.
273 my @fields = $record->fields();
275 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
277 foreach my $field (@fields) {
278 next if ( $field->tag() < 10 );
279 my @subf = $field->subfields;
282 # loop through each subfield
283 for my $i ( 0 .. $#subf ) {
284 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
285 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
286 $witness{ $subf[$i][0] } =
287 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
288 $this_row{ $subf[$i][0] } = $subf[$i][1];
291 push( @big_array, \%this_row );
294 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField($dbh,"items.holdingbranch",$frameworkcode);
295 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
297 #fill big_row with missing datas
298 foreach my $subfield_code ( keys(%witness) ) {
299 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
300 $big_array[$i]{$subfield_code} = " "
301 unless ( $big_array[$i]{$subfield_code} );
305 # now, construct template !
307 my @header_value_loop;
308 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
310 foreach my $subfield_code ( keys(%witness) ) {
311 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
314 $row_data{item_value} = $items_data;
315 push( @item_value_loop, \%row_data );
317 foreach my $subfield_code ( keys(%witness) ) {
319 $header_value{header_value} = $witness{$subfield_code};
320 push( @header_value_loop, \%header_value );
323 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
325 if ($subscriptionsnumber) {
326 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
327 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
329 subscriptiontitle => $subscriptiontitle,
330 subscriptionsnumber => $subscriptionsnumber,
335 item_loop => \@item_value_loop,
336 item_header_loop => \@header_value_loop,
337 biblionumber => $biblionumber,
339 hide_marc => C4::Context->preference('hide_marc'),
340 intranetcolorstylesheet =>
341 C4::Context->preference("intranetcolorstylesheet"),
342 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
343 IntranetNav => C4::Context->preference("IntranetNav"),
347 output_html_with_http_headers $query, $cookie, $template->output;