3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
34 use C4
::XISBN
qw(get_xisbns);
35 use C4
::External
::Amazon
;
36 use C4
::Search
; # enabled_staff_search_views
37 use C4
::Tags
qw(get_tags);
42 use C4
::CourseReserves
qw(GetItemCourseReservesInfo);
43 use C4
::Acquisition
qw(GetOrdersByBiblionumber);
44 use Koha
::AuthorisedValues
;
46 use Koha
::Illrequests
;
50 use Koha
::Virtualshelves
;
53 my $query = CGI
->new();
55 my $analyze = $query->param('analyze');
57 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user
(
59 template_name
=> 'catalogue/detail.tt',
63 flagsrequired
=> { catalogue
=> 1 },
67 # Determine if we should be offering any enhancement plugin buttons
68 if ( C4
::Context
->config('enable_plugins') ) {
69 # Only pass plugins that can offer a toolbar button
70 my @plugins = Koha
::Plugins
->new()->GetPlugins({
71 method
=> 'intranet_catalog_biblio_enhancements_toolbar_button'
74 my @tab_plugins = Koha
::Plugins
->new()->GetPlugins({
75 method
=> 'intranet_catalog_biblio_tab',
78 foreach my $tab_plugin (@tab_plugins) {
82 @biblio_tabs = $tab_plugin->intranet_catalog_biblio_tab();
83 foreach my $tab (@biblio_tabs) {
84 my $tab_id = 'tab-' . $tab->title;
85 $tab_id =~ s/[^0-9A-Za-z]+/-/g;
91 warn "Error calling 'intranet_catalog_biblio_tab' on the " . $tab_plugin->{class} . "plugin ($_)";
101 my $biblionumber = $query->param('biblionumber');
102 $biblionumber = HTML
::Entities
::encode
($biblionumber);
103 my $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
104 my $biblio = Koha
::Biblios
->find( $biblionumber );
105 $template->param( 'biblio', $biblio );
107 if ( not defined $record ) {
108 # biblionumber invalid -> report and exit
109 $template->param( unknownbiblionumber
=> 1,
110 biblionumber
=> $biblionumber );
111 output_html_with_http_headers
$query, $cookie, $template->output;
115 eval { $biblio->metadata->record };
116 $template->param( decoding_error
=> $@
);
118 if($query->cookie("holdfor")){
119 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
121 # FIXME Should pass the patron object
122 holdfor
=> $query->cookie("holdfor"),
123 holdfor_surname
=> $holdfor_patron->surname,
124 holdfor_firstname
=> $holdfor_patron->firstname,
125 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
129 if($query->cookie("searchToOrder")){
130 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
132 searchtoorder_basketno
=> $basketno,
133 searchtoorder_vendorid
=> $vendorid
137 my $fw = GetFrameworkCode
($biblionumber);
138 my $showallitems = $query->param('showallitems');
139 my $marcflavour = C4
::Context
->preference("marcflavour");
141 # XSLT processing of some stuff
142 my $xslfile = C4
::Context
->preference('XSLTDetailsDisplay') || "default";
143 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
144 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
148 XSLTDetailsDisplay
=> '1',
149 XSLTBloc
=> XSLTParse4Display
(
150 $biblionumber, $record, "XSLTDetailsDisplay",
151 1, undef, $sysxml, $xslfile, $lang
156 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
158 # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid
159 # Do not propagate it as we already deal with it previously in this script
160 my $coins = eval { $biblio->get_coins };
161 $template->param( ocoins
=> $coins );
163 # some useful variables for enhanced content;
164 # in each case, we're grabbing the first value we find in
165 # the record and normalizing it
166 my $upc = GetNormalizedUPC
($record,$marcflavour);
167 my $ean = GetNormalizedEAN
($record,$marcflavour);
168 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
169 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
172 normalized_upc
=> $upc,
173 normalized_ean
=> $ean,
174 normalized_oclc
=> $oclc,
175 normalized_isbn
=> $isbn,
178 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
179 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
180 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
181 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
182 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
183 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
184 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
186 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search->unblessed } };
188 my $dbh = C4
::Context
->dbh;
190 my @all_items = GetItemsInfo
( $biblionumber );
192 my $patron = Koha
::Patrons
->find( $borrowernumber );
193 for my $itm (@all_items) {
194 push @items, $itm unless ( $itm->{itemlost
} && $patron->category->hidelostitems && !$showallitems);
197 # flag indicating existence of at least one item linked via a host record
199 # adding items linked via host biblios
200 my @hostitems = GetHostItemsInfo
($record);
203 push (@items,@hostitems);
206 my $dat = &GetBiblioData
($biblionumber);
208 #coping with subscriptions
209 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
210 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
213 foreach my $subscription (@subscriptions) {
215 my $serials_to_display;
216 $cell{subscriptionid
} = $subscription->{subscriptionid
};
217 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
218 $cell{missinglist
} = $subscription->{missinglist
};
219 $cell{librariannote
} = $subscription->{librariannote
};
220 $cell{branchcode
} = $subscription->{branchcode
};
221 $cell{hasalert
} = $subscription->{hasalert
};
222 $cell{callnumber
} = $subscription->{callnumber
};
223 $cell{location
} = $subscription->{location
};
224 $cell{closed
} = $subscription->{closed
};
225 #get the three latest serials.
226 $serials_to_display = $subscription->{staffdisplaycount
};
227 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
228 $cell{staffdisplaycount
} = $serials_to_display;
229 $cell{latestserials
} =
230 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
235 # Get acquisition details
236 if ( C4
::Context
->preference('AcquisitionDetails') ) {
237 my $orders = Koha
::Acquisition
::Orders
->search(
238 { biblionumber
=> $biblionumber },
241 order_by
=> 'basketno.booksellerid'
243 ); # GetHistory sorted by aqbooksellerid, but does it make sense?
250 if ( C4
::Context
->preference('suggestion') ) {
251 my $suggestions = Koha
::Suggestions
->search(
253 biblionumber
=> $biblionumber,
257 order_by
=> { -desc
=> 'suggesteddate' }
260 my $nb_archived_suggestions = Koha
::Suggestions
->search({ biblionumber
=> $biblionumber, archived
=> 1 })->count;
261 $template->param( suggestions
=> $suggestions, nb_archived_suggestions
=> $nb_archived_suggestions );
264 if ( defined $dat->{'itemtype'} ) {
265 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
268 $dat->{'count'} = scalar @all_items + @hostitems;
269 $dat->{'showncount'} = scalar @items + @hostitems;
270 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
273 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.location' } ) };
275 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
277 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
278 my (@itemloop, @otheritemloop, %itemfields);
281 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
283 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
285 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
287 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
289 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.withdrawn', authorised_value
=> { not => undef } });
291 $template->param( itemwithdrawnloop
=> GetAuthorisedValues
( $mss->next->authorised_value) );
294 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.materials', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
297 my $materials_authvals = GetAuthorisedValues
($mss->next->authorised_value);
298 if ($materials_authvals) {
299 foreach my $value (@
$materials_authvals) {
300 $materials_map{$value->{authorised_value
}} = $value->{lib
};
306 my $materials_flag; # set this if the items have anything in the materials field
307 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
308 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
309 $template->param(SeparateHoldings
=> 1);
311 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
312 foreach my $item (@items) {
313 my $itembranchcode = $item->{$separatebranch};
315 # can place holds defaults to yes
316 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
318 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
321 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
323 #get shelf location and collection code description if they are authorised value.
324 # same thing for copy number
325 my $shelfcode = $item->{'location'};
326 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
327 my $ccode = $item->{'ccode'};
328 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
329 my $copynumber = $item->{'copynumber'};
330 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
331 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri publisheddate)) { # Warning when removing GetItemsInfo - publisheddate (at least) is not part of the items table
332 $itemfields{$_} = 1 if ( $item->{$_} );
336 my $item_object = Koha
::Items
->find( $item->{itemnumber
} );
337 my $holds = $item_object->current_holds;
338 if ( my $first_hold = $holds->next ) {
339 $item->{first_hold
} = $first_hold;
342 if ( my $checkout = $item_object->checkout ) {
343 $item->{CheckedOutFor
} = $checkout->patron;
346 # Check the transit status
347 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
348 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
349 $item->{transfertwhen
} = $transfertwhen;
350 $item->{transfertfrom
} = $transfertfrom;
351 $item->{transfertto
} = $transfertto;
352 $item->{nocancel
} = 1;
355 foreach my $f (qw( itemnotes )) {
357 $item->{$f} =~ s
|\n|<br
/>|g
;
362 #item has a host number if its biblio number does not match the current bib
364 if ($item->{biblionumber
} ne $biblionumber){
365 $item->{hostbiblionumber
} = $item->{biblionumber
};
366 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
371 # count if item is used in analytical bibliorecords
372 # The 'countanalytics' flag is only used in the templates if analyze is set
373 my $countanalytics = C4
::Context
->preference('EasyAnalyticalRecords') ? GetAnalyticsCount
($item->{itemnumber
}) : 0;
374 if ($countanalytics > 0){
376 $item->{countanalytics
} = $countanalytics;
380 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
382 if (defined $materials_map{ $item->{materials
} }) {
383 $item->{materials
} = $materials_map{ $item->{materials
} };
387 if ( C4
::Context
->preference('UseCourseReserves') ) {
388 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
391 if ( C4
::Context
->preference('IndependentBranches') ) {
392 my $userenv = C4
::Context
->userenv();
393 if ( not C4
::Context
->IsSuperLibrarian()
394 and $userenv->{branch
} ne $item->{homebranch
} ) {
395 $item->{cannot_be_edited
} = 1;
399 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
400 if ($itembranchcode and $itembranchcode eq $currentbranch) {
401 push @itemloop, $item;
403 push @otheritemloop, $item;
406 push @itemloop, $item;
410 # Display only one tab if one items list is empty
411 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
412 $template->param(SeparateHoldings
=> 0);
413 if (scalar(@itemloop) == 0) {
414 @itemloop = @otheritemloop;
418 $template->param( norequests
=> $norequests );
420 MARCNOTES
=> $marcnotesarray,
421 MARCSUBJCTS
=> $marcsubjctsarray,
422 MARCAUTHORS
=> $marcauthorsarray,
423 MARCSERIES
=> $marcseriesarray,
424 MARCURLS
=> $marcurlsarray,
425 MARCISBNS
=> $marcisbnsarray,
426 MARCHOSTS
=> $marchostsarray,
427 itemdata_ccode
=> $itemfields{ccode
},
428 itemdata_enumchron
=> $itemfields{enumchron
},
429 itemdata_uri
=> $itemfields{uri
},
430 itemdata_copynumber
=> $itemfields{copynumber
},
431 itemdata_stocknumber
=> $itemfields{stocknumber
},
432 itemdata_publisheddate
=> $itemfields{publisheddate
},
433 volinfo
=> $itemfields{enumchron
},
434 itemdata_itemnotes
=> $itemfields{itemnotes
},
435 itemdata_nonpublicnotes
=> $itemfields{itemnotes_nonpublic
},
436 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
437 hostrecords
=> $hostrecords,
438 analytics_flag
=> $analytics_flag,
439 C4
::Search
::enabled_staff_search_views
,
440 materials
=> $materials_flag,
443 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
444 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
445 my $subfields = substr $fieldspec, 3;
446 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
447 my @alternateholdingsinfo = ();
448 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
450 for my $field (@holdingsfields) {
451 my %holding = ( holding
=> '' );
452 my $havesubfield = 0;
453 for my $subfield ($field->subfields()) {
454 if ((index $subfields, $$subfield[0]) >= 0) {
455 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
456 $holding{'holding'} .= $$subfield[1];
461 push(@alternateholdingsinfo, \
%holding);
466 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
470 my @results = ( $dat, );
471 foreach ( keys %{$dat} ) {
472 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
475 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
476 # method query not found?!?!
477 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
479 itemloop
=> \
@itemloop,
480 otheritemloop
=> \
@otheritemloop,
481 biblionumber
=> $biblionumber,
482 ($analyze?
'analyze':'detailview') =>1,
483 subscriptions
=> \
@subs,
484 subscriptionsnumber
=> $subscriptionsnumber,
485 subscriptiontitle
=> $dat->{title
},
486 searchid
=> scalar $query->param('searchid'),
489 # $debug and $template->param(debug_display => 1);
493 if (C4
::Context
->preference("virtualshelves") ) {
494 my $shelves = Koha
::Virtualshelves
->search(
496 biblionumber
=> $biblionumber,
500 join => 'virtualshelfcontents',
503 $template->param( 'shelves' => $shelves );
507 if (C4
::Context
->preference("FRBRizeEditions")==1) {
510 XISBNS
=> scalar get_xisbns
($isbn, $biblionumber)
513 if ($@
) { warn "XISBN Failed $@"; }
516 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
517 my @images = ListImagesForBiblio
($biblionumber);
518 $template->{VARS
}->{localimages
} = \
@images;
522 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
523 $template->param( C4
::HTML5Media
->gethtml5media($record));
529 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
532 TagsShowOnDetail
=> $tag_quantity
534 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
535 'sort'=>'-weight', limit
=>$tag_quantity}));
538 #we only need to pass the number of holds to the template
539 my $holds = $biblio->holds;
540 $template->param( holdcount
=> $holds->count );
542 # Check if there are any ILL requests connected to the biblio
544 C4
::Context
->preference('ILLModule')
545 ? Koha
::Illrequests
->search( { biblio_id
=> $biblionumber } )
547 $template->param( illrequests
=> $illrequests );
549 my $StaffDetailItemSelection = C4
::Context
->preference('StaffDetailItemSelection');
550 if ($StaffDetailItemSelection) {
551 # Only enable item selection if user can execute at least one action
553 $flags->{superlibrarian
}
555 ref $flags->{tools
} eq 'HASH' && (
556 $flags->{tools
}->{items_batchmod
} # Modify selected items
557 || $flags->{tools
}->{items_batchdel
} # Delete selected items
560 || ( ref $flags->{tools
} eq '' && $flags->{tools
} )
564 StaffDetailItemSelection
=> $StaffDetailItemSelection );
568 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
569 my @deletedorders_using_biblio;
570 my @orders_using_biblio;
572 my @baskets_deletedorders;
574 foreach my $myorder (@allorders_using_biblio) {
575 my $basket = $myorder->{'basketno'};
576 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
577 push @deletedorders_using_biblio, $myorder;
578 unless (grep{ $_ eq $basket } @baskets_deletedorders){
579 push @baskets_deletedorders,$myorder->{'basketno'};
583 push @orders_using_biblio, $myorder;
584 unless (grep{ $_ eq $basket } @baskets_orders){
585 push @baskets_orders,$myorder->{'basketno'};
590 $template->param(biblio
=> $biblio);
592 my $count_orders_using_biblio = scalar @orders_using_biblio ;
593 $template->param (countorders
=> $count_orders_using_biblio);
595 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
596 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
598 $template->param (basketsorders
=> \
@baskets_orders);
599 $template->param (basketsdeletedorders
=> \
@baskets_deletedorders);
601 output_html_with_http_headers
$query, $cookie, $template->output;