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 });
80 my $biblio = Koha
::Biblios
->find( $biblionumber );
82 if ( not defined $record ) {
83 # biblionumber invalid -> report and exit
84 $template->param( unknownbiblionumber
=> 1,
85 biblionumber
=> $biblionumber );
86 output_html_with_http_headers
$query, $cookie, $template->output;
90 if($query->cookie("holdfor")){
91 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
93 # FIXME Should pass the patron object
94 holdfor
=> $query->cookie("holdfor"),
95 holdfor_surname
=> $holdfor_patron->surname,
96 holdfor_firstname
=> $holdfor_patron->firstname,
97 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
101 my $fw = GetFrameworkCode
($biblionumber);
102 my $showallitems = $query->param('showallitems');
103 my $marcflavour = C4
::Context
->preference("marcflavour");
105 # XSLT processing of some stuff
106 my $xslfile = C4
::Context
->preference('XSLTDetailsDisplay') || "default";
107 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
108 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
112 XSLTDetailsDisplay
=> '1',
113 XSLTBloc
=> XSLTParse4Display
(
114 $biblionumber, $record, "XSLTDetailsDisplay",
115 1, undef, $sysxml, $xslfile, $lang
120 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
121 $template->param( ocoins
=> $biblio->get_coins );
123 # some useful variables for enhanced content;
124 # in each case, we're grabbing the first value we find in
125 # the record and normalizing it
126 my $upc = GetNormalizedUPC
($record,$marcflavour);
127 my $ean = GetNormalizedEAN
($record,$marcflavour);
128 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
129 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
132 normalized_upc
=> $upc,
133 normalized_ean
=> $ean,
134 normalized_oclc
=> $oclc,
135 normalized_isbn
=> $isbn,
138 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
139 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
140 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
141 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
142 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
143 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
144 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
145 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
147 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search->unblessed } };
149 my $dbh = C4
::Context
->dbh;
151 my @all_items = GetItemsInfo
( $biblionumber );
153 my $patron = Koha
::Patrons
->find( $borrowernumber );
154 for my $itm (@all_items) {
155 push @items, $itm unless ( $itm->{itemlost
} && $patron->category->hidelostitems && !$showallitems);
158 # flag indicating existence of at least one item linked via a host record
160 # adding items linked via host biblios
161 my @hostitems = GetHostItemsInfo
($record);
164 push (@items,@hostitems);
167 my $dat = &GetBiblioData
($biblionumber);
169 #coping with subscriptions
170 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
171 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
174 foreach my $subscription (@subscriptions) {
176 my $serials_to_display;
177 $cell{subscriptionid
} = $subscription->{subscriptionid
};
178 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
179 $cell{missinglist
} = $subscription->{missinglist
};
180 $cell{librariannote
} = $subscription->{librariannote
};
181 $cell{branchcode
} = $subscription->{branchcode
};
182 $cell{hasalert
} = $subscription->{hasalert
};
183 $cell{callnumber
} = $subscription->{callnumber
};
184 $cell{location
} = $subscription->{location
};
185 $cell{closed
} = $subscription->{closed
};
186 #get the three latest serials.
187 $serials_to_display = $subscription->{staffdisplaycount
};
188 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
189 $cell{staffdisplaycount
} = $serials_to_display;
190 $cell{latestserials
} =
191 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
196 # Get acquisition details
197 if ( C4
::Context
->preference('AcquisitionDetails') ) {
198 my $orders = Koha
::Acquisition
::Orders
->search(
199 { biblionumber
=> $biblionumber },
202 order_by
=> 'basketno.booksellerid'
204 ); # GetHistory sorted by aqbooksellerid, but does it make sense?
211 if ( defined $dat->{'itemtype'} ) {
212 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
215 $dat->{'count'} = scalar @all_items + @hostitems;
216 $dat->{'showncount'} = scalar @items + @hostitems;
217 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
220 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.location' } ) };
222 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
224 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
225 my (@itemloop, @otheritemloop, %itemfields);
228 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
230 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
232 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
234 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
236 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.withdrawn', authorised_value
=> { not => undef } });
238 $template->param( itemwithdrawnloop
=> GetAuthorisedValues
( $mss->next->authorised_value) );
241 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.materials', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
244 my $materials_authvals = GetAuthorisedValues
($mss->next->authorised_value);
245 if ($materials_authvals) {
246 foreach my $value (@
$materials_authvals) {
247 $materials_map{$value->{authorised_value
}} = $value->{lib
};
253 my $materials_flag; # set this if the items have anything in the materials field
254 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
255 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
256 $template->param(SeparateHoldings
=> 1);
258 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
259 foreach my $item (@items) {
260 my $itembranchcode = $item->{$separatebranch};
262 # can place holds defaults to yes
263 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
265 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
268 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
270 #get shelf location and collection code description if they are authorised value.
271 # same thing for copy number
272 my $shelfcode = $item->{'location'};
273 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
274 my $ccode = $item->{'ccode'};
275 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
276 my $copynumber = $item->{'copynumber'};
277 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
278 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) {
279 $itemfields{$_} = 1 if ( $item->{$_} );
283 my $item_object = Koha
::Items
->find( $item->{itemnumber
} );
284 my $holds = $item_object->current_holds;
285 if ( my $first_hold = $holds->next ) {
286 my $patron = Koha
::Patrons
->find( $first_hold->borrowernumber );
287 $item->{backgroundcolor
} = 'reserved';
288 $item->{reservedate
} = $first_hold->reservedate;
289 $item->{ReservedFor
} = $patron,
290 $item->{ExpectedAtLibrary
} = $first_hold->branchcode;
291 # Check waiting status
292 $item->{waitingdate
} = $first_hold->waitingdate;
295 if ( my $checkout = $item_object->checkout ) {
296 $item->{CheckedOutFor
} = $checkout->patron;
299 # Check the transit status
300 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
301 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
302 $item->{transfertwhen
} = $transfertwhen;
303 $item->{transfertfrom
} = $transfertfrom;
304 $item->{transfertto
} = $transfertto;
305 $item->{nocancel
} = 1;
308 foreach my $f (qw( itemnotes )) {
310 $item->{$f} =~ s
|\n|<br
/>|g
;
315 #item has a host number if its biblio number does not match the current bib
317 if ($item->{biblionumber
} ne $biblionumber){
318 $item->{hostbiblionumber
} = $item->{biblionumber
};
319 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
324 # count if item is used in analytical bibliorecords
325 # The 'countanalytics' flag is only used in the templates if analyze is set
326 my $countanalytics = C4
::Context
->preference('EasyAnalyticalRecords') ? GetAnalyticsCount
($item->{itemnumber
}) : 0;
327 if ($countanalytics > 0){
329 $item->{countanalytics
} = $countanalytics;
333 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
335 if (defined $materials_map{ $item->{materials
} }) {
336 $item->{materials
} = $materials_map{ $item->{materials
} };
340 if ( C4
::Context
->preference('UseCourseReserves') ) {
341 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
344 if ( C4
::Context
->preference('IndependentBranches') ) {
345 my $userenv = C4
::Context
->userenv();
346 if ( not C4
::Context
->IsSuperLibrarian()
347 and $userenv->{branch
} ne $item->{homebranch
} ) {
348 $item->{cannot_be_edited
} = 1;
352 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
353 and C4
::Context
->preference('SeparateHoldings')) {
354 if ($itembranchcode and $itembranchcode eq $currentbranch) {
355 push @itemloop, $item;
357 push @otheritemloop, $item;
360 push @itemloop, $item;
364 # Display only one tab if one items list is empty
365 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
366 $template->param(SeparateHoldings
=> 0);
367 if (scalar(@itemloop) == 0) {
368 @itemloop = @otheritemloop;
372 $template->param( norequests
=> $norequests );
374 MARCNOTES
=> $marcnotesarray,
375 MARCSUBJCTS
=> $marcsubjctsarray,
376 MARCAUTHORS
=> $marcauthorsarray,
377 MARCSERIES
=> $marcseriesarray,
378 MARCURLS
=> $marcurlsarray,
379 MARCISBNS
=> $marcisbnsarray,
380 MARCHOSTS
=> $marchostsarray,
381 subtitle
=> $subtitle,
382 itemdata_ccode
=> $itemfields{ccode
},
383 itemdata_enumchron
=> $itemfields{enumchron
},
384 itemdata_uri
=> $itemfields{uri
},
385 itemdata_copynumber
=> $itemfields{copynumber
},
386 itemdata_stocknumber
=> $itemfields{stocknumber
},
387 volinfo
=> $itemfields{enumchron
},
388 itemdata_itemnotes
=> $itemfields{itemnotes
},
389 itemdata_nonpublicnotes
=> $itemfields{itemnotes_nonpublic
},
390 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
391 hostrecords
=> $hostrecords,
392 analytics_flag
=> $analytics_flag,
393 C4
::Search
::enabled_staff_search_views
,
394 materials
=> $materials_flag,
397 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
398 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
399 my $subfields = substr $fieldspec, 3;
400 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
401 my @alternateholdingsinfo = ();
402 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
404 for my $field (@holdingsfields) {
405 my %holding = ( holding
=> '' );
406 my $havesubfield = 0;
407 for my $subfield ($field->subfields()) {
408 if ((index $subfields, $$subfield[0]) >= 0) {
409 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
410 $holding{'holding'} .= $$subfield[1];
415 push(@alternateholdingsinfo, \
%holding);
420 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
424 my @results = ( $dat, );
425 foreach ( keys %{$dat} ) {
426 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
429 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
430 # method query not found?!?!
431 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
433 itemloop
=> \
@itemloop,
434 otheritemloop
=> \
@otheritemloop,
435 biblionumber
=> $biblionumber,
436 ($analyze?
'analyze':'detailview') =>1,
437 subscriptions
=> \
@subs,
438 subscriptionsnumber
=> $subscriptionsnumber,
439 subscriptiontitle
=> $dat->{title
},
440 searchid
=> scalar $query->param('searchid'),
443 # $debug and $template->param(debug_display => 1);
447 if (C4
::Context
->preference("virtualshelves") ) {
448 my $shelves = Koha
::Virtualshelves
->search(
450 biblionumber
=> $biblionumber,
454 join => 'virtualshelfcontents',
457 $template->param( 'shelves' => $shelves );
461 if (C4
::Context
->preference("FRBRizeEditions")==1) {
464 XISBNS
=> scalar get_xisbns
($isbn, $biblionumber)
467 if ($@
) { warn "XISBN Failed $@"; }
470 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
471 my @images = ListImagesForBiblio
($biblionumber);
472 $template->{VARS
}->{localimages
} = \
@images;
476 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
477 $template->param( C4
::HTML5Media
->gethtml5media($record));
483 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
486 TagsShowOnDetail
=> $tag_quantity
488 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
489 'sort'=>'-weight', limit
=>$tag_quantity}));
492 #we only need to pass the number of holds to the template
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;