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::Members; # to use GetMember
35 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
36 use C4::External::Amazon;
37 use C4::Search; # enabled_staff_search_views
38 use C4::Tags qw(get_tags);
39 use C4::VirtualShelves;
44 use C4::CourseReserves qw(GetItemCourseReservesInfo);
45 use C4::Acquisition qw(GetOrdersByBiblionumber);
47 use Koha::Virtualshelves;
49 my $query = CGI->new();
51 my $analyze = $query->param('analyze');
53 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
55 template_name => 'catalogue/detail.tt',
59 flagsrequired => { catalogue => 1 },
63 my $biblionumber = $query->param('biblionumber');
64 my $record = GetMarcBiblio($biblionumber);
66 if ( not defined $record ) {
67 # biblionumber invalid -> report and exit
68 $template->param( unknownbiblionumber => 1,
69 biblionumber => $biblionumber );
70 output_html_with_http_headers $query, $cookie, $template->output;
74 if($query->cookie("holdfor")){
75 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
77 holdfor => $query->cookie("holdfor"),
78 holdfor_surname => $holdfor_patron->{'surname'},
79 holdfor_firstname => $holdfor_patron->{'firstname'},
80 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
84 my $fw = GetFrameworkCode($biblionumber);
85 my $showallitems = $query->param('showallitems');
86 my $marcflavour = C4::Context->preference("marcflavour");
88 # XSLT processing of some stuff
89 if (C4::Context->preference("XSLTDetailsDisplay") ) {
90 $template->param('XSLTDetailsDisplay' =>'1',
91 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "XSLTDetailsDisplay") );
94 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
95 $template->param( ocoins => GetCOinSBiblio($record) );
97 # some useful variables for enhanced content;
98 # in each case, we're grabbing the first value we find in
99 # the record and normalizing it
100 my $upc = GetNormalizedUPC($record,$marcflavour);
101 my $ean = GetNormalizedEAN($record,$marcflavour);
102 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
103 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
106 normalized_upc => $upc,
107 normalized_ean => $ean,
108 normalized_oclc => $oclc,
109 normalized_isbn => $isbn,
112 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
113 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
114 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
115 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
116 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
117 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
118 my $marchostsarray = GetMarcHosts($record,$marcflavour);
119 my $subtitle = GetRecordValue('subtitle', $record, $fw);
121 # Get Branches, Itemtypes and Locations
122 my $branches = GetBranches();
123 my $itemtypes = GetItemTypes();
124 my $dbh = C4::Context->dbh;
126 my @all_items = GetItemsInfo( $biblionumber );
128 for my $itm (@all_items) {
129 push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems);
132 # flag indicating existence of at least one item linked via a host record
134 # adding items linked via host biblios
135 my @hostitems = GetHostItemsInfo($record);
138 push (@items,@hostitems);
141 my $dat = &GetBiblioData($biblionumber);
143 #coping with subscriptions
144 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
145 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
148 foreach my $subscription (@subscriptions) {
150 my $serials_to_display;
151 $cell{subscriptionid} = $subscription->{subscriptionid};
152 $cell{subscriptionnotes} = $subscription->{internalnotes};
153 $cell{missinglist} = $subscription->{missinglist};
154 $cell{librariannote} = $subscription->{librariannote};
155 $cell{branchcode} = $subscription->{branchcode};
156 $cell{branchname} = GetBranchName($subscription->{branchcode});
157 $cell{hasalert} = $subscription->{hasalert};
158 $cell{callnumber} = $subscription->{callnumber};
159 $cell{closed} = $subscription->{closed};
160 #get the three latest serials.
161 $serials_to_display = $subscription->{staffdisplaycount};
162 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
163 $cell{staffdisplaycount} = $serials_to_display;
164 $cell{latestserials} =
165 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
170 # Get acquisition details
171 if ( C4::Context->preference('AcquisitionDetails') ) {
172 my $orders = C4::Acquisition::GetHistory( biblionumber => $biblionumber, get_canceled_order => 1 );
178 if ( defined $dat->{'itemtype'} ) {
179 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
182 $dat->{'count'} = scalar @all_items + @hostitems;
183 $dat->{'showncount'} = scalar @items + @hostitems;
184 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
186 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
187 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
188 my $copynumbers = GetKohaAuthorisedValues('items.copynumber', $fw);
189 my (@itemloop, @otheritemloop, %itemfields);
191 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
192 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
195 my $materials_flag; # set this if the items have anything in the materials field
196 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
197 if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
198 $template->param(SeparateHoldings => 1);
200 my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch';
201 foreach my $item (@items) {
202 my $itembranchcode = $item->{$separatebranch};
204 # can place holds defaults to yes
205 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
207 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
210 $item->{datedue} = format_sqldatetime($item->{datedue});
211 # item damaged, lost, withdrawn loops
212 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
213 if ($item->{damaged}) {
214 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
216 #get shelf location and collection code description if they are authorised value.
217 # same thing for copy number
218 my $shelfcode = $item->{'location'};
219 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
220 my $ccode = $item->{'ccode'};
221 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
222 my $copynumber = $item->{'copynumber'};
223 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
224 foreach (qw(ccode enumchron copynumber stocknumber itemnotes uri)) {
225 $itemfields{$_} = 1 if ( $item->{$_} );
229 my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber($item->{itemnumber});
230 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
232 if (C4::Context->preference('HidePatronName')){
233 $item->{'hidepatronname'} = 1;
236 if ( defined $reservedate ) {
237 $item->{backgroundcolor} = 'reserved';
238 $item->{reservedate} = $reservedate;
239 $item->{ReservedForBorrowernumber} = $reservedfor;
240 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
241 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
242 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
243 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
244 # Check waiting status
245 $item->{waitingdate} = $wait;
249 # Check the transit status
250 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
251 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
252 $item->{transfertwhen} = $transfertwhen;
253 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
254 $item->{transfertto} = $branches->{$transfertto}{branchname};
255 $item->{nocancel} = 1;
258 # item has a host number if its biblio number does not match the current bib
259 if ($item->{biblionumber} ne $biblionumber){
260 $item->{hostbiblionumber} = $item->{biblionumber};
261 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
264 #count if item is used in analytical bibliorecords
265 my $countanalytics= GetAnalyticsCount($item->{itemnumber});
266 if ($countanalytics > 0){
268 $item->{countanalytics} = $countanalytics;
271 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
275 if ( C4::Context->preference('UseCourseReserves') ) {
276 $item->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->{'itemnumber'} );
279 if ( C4::Context->preference('IndependentBranches') ) {
280 my $userenv = C4::Context->userenv();
281 if ( not C4::Context->IsSuperLibrarian()
282 and $userenv->{branch} ne $item->{homebranch} ) {
283 $item->{cannot_be_edited} = 1;
287 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
288 and C4::Context->preference('SeparateHoldings')) {
289 if ($itembranchcode and $itembranchcode eq $currentbranch) {
290 push @itemloop, $item;
292 push @otheritemloop, $item;
295 push @itemloop, $item;
299 # Display only one tab if one items list is empty
300 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
301 $template->param(SeparateHoldings => 0);
302 if (scalar(@itemloop) == 0) {
303 @itemloop = @otheritemloop;
307 $template->param( norequests => $norequests );
309 MARCNOTES => $marcnotesarray,
310 MARCSUBJCTS => $marcsubjctsarray,
311 MARCAUTHORS => $marcauthorsarray,
312 MARCSERIES => $marcseriesarray,
313 MARCURLS => $marcurlsarray,
314 MARCISBNS => $marcisbnsarray,
315 MARCHOSTS => $marchostsarray,
316 subtitle => $subtitle,
317 itemdata_ccode => $itemfields{ccode},
318 itemdata_enumchron => $itemfields{enumchron},
319 itemdata_uri => $itemfields{uri},
320 itemdata_copynumber => $itemfields{copynumber},
321 itemdata_stocknumber => $itemfields{stocknumber},
322 volinfo => $itemfields{enumchron},
323 itemdata_itemnotes => $itemfields{itemnotes},
324 z3950_search_params => C4::Search::z3950_search_args($dat),
325 hostrecords => $hostrecords,
326 analytics_flag => $analytics_flag,
327 C4::Search::enabled_staff_search_views,
328 materials => $materials_flag,
331 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
332 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
333 my $subfields = substr $fieldspec, 3;
334 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
335 my @alternateholdingsinfo = ();
336 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
338 for my $field (@holdingsfields) {
339 my %holding = ( holding => '' );
340 my $havesubfield = 0;
341 for my $subfield ($field->subfields()) {
342 if ((index $subfields, $$subfield[0]) >= 0) {
343 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
344 $holding{'holding'} .= $$subfield[1];
349 push(@alternateholdingsinfo, \%holding);
354 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
358 my @results = ( $dat, );
359 foreach ( keys %{$dat} ) {
360 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
363 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
364 # method query not found?!?!
365 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages"));
367 itemloop => \@itemloop,
368 otheritemloop => \@otheritemloop,
369 biblionumber => $biblionumber,
370 ($analyze? 'analyze':'detailview') =>1,
371 subscriptions => \@subs,
372 subscriptionsnumber => $subscriptionsnumber,
373 subscriptiontitle => $dat->{title},
374 searchid => $query->param('searchid'),
377 # $debug and $template->param(debug_display => 1);
381 if (C4::Context->preference("virtualshelves") ) {
382 my $shelves = Koha::Virtualshelves->search(
384 biblionumber => $biblionumber,
388 join => 'virtualshelfcontents',
391 $template->param( 'shelves' => $shelves );
395 if (C4::Context->preference("FRBRizeEditions")==1) {
398 XISBNS => get_xisbns($isbn)
401 if ($@) { warn "XISBN Failed $@"; }
404 if ( C4::Context->preference("LocalCoverImages") == 1 ) {
405 my @images = ListImagesForBiblio($biblionumber);
406 $template->{VARS}->{localimages} = \@images;
410 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'staff') ) {
411 $template->param( C4::HTML5Media->gethtml5media($record));
417 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
420 TagsShowOnDetail => $tag_quantity
422 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
423 'sort'=>'-weight', limit=>$tag_quantity}));
426 #we only need to pass the number of holds to the template
427 my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
428 $template->param( holdcount => scalar ( @$holds ) );
430 my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
431 if ($StaffDetailItemSelection) {
432 # Only enable item selection if user can execute at least one action
434 $flags->{superlibrarian}
436 ref $flags->{tools} eq 'HASH' && (
437 $flags->{tools}->{items_batchmod} # Modify selected items
438 || $flags->{tools}->{items_batchdel} # Delete selected items
441 || ( ref $flags->{tools} eq '' && $flags->{tools} )
445 StaffDetailItemSelection => $StaffDetailItemSelection );
449 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
450 my @deletedorders_using_biblio;
451 my @orders_using_biblio;
453 my @baskets_deletedorders;
455 foreach my $myorder (@allorders_using_biblio) {
456 my $basket = $myorder->{'basketno'};
457 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
458 push @deletedorders_using_biblio, $myorder;
459 unless (grep(/^$basket$/, @baskets_deletedorders)){
460 push @baskets_deletedorders,$myorder->{'basketno'};
464 push @orders_using_biblio, $myorder;
465 unless (grep(/^$basket$/, @baskets_orders)){
466 push @baskets_orders,$myorder->{'basketno'};
471 my $count_orders_using_biblio = scalar @orders_using_biblio ;
472 $template->param (countorders => $count_orders_using_biblio);
474 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
475 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
477 $template->param (basketsorders => \@baskets_orders);
478 $template->param (basketsdeletedorders => \@baskets_deletedorders);
480 output_html_with_http_headers $query, $cookie, $template->output;