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>.
23 use C4::Acquisition qw( GetHistory );
26 use C4::Serials; #uses getsubscriptionfrom biblionumber
33 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
34 use C4::External::Amazon;
35 use C4::Search; # enabled_staff_search_views
36 use C4::Tags qw(get_tags);
41 use C4::CourseReserves qw(GetItemCourseReservesInfo);
42 use C4::Acquisition qw(GetOrdersByBiblionumber);
43 use Koha::AuthorisedValues;
48 use Koha::Virtualshelves;
50 my $query = CGI->new();
52 my $analyze = $query->param('analyze');
54 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
56 template_name => 'catalogue/detail.tt',
60 flagsrequired => { catalogue => 1 },
64 my $biblionumber = $query->param('biblionumber');
65 $biblionumber = HTML::Entities::encode($biblionumber);
66 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
68 if ( not defined $record ) {
69 # biblionumber invalid -> report and exit
70 $template->param( unknownbiblionumber => 1,
71 biblionumber => $biblionumber );
72 output_html_with_http_headers $query, $cookie, $template->output;
76 if($query->cookie("holdfor")){
77 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
79 # FIXME Should pass the patron object
80 holdfor => $query->cookie("holdfor"),
81 holdfor_surname => $holdfor_patron->surname,
82 holdfor_firstname => $holdfor_patron->firstname,
83 holdfor_cardnumber => $holdfor_patron->cardnumber,
87 my $fw = GetFrameworkCode($biblionumber);
88 my $showallitems = $query->param('showallitems');
89 my $marcflavour = C4::Context->preference("marcflavour");
91 # XSLT processing of some stuff
92 my $xslfile = C4::Context->preference('XSLTDetailsDisplay');
93 my $lang = $xslfile ? C4::Languages::getlanguage() : undef;
94 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
98 XSLTDetailsDisplay => '1',
99 XSLTBloc => XSLTParse4Display(
100 $biblionumber, $record, "XSLTDetailsDisplay",
101 1, undef, $sysxml, $xslfile, $lang
106 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
107 $template->param( ocoins => GetCOinSBiblio($record) );
109 # some useful variables for enhanced content;
110 # in each case, we're grabbing the first value we find in
111 # the record and normalizing it
112 my $upc = GetNormalizedUPC($record,$marcflavour);
113 my $ean = GetNormalizedEAN($record,$marcflavour);
114 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
115 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
118 normalized_upc => $upc,
119 normalized_ean => $ean,
120 normalized_oclc => $oclc,
121 normalized_isbn => $isbn,
124 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
125 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
126 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
127 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
128 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
129 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
130 my $marchostsarray = GetMarcHosts($record,$marcflavour);
131 my $subtitle = GetRecordValue('subtitle', $record, $fw);
133 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
135 my $dbh = C4::Context->dbh;
137 my @all_items = GetItemsInfo( $biblionumber );
139 my $patron = Koha::Patrons->find( $borrowernumber );
140 for my $itm (@all_items) {
141 push @items, $itm unless ( $itm->{itemlost} && $patron->category->hidelostitems && !$showallitems);
144 # flag indicating existence of at least one item linked via a host record
146 # adding items linked via host biblios
147 my @hostitems = GetHostItemsInfo($record);
150 push (@items,@hostitems);
153 my $dat = &GetBiblioData($biblionumber);
155 #coping with subscriptions
156 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
157 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
160 foreach my $subscription (@subscriptions) {
162 my $serials_to_display;
163 $cell{subscriptionid} = $subscription->{subscriptionid};
164 $cell{subscriptionnotes} = $subscription->{internalnotes};
165 $cell{missinglist} = $subscription->{missinglist};
166 $cell{librariannote} = $subscription->{librariannote};
167 $cell{branchcode} = $subscription->{branchcode};
168 $cell{hasalert} = $subscription->{hasalert};
169 $cell{callnumber} = $subscription->{callnumber};
170 $cell{closed} = $subscription->{closed};
171 #get the three latest serials.
172 $serials_to_display = $subscription->{staffdisplaycount};
173 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
174 $cell{staffdisplaycount} = $serials_to_display;
175 $cell{latestserials} =
176 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
181 # Get acquisition details
182 if ( C4::Context->preference('AcquisitionDetails') ) {
183 my $orders = C4::Acquisition::GetHistory( biblionumber => $biblionumber, get_canceled_order => 1 );
189 if ( defined $dat->{'itemtype'} ) {
190 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
193 $dat->{'count'} = scalar @all_items + @hostitems;
194 $dat->{'showncount'} = scalar @items + @hostitems;
195 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
198 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.location' } ) };
200 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
202 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
203 my (@itemloop, @otheritemloop, %itemfields);
206 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => { not => undef } });
209 my $materials_authvals = GetAuthorisedValues($mss->next->authorised_value);
210 if ($materials_authvals) {
211 foreach my $value (@$materials_authvals) {
212 $materials_map{$value->{authorised_value}} = $value->{lib};
218 my $materials_flag; # set this if the items have anything in the materials field
219 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
220 if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
221 $template->param(SeparateHoldings => 1);
223 my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch';
224 foreach my $item (@items) {
225 my $itembranchcode = $item->{$separatebranch};
227 # can place holds defaults to yes
228 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
230 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
233 $item->{datedue} = format_sqldatetime($item->{datedue});
235 #get shelf location and collection code description if they are authorised value.
236 # same thing for copy number
237 my $shelfcode = $item->{'location'};
238 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
239 my $ccode = $item->{'ccode'};
240 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
241 my $copynumber = $item->{'copynumber'};
242 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
243 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) {
244 $itemfields{$_} = 1 if ( $item->{$_} );
248 my $item_object = Koha::Items->find( $item->{itemnumber} );
249 my $holds = $item_object->current_holds;
250 if ( my $first_hold = $holds->next ) {
251 my $patron = Koha::Patrons->find( $first_hold->borrowernumber );
252 $item->{backgroundcolor} = 'reserved';
253 $item->{reservedate} = $first_hold->reservedate;
254 $item->{ReservedFor} = $patron,
255 $item->{ExpectedAtLibrary} = $first_hold->branchcode;
256 # Check waiting status
257 $item->{waitingdate} = $first_hold->waitingdate;
260 if ( my $checkout = $item_object->checkout ) {
261 $item->{CheckedOutFor} = $checkout->patron;
264 # Check the transit status
265 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
266 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
267 $item->{transfertwhen} = $transfertwhen;
268 $item->{transfertfrom} = $transfertfrom;
269 $item->{transfertto} = $transfertto;
270 $item->{nocancel} = 1;
273 foreach my $f (qw( itemnotes )) {
275 $item->{$f} =~ s|\n|<br />|g;
280 #item has a host number if its biblio number does not match the current bib
282 if ($item->{biblionumber} ne $biblionumber){
283 $item->{hostbiblionumber} = $item->{biblionumber};
284 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
287 #count if item is used in analytical bibliorecords
288 my $countanalytics= GetAnalyticsCount($item->{itemnumber});
289 if ($countanalytics > 0){
291 $item->{countanalytics} = $countanalytics;
294 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
296 if (defined $materials_map{ $item->{materials} }) {
297 $item->{materials} = $materials_map{ $item->{materials} };
301 if ( C4::Context->preference('UseCourseReserves') ) {
302 $item->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->{'itemnumber'} );
305 if ( C4::Context->preference('IndependentBranches') ) {
306 my $userenv = C4::Context->userenv();
307 if ( not C4::Context->IsSuperLibrarian()
308 and $userenv->{branch} ne $item->{homebranch} ) {
309 $item->{cannot_be_edited} = 1;
313 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
314 and C4::Context->preference('SeparateHoldings')) {
315 if ($itembranchcode and $itembranchcode eq $currentbranch) {
316 push @itemloop, $item;
318 push @otheritemloop, $item;
321 push @itemloop, $item;
325 # Display only one tab if one items list is empty
326 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
327 $template->param(SeparateHoldings => 0);
328 if (scalar(@itemloop) == 0) {
329 @itemloop = @otheritemloop;
333 $template->param( norequests => $norequests );
335 MARCNOTES => $marcnotesarray,
336 MARCSUBJCTS => $marcsubjctsarray,
337 MARCAUTHORS => $marcauthorsarray,
338 MARCSERIES => $marcseriesarray,
339 MARCURLS => $marcurlsarray,
340 MARCISBNS => $marcisbnsarray,
341 MARCHOSTS => $marchostsarray,
342 subtitle => $subtitle,
343 itemdata_ccode => $itemfields{ccode},
344 itemdata_enumchron => $itemfields{enumchron},
345 itemdata_uri => $itemfields{uri},
346 itemdata_copynumber => $itemfields{copynumber},
347 itemdata_stocknumber => $itemfields{stocknumber},
348 volinfo => $itemfields{enumchron},
349 itemdata_itemnotes => $itemfields{itemnotes},
350 itemdata_nonpublicnotes => $itemfields{itemnotes_nonpublic},
351 z3950_search_params => C4::Search::z3950_search_args($dat),
352 hostrecords => $hostrecords,
353 analytics_flag => $analytics_flag,
354 C4::Search::enabled_staff_search_views,
355 materials => $materials_flag,
358 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
359 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
360 my $subfields = substr $fieldspec, 3;
361 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
362 my @alternateholdingsinfo = ();
363 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
365 for my $field (@holdingsfields) {
366 my %holding = ( holding => '' );
367 my $havesubfield = 0;
368 for my $subfield ($field->subfields()) {
369 if ((index $subfields, $$subfield[0]) >= 0) {
370 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
371 $holding{'holding'} .= $$subfield[1];
376 push(@alternateholdingsinfo, \%holding);
381 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
385 my @results = ( $dat, );
386 foreach ( keys %{$dat} ) {
387 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
390 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
391 # method query not found?!?!
392 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages"));
394 itemloop => \@itemloop,
395 otheritemloop => \@otheritemloop,
396 biblionumber => $biblionumber,
397 ($analyze? 'analyze':'detailview') =>1,
398 subscriptions => \@subs,
399 subscriptionsnumber => $subscriptionsnumber,
400 subscriptiontitle => $dat->{title},
401 searchid => scalar $query->param('searchid'),
404 # $debug and $template->param(debug_display => 1);
408 if (C4::Context->preference("virtualshelves") ) {
409 my $shelves = Koha::Virtualshelves->search(
411 biblionumber => $biblionumber,
415 join => 'virtualshelfcontents',
418 $template->param( 'shelves' => $shelves );
422 if (C4::Context->preference("FRBRizeEditions")==1) {
425 XISBNS => scalar get_xisbns($isbn)
428 if ($@) { warn "XISBN Failed $@"; }
431 if ( C4::Context->preference("LocalCoverImages") == 1 ) {
432 my @images = ListImagesForBiblio($biblionumber);
433 $template->{VARS}->{localimages} = \@images;
437 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'staff') ) {
438 $template->param( C4::HTML5Media->gethtml5media($record));
444 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
447 TagsShowOnDetail => $tag_quantity
449 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
450 'sort'=>'-weight', limit=>$tag_quantity}));
453 #we only need to pass the number of holds to the template
454 my $biblio = Koha::Biblios->find( $biblionumber );
455 my $holds = $biblio->holds;
456 $template->param( holdcount => $holds->count );
458 my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
459 if ($StaffDetailItemSelection) {
460 # Only enable item selection if user can execute at least one action
462 $flags->{superlibrarian}
464 ref $flags->{tools} eq 'HASH' && (
465 $flags->{tools}->{items_batchmod} # Modify selected items
466 || $flags->{tools}->{items_batchdel} # Delete selected items
469 || ( ref $flags->{tools} eq '' && $flags->{tools} )
473 StaffDetailItemSelection => $StaffDetailItemSelection );
477 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
478 my @deletedorders_using_biblio;
479 my @orders_using_biblio;
481 my @baskets_deletedorders;
483 foreach my $myorder (@allorders_using_biblio) {
484 my $basket = $myorder->{'basketno'};
485 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
486 push @deletedorders_using_biblio, $myorder;
487 unless (grep(/^$basket$/, @baskets_deletedorders)){
488 push @baskets_deletedorders,$myorder->{'basketno'};
492 push @orders_using_biblio, $myorder;
493 unless (grep(/^$basket$/, @baskets_orders)){
494 push @baskets_orders,$myorder->{'basketno'};
499 my $count_orders_using_biblio = scalar @orders_using_biblio ;
500 $template->param (countorders => $count_orders_using_biblio);
502 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
503 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
505 $template->param (basketsorders => \@baskets_orders);
506 $template->param (basketsdeletedorders => \@baskets_deletedorders);
508 output_html_with_http_headers $query, $cookie, $template->output;