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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
47 #use warnings; FIXME - Bug 2505
58 use C4::Serials; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
59 use C4::Search; # enabled_staff_search_views
63 my $dbh = C4::Context->dbh;
64 my $biblionumber = $query->param('biblionumber');
65 my $frameworkcode = $query->param('frameworkcode');
66 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
68 $query->param('popup')
69 ; # if set to 1, then don't insert links, it's just to show the biblio
70 my $subscriptionid = $query->param('subscriptionid');
72 my $tagslib = &GetMarcStructure(1,$frameworkcode);
74 my $record = GetMarcBiblio($biblionumber);
75 my $biblio = GetBiblioData($biblionumber);
77 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
79 template_name => "catalogue/MARCdetail.tmpl",
83 flagsrequired => { catalogue => 1 },
89 my $itemcount = GetItemsCount($biblionumber);
90 $template->param( count => $itemcount,
91 bibliotitle => $biblio->{title}, );
93 # Getting the list of all frameworks
95 my $frameworks = getframeworks;
96 my @frameworkcodeloop;
97 foreach my $thisframeworkcode ( keys %$frameworks ) {
99 value => $thisframeworkcode,
100 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
102 if ($frameworkcode eq $thisframeworkcode){
105 push @frameworkcodeloop, \%row;
107 $template->param( frameworkcodeloop => \@frameworkcodeloop, );
112 # loop through each tab 0 through 9
113 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
115 # loop through each tag
116 my @fields = $record->fields();
121 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
122 { # or ($tagslib->{'000'}->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ )) {
124 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
125 $subfield_data{marc_value} = $record->leader();
126 $subfield_data{marc_subfield} = '@';
127 $subfield_data{marc_tag} = '000';
128 push( @subfields_data, \%subfield_data );
130 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
131 my @tmp = @subfields_data;
132 $tag_data{subfield} = \@tmp;
133 push( @loop_data, \%tag_data );
134 undef @subfields_data;
136 @fields = $record->fields();
137 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
139 # if tag <10, there's no subfield, use the "@" trick
140 if ( $fields[$x_i]->tag() < 10 ) {
143 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
144 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
146 $subfield_data{marc_lib} =
147 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
148 $subfield_data{marc_value} = $fields[$x_i]->data();
149 $subfield_data{marc_subfield} = '@';
150 $subfield_data{marc_tag} = $fields[$x_i]->tag();
151 push( @subfields_data, \%subfield_data );
154 my @subf = $fields[$x_i]->subfields;
156 # loop through each subfield
157 for my $i ( 0 .. $#subf ) {
158 $subf[$i][0] = "@" unless $subf[$i][0];
161 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
164 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
165 ->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
167 $subfield_data{short_desc} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
168 $subfield_data{long_desc} =
169 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
170 $subfield_data{link} =
171 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
173 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
174 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
177 $subfield_data{marc_value} = $subf[$i][1];
178 $subfield_data{is_url} = 1;
180 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
181 ->{kohafield} eq "biblioitems.isbn" )
184 # 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]);
185 $subfield_data{marc_value} = $subf[$i][1];
188 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
191 $subfield_data{authority} = $fields[$x_i]->subfield(9);
193 $subfield_data{marc_value} =
194 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
195 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
198 $subfield_data{marc_subfield} = $subf[$i][0];
199 $subfield_data{marc_tag} = $fields[$x_i]->tag();
200 push( @subfields_data, \%subfield_data );
203 if ( $#subfields_data == 0 ) {
204 $subfields_data[0]->{marc_lib} = '';
205 # $subfields_data[0]->{marc_subfield} = '';
207 if ( $#subfields_data >= 0) {
209 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4::Context->preference('LabelMARCView') eq 'economical')) {
213 if ( C4::Context->preference('hide_marc') ) {
214 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
220 . C4::Koha::display_marc_indicators($fields[$x_i])
222 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
225 my @tmp = @subfields_data;
226 $tag_data{subfield} = \@tmp;
227 push( @loop_data, \%tag_data );
228 undef @subfields_data;
231 $template->param( $tabloop . "XX" => \@loop_data );
234 # now, build item tab !
235 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
236 # loop through each tag
237 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
238 # then construct template.
239 my @fields = $record->fields();
241 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
244 foreach my $field (@fields) {
245 next if ( $field->tag() < 10 );
246 my @subf = $field->subfields;
249 # loop through each subfield
250 for my $i ( 0 .. $#subf ) {
251 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
252 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
253 $witness{ $subf[$i][0] } =
254 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
255 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(),
256 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
257 $norequests = 0 if $subf[$i][1] ==0 and $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.notforloan';
260 push( @big_array, \%this_row );
264 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
265 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
267 #fill big_row with missing datas
268 foreach my $subfield_code ( keys(%witness) ) {
269 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
270 $big_array[$i]{$subfield_code} = " "
271 unless ( $big_array[$i]{$subfield_code} );
275 # now, construct template !
277 my @header_value_loop;
278 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
280 foreach my $subfield_code ( keys(%witness) ) {
281 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
284 $row_data{item_value} = $items_data;
285 push( @item_value_loop, \%row_data );
287 foreach my $subfield_code ( keys(%witness) ) {
289 $header_value{header_value} = $witness{$subfield_code};
290 push( @header_value_loop, \%header_value );
293 my $subscriptionscount = CountSubscriptionFromBiblionumber($biblionumber);
295 if ($subscriptionscount) {
296 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
297 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
299 subscriptiontitle => $subscriptiontitle,
300 subscriptionsnumber => $subscriptionscount,
305 norequests => $norequests,
306 item_loop => \@item_value_loop,
307 item_header_loop => \@header_value_loop,
308 biblionumber => $biblionumber,
310 hide_marc => C4::Context->preference('hide_marc'),
312 z3950_search_params => C4::Search::z3950_search_args($biblio),
313 C4::Search::enabled_staff_search_views,
316 output_html_with_http_headers $query, $cookie, $template->output;