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>.
26 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
33 use C4
::XISBN
qw(get_xisbns);
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
;
51 my $query = CGI
->new();
53 my $analyze = $query->param('analyze');
55 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user
(
57 template_name
=> 'catalogue/detail.tt',
61 flagsrequired
=> { catalogue
=> 1 },
65 # Determine if we should be offering any enhancement plugin buttons
66 if ( C4
::Context
->preference('UseKohaPlugins') &&
67 C4
::Context
->config('enable_plugins') ) {
68 # Only pass plugins that can offer a toolbar button
69 my @plugins = Koha
::Plugins
->new()->GetPlugins({
70 method
=> 'intranet_catalog_biblio_enhancements_toolbar_button'
77 my $biblionumber = $query->param('biblionumber');
78 $biblionumber = HTML
::Entities
::encode
($biblionumber);
79 my $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
81 if ( not defined $record ) {
82 # biblionumber invalid -> report and exit
83 $template->param( unknownbiblionumber
=> 1,
84 biblionumber
=> $biblionumber );
85 output_html_with_http_headers
$query, $cookie, $template->output;
89 if($query->cookie("holdfor")){
90 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
92 # FIXME Should pass the patron object
93 holdfor
=> $query->cookie("holdfor"),
94 holdfor_surname
=> $holdfor_patron->surname,
95 holdfor_firstname
=> $holdfor_patron->firstname,
96 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
100 my $fw = GetFrameworkCode
($biblionumber);
101 my $showallitems = $query->param('showallitems');
102 my $marcflavour = C4
::Context
->preference("marcflavour");
104 # XSLT processing of some stuff
105 my $xslfile = C4
::Context
->preference('XSLTDetailsDisplay');
106 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
107 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
111 XSLTDetailsDisplay
=> '1',
112 XSLTBloc
=> XSLTParse4Display
(
113 $biblionumber, $record, "XSLTDetailsDisplay",
114 1, undef, $sysxml, $xslfile, $lang
119 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
120 $template->param( ocoins
=> GetCOinSBiblio
($record) );
122 # some useful variables for enhanced content;
123 # in each case, we're grabbing the first value we find in
124 # the record and normalizing it
125 my $upc = GetNormalizedUPC
($record,$marcflavour);
126 my $ean = GetNormalizedEAN
($record,$marcflavour);
127 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
128 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
131 normalized_upc
=> $upc,
132 normalized_ean
=> $ean,
133 normalized_oclc
=> $oclc,
134 normalized_isbn
=> $isbn,
137 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
138 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
139 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
140 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
141 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
142 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
143 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
144 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
146 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search->unblessed } };
148 my $dbh = C4
::Context
->dbh;
150 my @all_items = GetItemsInfo
( $biblionumber );
152 my $patron = Koha
::Patrons
->find( $borrowernumber );
153 for my $itm (@all_items) {
154 push @items, $itm unless ( $itm->{itemlost
} && $patron->category->hidelostitems && !$showallitems);
157 # flag indicating existence of at least one item linked via a host record
159 # adding items linked via host biblios
160 my @hostitems = GetHostItemsInfo
($record);
163 push (@items,@hostitems);
166 my $dat = &GetBiblioData
($biblionumber);
168 #coping with subscriptions
169 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
170 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
173 foreach my $subscription (@subscriptions) {
175 my $serials_to_display;
176 $cell{subscriptionid
} = $subscription->{subscriptionid
};
177 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
178 $cell{missinglist
} = $subscription->{missinglist
};
179 $cell{librariannote
} = $subscription->{librariannote
};
180 $cell{branchcode
} = $subscription->{branchcode
};
181 $cell{hasalert
} = $subscription->{hasalert
};
182 $cell{callnumber
} = $subscription->{callnumber
};
183 $cell{location
} = $subscription->{location
};
184 $cell{closed
} = $subscription->{closed
};
185 #get the three latest serials.
186 $serials_to_display = $subscription->{staffdisplaycount
};
187 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
188 $cell{staffdisplaycount
} = $serials_to_display;
189 $cell{latestserials
} =
190 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
195 # Get acquisition details
196 if ( C4
::Context
->preference('AcquisitionDetails') ) {
197 my $orders = Koha
::Acquisition
::Orders
->search(
198 { biblionumber
=> $biblionumber },
201 order_by
=> 'basketno.booksellerid'
203 ); # GetHistory sorted by aqbooksellerid, but does it make sense?
210 if ( defined $dat->{'itemtype'} ) {
211 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
214 $dat->{'count'} = scalar @all_items + @hostitems;
215 $dat->{'showncount'} = scalar @items + @hostitems;
216 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
219 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.location' } ) };
221 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
223 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
224 my (@itemloop, @otheritemloop, %itemfields);
227 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
229 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
231 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
233 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
235 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.withdrawn', authorised_value
=> { not => undef } });
237 $template->param( itemwithdrawnloop
=> GetAuthorisedValues
( $mss->next->authorised_value) );
240 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.materials', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
243 my $materials_authvals = GetAuthorisedValues
($mss->next->authorised_value);
244 if ($materials_authvals) {
245 foreach my $value (@
$materials_authvals) {
246 $materials_map{$value->{authorised_value
}} = $value->{lib
};
252 my $materials_flag; # set this if the items have anything in the materials field
253 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
254 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
255 $template->param(SeparateHoldings
=> 1);
257 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
258 foreach my $item (@items) {
259 my $itembranchcode = $item->{$separatebranch};
261 # can place holds defaults to yes
262 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
264 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
267 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
269 #get shelf location and collection code description if they are authorised value.
270 # same thing for copy number
271 my $shelfcode = $item->{'location'};
272 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
273 my $ccode = $item->{'ccode'};
274 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
275 my $copynumber = $item->{'copynumber'};
276 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
277 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) {
278 $itemfields{$_} = 1 if ( $item->{$_} );
282 my $item_object = Koha
::Items
->find( $item->{itemnumber
} );
283 my $holds = $item_object->current_holds;
284 if ( my $first_hold = $holds->next ) {
285 my $patron = Koha
::Patrons
->find( $first_hold->borrowernumber );
286 $item->{backgroundcolor
} = 'reserved';
287 $item->{reservedate
} = $first_hold->reservedate;
288 $item->{ReservedFor
} = $patron,
289 $item->{ExpectedAtLibrary
} = $first_hold->branchcode;
290 # Check waiting status
291 $item->{waitingdate
} = $first_hold->waitingdate;
294 if ( my $checkout = $item_object->checkout ) {
295 $item->{CheckedOutFor
} = $checkout->patron;
298 # Check the transit status
299 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
300 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
301 $item->{transfertwhen
} = $transfertwhen;
302 $item->{transfertfrom
} = $transfertfrom;
303 $item->{transfertto
} = $transfertto;
304 $item->{nocancel
} = 1;
307 foreach my $f (qw( itemnotes )) {
309 $item->{$f} =~ s
|\n|<br
/>|g
;
314 #item has a host number if its biblio number does not match the current bib
316 if ($item->{biblionumber
} ne $biblionumber){
317 $item->{hostbiblionumber
} = $item->{biblionumber
};
318 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
323 # count if item is used in analytical bibliorecords
324 # The 'countanalytics' flag is only used in the templates if analyze is set
325 my $countanalytics = C4
::Context
->preference('EasyAnalyticalRecords') ? GetAnalyticsCount
($item->{itemnumber
}) : 0;
326 if ($countanalytics > 0){
328 $item->{countanalytics
} = $countanalytics;
332 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
334 if (defined $materials_map{ $item->{materials
} }) {
335 $item->{materials
} = $materials_map{ $item->{materials
} };
339 if ( C4
::Context
->preference('UseCourseReserves') ) {
340 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
343 if ( C4
::Context
->preference('IndependentBranches') ) {
344 my $userenv = C4
::Context
->userenv();
345 if ( not C4
::Context
->IsSuperLibrarian()
346 and $userenv->{branch
} ne $item->{homebranch
} ) {
347 $item->{cannot_be_edited
} = 1;
351 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
352 and C4
::Context
->preference('SeparateHoldings')) {
353 if ($itembranchcode and $itembranchcode eq $currentbranch) {
354 push @itemloop, $item;
356 push @otheritemloop, $item;
359 push @itemloop, $item;
363 # Display only one tab if one items list is empty
364 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
365 $template->param(SeparateHoldings
=> 0);
366 if (scalar(@itemloop) == 0) {
367 @itemloop = @otheritemloop;
371 $template->param( norequests
=> $norequests );
373 MARCNOTES
=> $marcnotesarray,
374 MARCSUBJCTS
=> $marcsubjctsarray,
375 MARCAUTHORS
=> $marcauthorsarray,
376 MARCSERIES
=> $marcseriesarray,
377 MARCURLS
=> $marcurlsarray,
378 MARCISBNS
=> $marcisbnsarray,
379 MARCHOSTS
=> $marchostsarray,
380 subtitle
=> $subtitle,
381 itemdata_ccode
=> $itemfields{ccode
},
382 itemdata_enumchron
=> $itemfields{enumchron
},
383 itemdata_uri
=> $itemfields{uri
},
384 itemdata_copynumber
=> $itemfields{copynumber
},
385 itemdata_stocknumber
=> $itemfields{stocknumber
},
386 volinfo
=> $itemfields{enumchron
},
387 itemdata_itemnotes
=> $itemfields{itemnotes
},
388 itemdata_nonpublicnotes
=> $itemfields{itemnotes_nonpublic
},
389 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
390 hostrecords
=> $hostrecords,
391 analytics_flag
=> $analytics_flag,
392 C4
::Search
::enabled_staff_search_views
,
393 materials
=> $materials_flag,
396 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
397 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
398 my $subfields = substr $fieldspec, 3;
399 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
400 my @alternateholdingsinfo = ();
401 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
403 for my $field (@holdingsfields) {
404 my %holding = ( holding
=> '' );
405 my $havesubfield = 0;
406 for my $subfield ($field->subfields()) {
407 if ((index $subfields, $$subfield[0]) >= 0) {
408 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
409 $holding{'holding'} .= $$subfield[1];
414 push(@alternateholdingsinfo, \
%holding);
419 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
423 my @results = ( $dat, );
424 foreach ( keys %{$dat} ) {
425 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
428 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
429 # method query not found?!?!
430 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
432 itemloop
=> \
@itemloop,
433 otheritemloop
=> \
@otheritemloop,
434 biblionumber
=> $biblionumber,
435 ($analyze?
'analyze':'detailview') =>1,
436 subscriptions
=> \
@subs,
437 subscriptionsnumber
=> $subscriptionsnumber,
438 subscriptiontitle
=> $dat->{title
},
439 searchid
=> scalar $query->param('searchid'),
442 # $debug and $template->param(debug_display => 1);
446 if (C4
::Context
->preference("virtualshelves") ) {
447 my $shelves = Koha
::Virtualshelves
->search(
449 biblionumber
=> $biblionumber,
453 join => 'virtualshelfcontents',
456 $template->param( 'shelves' => $shelves );
460 if (C4
::Context
->preference("FRBRizeEditions")==1) {
463 XISBNS
=> scalar get_xisbns
($isbn)
466 if ($@
) { warn "XISBN Failed $@"; }
469 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
470 my @images = ListImagesForBiblio
($biblionumber);
471 $template->{VARS
}->{localimages
} = \
@images;
475 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
476 $template->param( C4
::HTML5Media
->gethtml5media($record));
482 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
485 TagsShowOnDetail
=> $tag_quantity
487 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
488 'sort'=>'-weight', limit
=>$tag_quantity}));
491 #we only need to pass the number of holds to the template
492 my $biblio = Koha
::Biblios
->find( $biblionumber );
493 my $holds = $biblio->holds;
494 $template->param( holdcount
=> $holds->count );
496 my $StaffDetailItemSelection = C4
::Context
->preference('StaffDetailItemSelection');
497 if ($StaffDetailItemSelection) {
498 # Only enable item selection if user can execute at least one action
500 $flags->{superlibrarian
}
502 ref $flags->{tools
} eq 'HASH' && (
503 $flags->{tools
}->{items_batchmod
} # Modify selected items
504 || $flags->{tools
}->{items_batchdel
} # Delete selected items
507 || ( ref $flags->{tools
} eq '' && $flags->{tools
} )
511 StaffDetailItemSelection
=> $StaffDetailItemSelection );
515 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
516 my @deletedorders_using_biblio;
517 my @orders_using_biblio;
519 my @baskets_deletedorders;
521 foreach my $myorder (@allorders_using_biblio) {
522 my $basket = $myorder->{'basketno'};
523 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
524 push @deletedorders_using_biblio, $myorder;
525 unless (grep(/^$basket$/, @baskets_deletedorders)){
526 push @baskets_deletedorders,$myorder->{'basketno'};
530 push @orders_using_biblio, $myorder;
531 unless (grep(/^$basket$/, @baskets_orders)){
532 push @baskets_orders,$myorder->{'basketno'};
537 my $count_orders_using_biblio = scalar @orders_using_biblio ;
538 $template->param (countorders
=> $count_orders_using_biblio);
540 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
541 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
543 $template->param (basketsorders
=> \
@baskets_orders);
544 $template->param (basketsdeletedorders
=> \
@baskets_deletedorders);
546 output_html_with_http_headers
$query, $cookie, $template->output;