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};
70 if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
72 my $itemtypedef = getitemtypeinfo($value);
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 = $query->param('frameworkcode');
99 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
101 $query->param('popup')
102 ; # if set to 1, then don't insert links, it's just to show the biblio
103 my $subscriptionid = $query->param('subscriptionid');
105 my $tagslib = &GetMarcStructure(1,$frameworkcode);
107 my $record = GetMarcBiblio($biblionumber);
110 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
112 template_name => "catalogue/MARCdetail.tmpl",
115 authnotrequired => 0,
116 flagsrequired => { catalogue => 1 },
121 #count of item linked
122 my $itemcount = GetItemsCount($biblionumber);
123 $template->param( count => $itemcount);
125 #Getting the list of all frameworks
127 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
132 push @select_fwk, "Default";
133 $select_fwk{"Default"} = "Default";
135 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
136 push @select_fwk, $fwk;
137 $select_fwk{$fwk} = $description;
139 $curfwk=$frameworkcode;
140 my $framework=CGI::scrolling_list( -name => 'Frameworks',
143 -OnChange => 'Changefwk(this);',
144 -values => \@select_fwk,
145 -labels => \%select_fwk,
148 $template->param(framework => $framework);
153 # loop through each tab 0 through 9
154 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
156 # loop through each tag
157 my @fields = $record->fields();
162 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
163 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
165 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
166 $subfield_data{marc_value} = $record->leader();
167 $subfield_data{marc_subfield} = '@';
168 $subfield_data{marc_tag} = '000';
169 push( @subfields_data, \%subfield_data );
171 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
172 my @tmp = @subfields_data;
173 $tag_data{subfield} = \@tmp;
174 push( @loop_data, \%tag_data );
175 undef @subfields_data;
177 @fields = $record->fields();
178 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
180 # if tag <10, there's no subfield, use the "@" trick
181 if ( $fields[$x_i]->tag() < 10 ) {
184 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
185 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} );
187 $subfield_data{marc_lib} =
188 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
189 $subfield_data{marc_value} = $fields[$x_i]->data();
190 $subfield_data{marc_subfield} = '@';
191 $subfield_data{marc_tag} = $fields[$x_i]->tag();
192 push( @subfields_data, \%subfield_data );
195 my @subf = $fields[$x_i]->subfields;
197 # loop through each subfield
198 for my $i ( 0 .. $#subf ) {
199 $subf[$i][0] = "@" unless $subf[$i][0];
202 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
205 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
208 $subfield_data{short_desc} = substr(
209 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib},
212 $subfield_data{long_desc} =
213 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
214 $subfield_data{link} =
215 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
217 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
218 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
221 $subfield_data{marc_value} =
222 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
224 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
225 ->{kohafield} eq "biblioitems.isbn" )
228 # 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]);
229 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
232 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
235 $subfield_data{authority} = $fields[$x_i]->subfield(9);
237 $subfield_data{marc_value} =
238 get_authorised_value_desc( $tagslib, $fields[$x_i]->tag(),
239 $subf[$i][0], $subf[$i][1], '', $dbh );
241 $subfield_data{marc_subfield} = $subf[$i][0];
242 $subfield_data{marc_tag} = $fields[$x_i]->tag();
243 push( @subfields_data, \%subfield_data );
246 if ( $#subfields_data == 0 ) {
247 $subfields_data[0]->{marc_lib} = '';
248 $subfields_data[0]->{marc_subfield} = '';
250 if ( $#subfields_data >= 0 ) {
252 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() ) {
256 if ( C4::Context->preference('hide_marc') ) {
257 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
261 $fields[$x_i]->tag() . ' -'
262 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
265 my @tmp = @subfields_data;
266 $tag_data{subfield} = \@tmp;
267 push( @loop_data, \%tag_data );
268 undef @subfields_data;
271 $template->param( $tabloop . "XX" => \@loop_data );
274 # now, build item tab !
275 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
276 # loop through each tag
277 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
278 # then construct template.
279 my @fields = $record->fields();
281 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
283 foreach my $field (@fields) {
284 next if ( $field->tag() < 10 );
285 my @subf = $field->subfields;
288 # loop through each subfield
289 for my $i ( 0 .. $#subf ) {
290 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
291 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
292 $witness{ $subf[$i][0] } =
293 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
294 $this_row{ $subf[$i][0] } = $subf[$i][1];
297 push( @big_array, \%this_row );
300 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
301 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
303 #fill big_row with missing datas
304 foreach my $subfield_code ( keys(%witness) ) {
305 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
306 $big_array[$i]{$subfield_code} = " "
307 unless ( $big_array[$i]{$subfield_code} );
311 # now, construct template !
313 my @header_value_loop;
314 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
316 foreach my $subfield_code ( keys(%witness) ) {
317 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
320 $row_data{item_value} = $items_data;
321 push( @item_value_loop, \%row_data );
323 foreach my $subfield_code ( keys(%witness) ) {
325 $header_value{header_value} = $witness{$subfield_code};
326 push( @header_value_loop, \%header_value );
329 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
331 if ($subscriptionsnumber) {
332 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
333 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
335 subscriptiontitle => $subscriptiontitle,
336 subscriptionsnumber => $subscriptionsnumber,
341 item_loop => \@item_value_loop,
342 item_header_loop => \@header_value_loop,
343 biblionumber => $biblionumber,
345 hide_marc => C4::Context->preference('hide_marc'),
348 output_html_with_http_headers $query, $cookie, $template->output;