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
50 use C4::Auth qw( get_template_and_user );
52 use C4::Output qw( output_html_with_http_headers );
55 GetAuthorisedValueDesc
62 use C4::Serials qw( CountSubscriptionFromBiblionumber GetSubscription GetSubscriptionsFromBiblionumber );
63 use C4::Search qw( z3950_search_args enabled_staff_search_views );
66 use Koha::BiblioFrameworks;
68 use Koha::DateUtils qw( output_pref );
69 use Koha::Virtualshelves;
71 use List::MoreUtils qw( uniq );
74 my $dbh = C4::Context->dbh;
75 my $biblionumber = $query->param('biblionumber');
76 $biblionumber = HTML::Entities::encode($biblionumber);
77 my $frameworkcode = $query->param('frameworkcode') // GetFrameworkCode( $biblionumber );
79 $query->param('popup')
80 ; # if set to 1, then don't insert links, it's just to show the biblio
81 my $subscriptionid = $query->param('subscriptionid');
84 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
86 template_name => "catalogue/MARCdetail.tt",
89 flagsrequired => { catalogue => 1 },
93 my $record = GetMarcBiblio({
94 biblionumber => $biblionumber,
97 if ( not defined $record ) {
98 # biblionumber invalid -> report and exit
99 $template->param( unknownbiblionumber => 1,
100 biblionumber => $biblionumber
102 output_html_with_http_headers $query, $cookie, $template->output;
106 my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
107 my $tagslib = &GetMarcStructure(1,$frameworkcode);
108 my $biblio = GetBiblioData($biblionumber);
110 if($query->cookie("holdfor")){
111 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
113 holdfor => $query->cookie("holdfor"),
114 holdfor_patron => $holdfor_patron,
118 if( $query->cookie("searchToOrder") ){
119 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
121 searchtoorder_basketno => $basketno,
122 searchtoorder_vendorid => $vendorid
126 $template->param( ocoins => $biblio_object->get_coins );
128 #count of item linked
129 my $itemcount = $biblio_object->items->count;
130 $template->param( count => $itemcount,
131 bibliotitle => $biblio->{title}, );
133 my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'] } );
135 frameworks => $frameworks,
136 frameworkcode => $frameworkcode,
141 # loop through each tab 0 through 9
142 for ( my $tabloop = 0 ; $tabloop <= 10 ; $tabloop++ ) {
144 # loop through each tag
145 my @fields = $record->fields();
150 unless ( $tagslib->{'000'}->{'@'}->{tab} ne $tabloop )
151 { # or ($tagslib->{'000'}->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/ )) {
153 $subfield_data{marc_lib} = $tagslib->{'000'}->{'@'}->{lib};
154 $subfield_data{marc_value} = $record->leader();
155 $subfield_data{marc_subfield} = '@';
156 $subfield_data{marc_tag} = '000';
157 push( @subfields_data, \%subfield_data );
159 $tag_data{tag} = '000';
160 $tag_data{tag_desc} = $tagslib->{'000'}->{lib};
161 my @tmp = @subfields_data;
162 $tag_data{subfield} = \@tmp;
163 push( @loop_data, \%tag_data );
164 undef @subfields_data;
166 @fields = $record->fields();
167 for ( my $x_i = 0 ; $x_i <= $#fields ; $x_i++ ) {
169 # if tag <10, there's no subfield, use the "@" trick
170 if ( $fields[$x_i]->tag() < 10 ) {
173 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{tab} ne $tabloop );
174 next if ( $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
176 $subfield_data{marc_lib} =
177 $tagslib->{ $fields[$x_i]->tag() }->{'@'}->{lib};
178 $subfield_data{marc_value} = $fields[$x_i]->data();
179 $subfield_data{marc_subfield} = '@';
180 $subfield_data{marc_tag} = $fields[$x_i]->tag();
181 push( @subfields_data, \%subfield_data );
184 my @subf = $fields[$x_i]->subfields;
186 # loop through each subfield
187 for my $i ( 0 .. $#subf ) {
188 $subf[$i][0] = "@" unless defined $subf[$i][0];
191 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{tab}
194 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
195 ->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
197 $subfield_data{short_desc} = $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
198 $subfield_data{long_desc} =
199 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{lib};
200 $subfield_data{link} =
201 $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }->{link};
203 # warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link};
204 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
207 $subfield_data{marc_value} = $subf[$i][1];
208 $subfield_data{is_url} = 1;
210 elsif ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
211 ->{kohafield} eq "biblioitems.isbn" )
214 # 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]);
215 $subfield_data{marc_value} = $subf[$i][1];
218 if ( $tagslib->{ $fields[$x_i]->tag() }->{ $subf[$i][0] }
221 $subfield_data{authority} = $fields[$x_i]->subfield(9);
223 $subfield_data{marc_value} =
224 GetAuthorisedValueDesc( $fields[$x_i]->tag(),
225 $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
228 $subfield_data{marc_subfield} = $subf[$i][0];
229 $subfield_data{marc_tag} = $fields[$x_i]->tag();
230 push( @subfields_data, \%subfield_data );
233 if ( $#subfields_data == 0 ) {
234 $subfields_data[0]->{marc_lib} = '';
235 # $subfields_data[0]->{marc_subfield} = '';
237 if ( $#subfields_data >= 0) {
239 if ( $fields[$x_i]->tag() eq $fields[ $x_i - 1 ]->tag() && (C4::Context->preference('LabelMARCView') eq 'economical')) {
243 if ( C4::Context->preference('hide_marc') ) {
244 $tag_data{tag} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
247 $tag_data{tag} = $fields[$x_i]->tag();
248 $tag_data{tag_ind} = C4::Koha::display_marc_indicators($fields[$x_i]);
249 $tag_data{tag_desc} = $tagslib->{ $fields[$x_i]->tag() }->{lib};
252 my @tmp = @subfields_data;
253 $tag_data{subfield} = \@tmp;
254 push( @loop_data, \%tag_data );
255 undef @subfields_data;
258 $template->param( "tab" . $tabloop . "XX" => \@loop_data );
261 # now, build item tab !
262 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
263 # loop through each tag
264 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
265 # then construct template.
266 my @fields = $record->fields();
268 ; #---- stores the list of subfields used at least once, with the "meaning" of the code
269 my @item_subfield_codes;
272 foreach my $field (@fields) {
273 next if ( $field->tag() < 10 );
274 my @subf = $field->subfields;
277 # loop through each subfield
278 for my $i ( 0 .. $#subf ) {
279 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{tab} ne 10 );
280 next if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{hidden} =~ /-7|-4|-3|-2|2|3|5|8/);
282 push @item_subfield_codes, $subf[$i][0];
283 $witness{ $subf[$i][0] } =
284 $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
286 # Allow repeatables (BZ 13574)
287 if( $item->{$subf[$i][0]}) {
288 $item->{$subf[$i][0]} .= ' | ';
290 $item->{$subf[$i][0]} = q{};
292 if( $tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl} ) {
293 $item->{$subf[$i][0]} .= "<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
295 $item->{ $subf[$i][0] } .= GetAuthorisedValueDesc( $field->tag(), $subf[$i][0], $subf[$i][1], '', $tagslib) || $subf[$i][1];
298 my $kohafield = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield};
299 $item->{ $subf[$i][0] } = output_pref( { str => $item->{ $subf[$i][0] }, dateonly => 1 } )
300 if grep { $kohafield eq $_ }
301 qw( items.dateaccessioned items.onloan items.datelastseen items.datelastborrowed items.replacementpricedate );
303 push @item_loop, $item if $item;
306 my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField( "items.holdingbranch" );
307 @item_loop = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @item_loop;
309 @item_subfield_codes = uniq @item_subfield_codes;
311 my @item_header_loop;
312 for my $subfield_code ( @item_subfield_codes ) {
313 push @item_header_loop, $witness{$subfield_code};
314 for my $item_data ( @item_loop ) {
315 $item_data->{$subfield_code} ||= " "
319 my $subscriptionscount = CountSubscriptionFromBiblionumber($biblionumber);
321 if ($subscriptionscount) {
322 my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
323 my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
325 subscriptiontitle => $subscriptiontitle,
326 subscriptionsnumber => $subscriptionscount,
330 # get biblionumbers stored in the cart
333 if($query->cookie("intranet_bib_list")){
334 my $cart_list = $query->cookie("intranet_bib_list");
335 @cart_list = split(/\//, $cart_list);
336 if ( grep {$_ eq $biblionumber} @cart_list) {
337 $template->param( incart => 1 );
341 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
343 borrowernumber => $loggedinuser,
348 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
350 borrowernumber => $loggedinuser,
358 add_to_some_private_shelves => $some_private_shelves,
359 add_to_some_public_shelves => $some_public_shelves,
363 item_loop => \@item_loop,
364 item_header_loop => \@item_header_loop,
365 item_subfield_codes => \@item_subfield_codes,
366 biblionumber => $biblionumber,
368 hide_marc => C4::Context->preference('hide_marc'),
370 z3950_search_params => C4::Search::z3950_search_args($biblio),
371 C4::Search::enabled_staff_search_views,
372 searchid => scalar $query->param('searchid'),
373 biblio => $biblio_object,
374 loggedinuser => $loggedinuser,
377 $template->param( holdcount => $biblio_object->holds->count );
379 output_html_with_http_headers $query, $cookie, $template->output;