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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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.tt.
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
62 use List
::MoreUtils
qw( uniq );
65 my $dbh = C4
::Context
->dbh;
66 my $biblionumber = $query->param('biblionumber');
67 my $frameworkcode = $query->param('frameworkcode');
68 $frameworkcode = GetFrameworkCode
( $biblionumber ) unless ($frameworkcode);
70 $query->param('popup')
71 ; # if set to 1, then don't insert links, it's just to show the biblio
72 my $subscriptionid = $query->param('subscriptionid');
75 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
77 template_name
=> "catalogue/MARCdetail.tt",
81 flagsrequired
=> { catalogue
=> 1 },
86 my $record = GetMarcBiblio
($biblionumber, 1);
87 $template->param( ocoins
=> GetCOinSBiblio
($record) );
89 if ( not defined $record ) {
90 # biblionumber invalid -> report and exit
91 $template->param( unknownbiblionumber
=> 1,
92 biblionumber
=> $biblionumber
94 output_html_with_http_headers
$query, $cookie, $template->output;
98 my $tagslib = &GetMarcStructure
(1,$frameworkcode);
99 my $biblio = GetBiblioData
($biblionumber);
101 if($query->cookie("holdfor")){
102 my $holdfor_patron = GetMember
('borrowernumber' => $query->cookie("holdfor"));
104 holdfor
=> $query->cookie("holdfor"),
105 holdfor_surname
=> $holdfor_patron->{'surname'},
106 holdfor_firstname
=> $holdfor_patron->{'firstname'},
107 holdfor_cardnumber
=> $holdfor_patron->{'cardnumber'},
111 #count of item linked
112 my $itemcount = GetItemsCount
($biblionumber);
113 $template->param( count
=> $itemcount,
114 bibliotitle
=> $biblio->{title
}, );
116 # Getting the list of all frameworks
118 my $frameworks = getframeworks
;
119 my @frameworkcodeloop;
120 foreach my $thisframeworkcode ( keys %$frameworks ) {
122 value
=> $thisframeworkcode,
123 frameworktext
=> $frameworks->{$thisframeworkcode}->{'frameworktext'},
125 if ($frameworkcode eq $thisframeworkcode){
128 push @frameworkcodeloop, \
%row;
130 $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';
153 $tag_data{tag_desc
} = $tagslib->{'000'}->{lib
};
154 my @tmp = @subfields_data;
155 $tag_data{subfield
} = \
@tmp;
156 push( @loop_data, \
%tag_data );
157 undef @subfields_data;
159 @fields = $record->fields();
160 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
162 # if tag <10, there's no subfield, use the "@" trick
163 if ( $fields[$x_i]->tag() < 10 ) {
166 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
167 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
169 $subfield_data{marc_lib
} =
170 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
171 $subfield_data{marc_value
} = $fields[$x_i]->data();
172 $subfield_data{marc_subfield
} = '@';
173 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
174 push( @subfields_data, \
%subfield_data );
177 my @subf = $fields[$x_i]->subfields;
179 # loop through each subfield
180 for my $i ( 0 .. $#subf ) {
181 $subf[$i][0] = "@" unless defined $subf[$i][0];
184 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab
}
187 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
188 ->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
190 $subfield_data{short_desc
} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
191 $subfield_data{long_desc
} =
192 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
193 $subfield_data{link} =
194 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
196 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
197 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
200 $subfield_data{marc_value
} = $subf[$i][1];
201 $subfield_data{is_url
} = 1;
203 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
204 ->{kohafield
} eq "biblioitems.isbn" )
207 # 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]);
208 $subfield_data{marc_value
} = $subf[$i][1];
211 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
214 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
216 $subfield_data{marc_value
} =
217 GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
218 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
221 $subfield_data{marc_subfield
} = $subf[$i][0];
222 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
223 push( @subfields_data, \
%subfield_data );
226 if ( $#subfields_data == 0 ) {
227 $subfields_data[0]->{marc_lib
} = '';
228 # $subfields_data[0]->{marc_subfield} = '';
230 if ( $#subfields_data >= 0) {
232 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4
::Context
->preference('LabelMARCView') eq 'economical')) {
236 if ( C4
::Context
->preference('hide_marc') ) {
237 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
240 $tag_data{tag
} = $fields[$x_i]->tag();
241 $tag_data{tag_ind
} = C4
::Koha
::display_marc_indicators
($fields[$x_i]);
242 $tag_data{tag_desc
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
245 my @tmp = @subfields_data;
246 $tag_data{subfield
} = \
@tmp;
247 push( @loop_data, \
%tag_data );
248 undef @subfields_data;
251 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
254 # now, build item tab !
255 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
256 # loop through each tag
257 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
258 # then construct template.
259 my @fields = $record->fields();
261 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
262 my @item_subfield_codes;
265 foreach my $field (@fields) {
266 next if ( $field->tag() < 10 );
267 my @subf = $field->subfields;
270 # loop through each subfield
271 for my $i ( 0 .. $#subf ) {
272 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab
} ne 10 );
273 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
274 push @item_subfield_codes, $subf[$i][0];
275 $witness{ $subf[$i][0] } =
276 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
};
277 $item->{ $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';
281 push @item_loop, $item if $item;
284 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField
("items.holdingbranch",$frameworkcode);
285 @item_loop = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @item_loop;
287 @item_subfield_codes = uniq
@item_subfield_codes;
289 my @item_header_loop;
290 for my $subfield_code ( @item_subfield_codes ) {
291 push @item_header_loop, $witness{$subfield_code};
292 for my $item_data ( @item_loop ) {
293 $item_data->{$subfield_code} ||= " "
297 my $subscriptionscount = CountSubscriptionFromBiblionumber
($biblionumber);
299 if ($subscriptionscount) {
300 my $subscriptions = GetSubscriptionsFromBiblionumber
($biblionumber);
301 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
303 subscriptiontitle
=> $subscriptiontitle,
304 subscriptionsnumber
=> $subscriptionscount,
309 norequests
=> $norequests,
310 item_loop
=> \
@item_loop,
311 item_header_loop
=> \
@item_header_loop,
312 item_subfield_codes
=> \
@item_subfield_codes,
313 biblionumber
=> $biblionumber,
315 hide_marc
=> C4
::Context
->preference('hide_marc'),
317 z3950_search_params
=> C4
::Search
::z3950_search_args
($biblio),
318 C4
::Search
::enabled_staff_search_views
,
319 searchid
=> scalar $query->param('searchid'),
322 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
323 my @deletedorders_using_biblio;
324 my @orders_using_biblio;
326 my @baskets_deletedorders;
328 foreach my $myorder (@allorders_using_biblio) {
329 my $basket = $myorder->{'basketno'};
330 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
331 push @deletedorders_using_biblio, $myorder;
332 unless (grep(/^$basket$/, @baskets_deletedorders)){
333 push @baskets_deletedorders,$myorder->{'basketno'};
337 push @orders_using_biblio, $myorder;
338 unless (grep(/^$basket$/, @baskets_orders)){
339 push @baskets_orders,$myorder->{'basketno'};
344 my $count_orders_using_biblio = scalar @orders_using_biblio ;
345 $template->param (countorders
=> $count_orders_using_biblio);
347 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
348 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
350 my $holds = C4
::Reserves
::GetReservesFromBiblionumber
({ biblionumber
=> $biblionumber, all_dates
=> 1 });
351 my $holdcount = scalar( @
$holds );
352 $template->param( holdcount
=> scalar ( @
$holds ) );
354 output_html_with_http_headers
$query, $cookie, $template->output;