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
59 use C4
::Serials
; #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60 use C4
::Search
; # enabled_staff_search_views
63 use Koha
::BiblioFrameworks
;
66 use List
::MoreUtils
qw( uniq );
69 my $dbh = C4
::Context
->dbh;
70 my $biblionumber = $query->param('biblionumber');
71 $biblionumber = HTML
::Entities
::encode
($biblionumber);
72 my $frameworkcode = $query->param('frameworkcode');
73 $frameworkcode = GetFrameworkCode
( $biblionumber ) unless ($frameworkcode);
75 $query->param('popup')
76 ; # if set to 1, then don't insert links, it's just to show the biblio
77 my $subscriptionid = $query->param('subscriptionid');
80 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
82 template_name
=> "catalogue/MARCdetail.tt",
86 flagsrequired
=> { catalogue
=> 1 },
91 my $record = GetMarcBiblio
($biblionumber, 1);
92 $template->param( ocoins
=> GetCOinSBiblio
($record) );
94 if ( not defined $record ) {
95 # biblionumber invalid -> report and exit
96 $template->param( unknownbiblionumber
=> 1,
97 biblionumber
=> $biblionumber
99 output_html_with_http_headers
$query, $cookie, $template->output;
103 my $biblio_object = Koha
::Biblios
->find( $biblionumber ); # FIXME Should replace $biblio
104 my $tagslib = &GetMarcStructure
(1,$frameworkcode);
105 my $biblio = GetBiblioData
($biblionumber);
107 if($query->cookie("holdfor")){
108 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
110 holdfor
=> $query->cookie("holdfor"),
111 holdfor_surname
=> $holdfor_patron->surname,
112 holdfor_firstname
=> $holdfor_patron->firstname,
113 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
117 #count of item linked
118 my $itemcount = $biblio_object->items->count;
119 $template->param( count
=> $itemcount,
120 bibliotitle
=> $biblio->{title
}, );
122 my $frameworks = Koha
::BiblioFrameworks
->search( {}, { order_by
=> ['frameworktext'] } );
124 frameworks
=> $frameworks,
125 frameworkcode
=> $frameworkcode,
130 # loop through each tab 0 through 9
131 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
133 # loop through each tag
134 my @fields = $record->fields();
139 unless ( $tagslib->{'000'}->{'@'}->{tab
} ne $tabloop )
140 { # or ($tagslib->{'000'}->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ )) {
142 $subfield_data{marc_lib
} = $tagslib->{'000'}->{'@'}->{lib
};
143 $subfield_data{marc_value
} = $record->leader();
144 $subfield_data{marc_subfield
} = '@';
145 $subfield_data{marc_tag
} = '000';
146 push( @subfields_data, \
%subfield_data );
148 $tag_data{tag
} = '000';
149 $tag_data{tag_desc
} = $tagslib->{'000'}->{lib
};
150 my @tmp = @subfields_data;
151 $tag_data{subfield
} = \
@tmp;
152 push( @loop_data, \
%tag_data );
153 undef @subfields_data;
155 @fields = $record->fields();
156 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
158 # if tag <10, there's no subfield, use the "@" trick
159 if ( $fields[$x_i]->tag() < 10 ) {
162 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab
} ne $tabloop );
163 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
165 $subfield_data{marc_lib
} =
166 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib
};
167 $subfield_data{marc_value
} = $fields[$x_i]->data();
168 $subfield_data{marc_subfield
} = '@';
169 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
170 push( @subfields_data, \
%subfield_data );
173 my @subf = $fields[$x_i]->subfields;
175 # loop through each subfield
176 for my $i ( 0 .. $#subf ) {
177 $subf[$i][0] = "@" unless defined $subf[$i][0];
180 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab
}
183 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
184 ->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
186 $subfield_data{short_desc
} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
187 $subfield_data{long_desc
} =
188 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib
};
189 $subfield_data{link} =
190 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
192 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
193 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
196 $subfield_data{marc_value
} = $subf[$i][1];
197 $subfield_data{is_url
} = 1;
199 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
200 ->{kohafield
} eq "biblioitems.isbn" )
203 # 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]);
204 $subfield_data{marc_value
} = $subf[$i][1];
207 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
210 $subfield_data{authority
} = $fields[$x_i]->subfield(9);
212 $subfield_data{marc_value
} =
213 GetAuthorisedValueDesc
( $fields[$x_i]->tag(),
214 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
217 $subfield_data{marc_subfield
} = $subf[$i][0];
218 $subfield_data{marc_tag
} = $fields[$x_i]->tag();
219 push( @subfields_data, \
%subfield_data );
222 if ( $#subfields_data == 0 ) {
223 $subfields_data[0]->{marc_lib
} = '';
224 # $subfields_data[0]->{marc_subfield} = '';
226 if ( $#subfields_data >= 0) {
228 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4
::Context
->preference('LabelMARCView') eq 'economical')) {
232 if ( C4
::Context
->preference('hide_marc') ) {
233 $tag_data{tag
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
236 $tag_data{tag
} = $fields[$x_i]->tag();
237 $tag_data{tag_ind
} = C4
::Koha
::display_marc_indicators
($fields[$x_i]);
238 $tag_data{tag_desc
} = $tagslib->{ $fields[$x_i]->tag() }->{lib
};
241 my @tmp = @subfields_data;
242 $tag_data{subfield
} = \
@tmp;
243 push( @loop_data, \
%tag_data );
244 undef @subfields_data;
247 $template->param( "tab" . $tabloop . "XX" => \
@loop_data );
250 # now, build item tab !
251 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
252 # loop through each tag
253 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
254 # then construct template.
255 my @fields = $record->fields();
257 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
258 my @item_subfield_codes;
261 foreach my $field (@fields) {
262 next if ( $field->tag() < 10 );
263 my @subf = $field->subfields;
266 # loop through each subfield
267 for my $i ( 0 .. $#subf ) {
268 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab
} ne 10 );
269 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden
} =~ /-7|-4|-3|-2|2|3|5|8/);
270 push @item_subfield_codes, $subf[$i][0];
271 $witness{ $subf[$i][0] } =
272 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib
};
273 $item->{ $subf[$i][0] } = GetAuthorisedValueDesc
( $field->tag(),
274 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
275 $norequests = 0 if $subf[$i][1] ==0 and $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield
} eq 'items.notforloan';
277 push @item_loop, $item if $item;
280 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField
("items.holdingbranch",$frameworkcode);
281 @item_loop = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @item_loop;
283 @item_subfield_codes = uniq
@item_subfield_codes;
285 my @item_header_loop;
286 for my $subfield_code ( @item_subfield_codes ) {
287 push @item_header_loop, $witness{$subfield_code};
288 for my $item_data ( @item_loop ) {
289 $item_data->{$subfield_code} ||= " "
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_loop,
307 item_header_loop
=> \
@item_header_loop,
308 item_subfield_codes
=> \
@item_subfield_codes,
309 biblionumber
=> $biblionumber,
311 hide_marc
=> C4
::Context
->preference('hide_marc'),
313 z3950_search_params
=> C4
::Search
::z3950_search_args
($biblio),
314 C4
::Search
::enabled_staff_search_views
,
315 searchid
=> scalar $query->param('searchid'),
318 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
319 my @deletedorders_using_biblio;
320 my @orders_using_biblio;
322 my @baskets_deletedorders;
324 foreach my $myorder (@allorders_using_biblio) {
325 my $basket = $myorder->{'basketno'};
326 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
327 push @deletedorders_using_biblio, $myorder;
328 unless (grep(/^$basket$/, @baskets_deletedorders)){
329 push @baskets_deletedorders,$myorder->{'basketno'};
333 push @orders_using_biblio, $myorder;
334 unless (grep(/^$basket$/, @baskets_orders)){
335 push @baskets_orders,$myorder->{'basketno'};
340 my $count_orders_using_biblio = scalar @orders_using_biblio ;
341 $template->param (countorders
=> $count_orders_using_biblio);
343 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
344 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
346 $biblio = Koha
::Biblios
->find( $biblionumber );
347 my $holds = $biblio->holds;
348 $template->param( holdcount
=> $holds->count );
350 output_html_with_http_headers
$query, $cookie, $template->output;