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
30 This script needs a biblionumber as parameter
32 It shows the biblio in a (nice) MARC format depending on MARC
35 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
36 this template must be divided into 11 "tabs".
38 The first 10 tabs present the biblio, the 11th one presents
39 the items attached to the biblio
46 #use warnings; FIXME - Bug 2505
57 use C4::Members; # to use GetMember
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 },
88 if($query->cookie("holdfor")){
89 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
91 holdfor => $query->cookie("holdfor"),
92 holdfor_surname => $holdfor_patron->{'surname'},
93 holdfor_firstname => $holdfor_patron->{'firstname'},
94 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
99 my $itemcount = GetItemsCount($biblionumber);
100 $template->param( count => $itemcount,
101 bibliotitle => $biblio->{title}, );
103 # Getting the list of all frameworks
105 my $frameworks = getframeworks;
106 my @frameworkcodeloop;
107 foreach my $thisframeworkcode ( keys %$frameworks ) {
109 value => $thisframeworkcode,
110 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
112 if ($frameworkcode eq $thisframeworkcode){
115 push @frameworkcodeloop, \%row;
117 $template->param( frameworkcodeloop => \@frameworkcodeloop, );
122 # loop through each tab 0 through 9
123 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
125 # loop through each tag
126 my @fields = $record->fields();
131 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
132 { # or ($tagslib->{'000'}->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ )) {
134 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
135 $subfield_data{marc_value} = $record->leader();
136 $subfield_data{marc_subfield} = '@';
137 $subfield_data{marc_tag} = '000';
138 push( @subfields_data, \%subfield_data );
140 $tag_data{tag} = '000 -' . $tagslib->{'000'}->{lib};
141 my @tmp = @subfields_data;
142 $tag_data{subfield} = \@tmp;
143 push( @loop_data, \%tag_data );
144 undef @subfields_data;
146 @fields = $record->fields();
147 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
149 # if tag <10, there's no subfield, use the "@" trick
150 if ( $fields[$x_i]->tag() < 10 ) {
153 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
154 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
156 $subfield_data{marc_lib} =
157 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
158 $subfield_data{marc_value} = $fields[$x_i]->data();
159 $subfield_data{marc_subfield} = '@';
160 $subfield_data{marc_tag} = $fields[$x_i]->tag();
161 push( @subfields_data, \%subfield_data );
164 my @subf = $fields[$x_i]->subfields;
166 # loop through each subfield
167 for my $i ( 0 .. $#subf ) {
168 $subf[$i][0] = "@" unless $subf[$i][0];
171 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
174 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
175 ->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
177 $subfield_data{short_desc} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
178 $subfield_data{long_desc} =
179 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
180 $subfield_data{link} =
181 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
183 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
184 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
187 $subfield_data{marc_value} = $subf[$i][1];
188 $subfield_data{is_url} = 1;
190 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
191 ->{kohafield} eq "biblioitems.isbn" )
194 # 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]);
195 $subfield_data{marc_value} = $subf[$i][1];
198 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
201 $subfield_data{authority} = $fields[$x_i]->subfield(9);
203 $subfield_data{marc_value} =
204 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
205 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
208 $subfield_data{marc_subfield} = $subf[$i][0];
209 $subfield_data{marc_tag} = $fields[$x_i]->tag();
210 push( @subfields_data, \%subfield_data );
213 if ( $#subfields_data == 0 ) {
214 $subfields_data[0]->{marc_lib} = '';
215 # $subfields_data[0]->{marc_subfield} = '';
217 if ( $#subfields_data >= 0) {
219 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4::Context->preference('LabelMARCView') eq 'economical')) {
223 if ( C4::Context->preference('hide_marc') ) {
224 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
230 . C4::Koha::display_marc_indicators($fields[$x_i])
232 . $tagslib->{ $fields[$x_i]->tag() }->{lib};
235 my @tmp = @subfields_data;
236 $tag_data{subfield} = \@tmp;
237 push( @loop_data, \%tag_data );
238 undef @subfields_data;
241 $template->param( $tabloop . "XX" => \@loop_data );
244 # now, build item tab !
245 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
246 # loop through each tag
247 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
248 # then construct template.
249 my @fields = $record->fields();
251 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
254 foreach my $field (@fields) {
255 next if ( $field->tag() < 10 );
256 my @subf = $field->subfields;
259 # loop through each subfield
260 for my $i ( 0 .. $#subf ) {
261 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
262 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
263 $witness{ $subf[$i][0] } =
264 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
265 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc( $field->tag(),
266 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
267 $norequests = 0 if $subf[$i][1] ==0 and $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.notforloan';
270 push( @big_array, \%this_row );
274 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$frameworkcode);
275 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
277 #fill big_row with missing datas
278 foreach my $subfield_code ( keys(%witness) ) {
279 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
280 $big_array[$i]{$subfield_code} = " "
281 unless ( $big_array[$i]{$subfield_code} );
285 # now, construct template !
287 my @header_value_loop;
288 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
290 foreach my $subfield_code ( keys(%witness) ) {
291 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
294 $row_data{item_value} = $items_data;
295 push( @item_value_loop, \%row_data );
297 foreach my $subfield_code ( keys(%witness) ) {
299 $header_value{header_value} = $witness{$subfield_code};
300 push( @header_value_loop, \%header_value );
303 my $subscriptionscount = CountSubscriptionFromBiblionumber($biblionumber);
305 if ($subscriptionscount) {
306 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
307 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
309 subscriptiontitle => $subscriptiontitle,
310 subscriptionsnumber => $subscriptionscount,
315 norequests => $norequests,
316 item_loop => \@item_value_loop,
317 item_header_loop => \@header_value_loop,
318 biblionumber => $biblionumber,
320 hide_marc => C4::Context->preference('hide_marc'),
322 z3950_search_params => C4::Search::z3950_search_args($biblio),
323 C4::Search::enabled_staff_search_views,
326 output_html_with_http_headers $query, $cookie, $template->output;