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 = $query->param('frameworkcode');
98 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
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(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 #count of item linked
121 my $itemcount = GetItemsCount($biblionumber);
122 $template->param( count => $itemcount);
124 #Getting the list of all frameworks
126 $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
131 push @select_fwk, "Default";
132 $select_fwk{"Default"} = "Default";
134 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
135 push @select_fwk, $fwk;
136 $select_fwk{$fwk} = $description;
138 $curfwk=$frameworkcode;
139 my $framework=CGI::scrolling_list( -name => 'Frameworks',
142 -OnChange => 'Changefwk(this);',
143 -values => \@select_fwk,
144 -labels => \%select_fwk,
147 $template->param(framework => $framework);
152 # loop through each tab 0 through 9
153 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
155 # loop through each tag
156 my @fields = $record->fields();
161 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
162 { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) {
164 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
165 $subfield_data{marc_value} = $record->leader();
166 $subfield_data{marc_subfield} = '@';
167 $subfield_data{marc_tag} = '000';
168 push( @subfields_data, \%subfield_data );
170 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
171 my @tmp = @subfields_data;
172 $tag_data{subfield} = \@tmp;
173 push( @loop_data, \%tag_data );
174 undef @subfields_data;
176 @fields = $record->fields();
177 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
179 # if tag <10, there's no subfield, use the "@" trick
180 if ( $fields[$x_i]->tag() < 10 ) {
183 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
184 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} );
186 $subfield_data{marc_lib} =
187 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
188 $subfield_data{marc_value} = $fields[$x_i]->data();
189 $subfield_data{marc_subfield} = '@';
190 $subfield_data{marc_tag} = $fields[$x_i]->tag();
191 push( @subfields_data, \%subfield_data );
194 my @subf = $fields[$x_i]->subfields;
196 # loop through each subfield
197 for my $i ( 0 .. $#subf ) {
198 $subf[$i][0] = "@" unless $subf[$i][0];
201 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
204 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
207 $subfield_data{short_desc} = substr(
208 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib},
211 $subfield_data{long_desc} =
212 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
213 $subfield_data{link} =
214 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
216 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
217 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
220 $subfield_data{marc_value} =
221 "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
223 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
224 ->{kohafield} eq "biblioitems.isbn" )
227 # 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]);
228 $subfield_data{marc_value} = DisplayISBN( $subf[$i][1] );
231 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
234 $subfield_data{authority} = $fields[$x_i]->subfield(9);
236 $subfield_data{marc_value} =
237 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
238 $subf[$i][0], $subf[$i][1], '', $tagslib );
240 $subfield_data{marc_subfield} = $subf[$i][0];
241 $subfield_data{marc_tag} = $fields[$x_i]->tag();
242 push( @subfields_data, \%subfield_data );
245 if ( $#subfields_data == 0 ) {
246 $subfields_data[0]->{marc_lib} = '';
247 $subfields_data[0]->{marc_subfield} = '';
249 if ( $#subfields_data >= 0 ) {
251 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() ) {
255 if ( C4::Context->preference('hide_marc') ) {
256 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
260 $fields[$x_i]->tag() . ' -'
261 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
264 my @tmp = @subfields_data;
265 $tag_data{subfield} = \@tmp;
266 push( @loop_data, \%tag_data );
267 undef @subfields_data;
270 $template->param( $tabloop . "XX" => \@loop_data );
273 # now, build item tab !
274 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
275 # loop through each tag
276 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
277 # then construct template.
278 my @fields = $record->fields();
280 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
282 foreach my $field (@fields) {
283 next if ( $field->tag() < 10 );
284 my @subf = $field->subfields;
287 # loop through each subfield
288 for my $i ( 0 .. $#subf ) {
289 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
290 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} );
291 $witness{ $subf[$i][0] } =
292 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
293 $this_row{ $subf[$i][0] } = $subf[$i][1];
296 push( @big_array, \%this_row );
299 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
300 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
302 #fill big_row with missing datas
303 foreach my $subfield_code ( keys(%witness) ) {
304 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
305 $big_array[$i]{$subfield_code} = " "
306 unless ( $big_array[$i]{$subfield_code} );
310 # now, construct template !
312 my @header_value_loop;
313 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
315 foreach my $subfield_code ( keys(%witness) ) {
316 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
319 $row_data{item_value} = $items_data;
320 push( @item_value_loop, \%row_data );
322 foreach my $subfield_code ( keys(%witness) ) {
324 $header_value{header_value} = $witness{$subfield_code};
325 push( @header_value_loop, \%header_value );
328 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
330 if ($subscriptionsnumber) {
331 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
332 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
334 subscriptiontitle => $subscriptiontitle,
335 subscriptionsnumber => $subscriptionsnumber,
340 item_loop => \@item_value_loop,
341 item_header_loop => \@header_value_loop,
342 biblionumber => $biblionumber,
344 hide_marc => C4::Context->preference('hide_marc'),
345 intranetcolorstylesheet =>
346 C4::Context->preference("intranetcolorstylesheet"),
347 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
348 IntranetNav => C4::Context->preference("IntranetNav"),
352 output_html_with_http_headers $query, $cookie, $template->output;