3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 MARCdetail.pl : script to show a biblio in MARC format
31 This script needs a biblionumber as parameter
33 It shows the biblio in a (nice) MARC format depending on MARC
36 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
37 this template must be divided into 11 "tabs".
39 The first 10 tabs present the biblio, the 11th one presents
40 the items attached to the biblio
47 #use warnings; FIXME - Bug 2505
58 use C4
::Members
; # to use GetMember
59 use C4
::Serials
; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60 use C4
::Search
; # enabled_staff_search_views
64 my $dbh = C4
::Context
->dbh;
65 my $biblionumber = $query->param('biblionumber');
66 my $frameworkcode = $query->param('frameworkcode');
67 $frameworkcode = GetFrameworkCode
( $biblionumber ) unless ($frameworkcode);
69 $query->param('popup')
70 ; # if set to 1, then don't insert links, it's just to show the biblio
71 my $subscriptionid = $query->param('subscriptionid');
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
76 template_name
=> "catalogue/MARCdetail.tmpl",
80 flagsrequired
=> { catalogue
=> 1 },
85 my $record = GetMarcBiblio
($biblionumber);
86 $template->param( ocoins
=> GetCOinSBiblio
($record) );
88 if ( not defined $record ) {
89 # biblionumber invalid -> report and exit
90 $template->param( unknownbiblionumber
=> 1,
91 biblionumber
=> $biblionumber
93 output_html_with_http_headers
$query, $cookie, $template->output;
97 my $tagslib = &GetMarcStructure
(1,$frameworkcode);
98 my $biblio = GetBiblioData
($biblionumber);
100 if($query->cookie("holdfor")){
101 my $holdfor_patron = GetMember
('borrowernumber' => $query->cookie("holdfor"));
103 holdfor
=> $query->cookie("holdfor"),
104 holdfor_surname
=> $holdfor_patron->{'surname'},
105 holdfor_firstname
=> $holdfor_patron->{'firstname'},
106 holdfor_cardnumber
=> $holdfor_patron->{'cardnumber'},
110 #count of item linked
111 my $itemcount = GetItemsCount
($biblionumber);
112 $template->param( count
=> $itemcount,
113 bibliotitle
=> $biblio->{title
}, );
115 # Getting the list of all frameworks
117 my $frameworks = getframeworks
;
118 my @frameworkcodeloop;
119 foreach my $thisframeworkcode ( keys %$frameworks ) {
121 value
=> $thisframeworkcode,
122 frameworktext
=> $frameworks->{$thisframeworkcode}->{'frameworktext'},
124 if ($frameworkcode eq $thisframeworkcode){
127 push @frameworkcodeloop, \
%row;
129 $template->param( frameworkcodeloop
=> \
@frameworkcodeloop, );
134 # loop through each tab 0 through 9
135 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
137 # loop through each tag
138 my @fields = $record->fields();
143 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop )
144 { # or ($tagslib->{'000'}->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ )) {
146 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
147 $subfield_data{marc_value
} = $record->leader();
148 $subfield_data{marc_subfield
} = '@';
149 $subfield_data{marc_tag
} = '000';
150 push( @subfields_data, \
%subfield_data );
152 $tag_data{tag
} = '000 -' . $tagslib->{'000'}->{lib
};
153 my @tmp = @subfields_data;
154 $tag_data{subfield
} = \
@tmp;
155 push( @loop_data, \
%tag_data );
156 undef @subfields_data;
158 @fields = $record->fields();
159 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
161 # if tag <10, there's no subfield, use the "@" trick
162 if ( $fields[$x_i]->tag() < 10 ) {
165 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
166 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
168 $subfield_data{marc_lib
} =
169 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
170 $subfield_data{marc_value
} = $fields[$x_i]->data();
171 $subfield_data{marc_subfield
} = '@';
172 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
173 push( @subfields_data, \
%subfield_data );
176 my @subf = $fields[$x_i]->subfields;
178 # loop through each subfield
179 for my $i ( 0 .. $#subf ) {
180 $subf[$i][0] = "@" unless $subf[$i][0];
183 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab
}
186 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
187 ->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
189 $subfield_data{short_desc
} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
190 $subfield_data{long_desc
} =
191 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
192 $subfield_data{link} =
193 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
195 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
196 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
199 $subfield_data{marc_value
} = $subf[$i][1];
200 $subfield_data{is_url
} = 1;
202 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
203 ->{kohafield
} eq "biblioitems.isbn" )
206 # 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]);
207 $subfield_data{marc_value
} = $subf[$i][1];
210 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
213 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
215 $subfield_data{marc_value
} =
216 GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
217 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
220 $subfield_data{marc_subfield
} = $subf[$i][0];
221 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
222 push( @subfields_data, \
%subfield_data );
225 if ( $#subfields_data == 0 ) {
226 $subfields_data[0]->{marc_lib
} = '';
227 # $subfields_data[0]->{marc_subfield} = '';
229 if ( $#subfields_data >= 0) {
231 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4
::Context
->preference('LabelMARCView') eq 'economical')) {
235 if ( C4
::Context
->preference('hide_marc') ) {
236 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
242 . C4
::Koha
::display_marc_indicators
($fields[$x_i])
244 . $tagslib->{ $fields[$x_i]->tag() }->{lib
};
247 my @tmp = @subfields_data;
248 $tag_data{subfield
} = \
@tmp;
249 push( @loop_data, \
%tag_data );
250 undef @subfields_data;
253 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
256 # now, build item tab !
257 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
258 # loop through each tag
259 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
260 # then construct template.
261 my @fields = $record->fields();
263 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
266 foreach my $field (@fields) {
267 next if ( $field->tag() < 10 );
268 my @subf = $field->subfields;
271 # loop through each subfield
272 for my $i ( 0 .. $#subf ) {
273 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab
} ne 10 );
274 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
275 $witness{ $subf[$i][0] } =
276 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
};
277 $this_row{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(),
278 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
279 $norequests = 0 if $subf[$i][1] ==0 and $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield
} eq 'items.notforloan';
282 push( @big_array, \
%this_row );
286 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField
("items.holdingbranch",$frameworkcode);
287 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
289 #fill big_row with missing datas
290 foreach my $subfield_code ( keys(%witness) ) {
291 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
292 $big_array[$i]{$subfield_code} = " "
293 unless ( $big_array[$i]{$subfield_code} );
297 # now, construct template !
299 my @header_value_loop;
300 for ( my $i = 0 ; $i <= $#big_array ; $i++ ) {
302 foreach my $subfield_code ( keys(%witness) ) {
303 $items_data .= "<td>" . $big_array[$i]{$subfield_code} . "</td>";
306 $row_data{item_value
} = $items_data;
307 push( @item_value_loop, \
%row_data );
309 foreach my $subfield_code ( keys(%witness) ) {
311 $header_value{header_value
} = $witness{$subfield_code};
312 push( @header_value_loop, \
%header_value );
315 my $subscriptionscount = CountSubscriptionFromBiblionumber
($biblionumber);
317 if ($subscriptionscount) {
318 my $subscriptions = GetSubscriptionsFromBiblionumber
($biblionumber);
319 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
321 subscriptiontitle
=> $subscriptiontitle,
322 subscriptionsnumber
=> $subscriptionscount,
327 norequests
=> $norequests,
328 item_loop
=> \
@item_value_loop,
329 item_header_loop
=> \
@header_value_loop,
330 biblionumber
=> $biblionumber,
332 hide_marc
=> C4
::Context
->preference('hide_marc'),
334 z3950_search_params
=> C4
::Search
::z3950_search_args
($biblio),
335 C4
::Search
::enabled_staff_search_views
,
338 output_html_with_http_headers
$query, $cookie, $template->output;