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
32 use C4
::Members
; # to use GetMember
34 use C4
::XISBN
qw(get_xisbns get_biblionumber_from_isbn);
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
;
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 $biblionumber = HTML
::Entities
::encode
($biblionumber);
65 my $record = GetMarcBiblio
($biblionumber);
67 if ( not defined $record ) {
68 # biblionumber invalid -> report and exit
69 $template->param( unknownbiblionumber
=> 1,
70 biblionumber
=> $biblionumber );
71 output_html_with_http_headers
$query, $cookie, $template->output;
75 if($query->cookie("holdfor")){
76 my $holdfor_patron = GetMember
('borrowernumber' => $query->cookie("holdfor"));
78 holdfor
=> $query->cookie("holdfor"),
79 holdfor_surname
=> $holdfor_patron->{'surname'},
80 holdfor_firstname
=> $holdfor_patron->{'firstname'},
81 holdfor_cardnumber
=> $holdfor_patron->{'cardnumber'},
85 my $fw = GetFrameworkCode
($biblionumber);
86 my $showallitems = $query->param('showallitems');
87 my $marcflavour = C4
::Context
->preference("marcflavour");
89 # XSLT processing of some stuff
90 my $xslfile = C4
::Context
->preference('XSLTDetailsDisplay');
91 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
92 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
96 XSLTDetailsDisplay
=> '1',
97 XSLTBloc
=> XSLTParse4Display
(
98 $biblionumber, $record, "XSLTDetailsDisplay",
99 1, undef, $sysxml, $xslfile, $lang
104 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
105 $template->param( ocoins
=> GetCOinSBiblio
($record) );
107 # some useful variables for enhanced content;
108 # in each case, we're grabbing the first value we find in
109 # the record and normalizing it
110 my $upc = GetNormalizedUPC
($record,$marcflavour);
111 my $ean = GetNormalizedEAN
($record,$marcflavour);
112 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
113 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
116 normalized_upc
=> $upc,
117 normalized_ean
=> $ean,
118 normalized_oclc
=> $oclc,
119 normalized_isbn
=> $isbn,
122 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
123 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
124 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
125 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
126 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
127 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
128 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
129 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
131 # Get Branches, Itemtypes and Locations
132 my $itemtypes = GetItemTypes
();
133 my $dbh = C4
::Context
->dbh;
135 my @all_items = GetItemsInfo
( $biblionumber );
137 my $patron = Koha
::Patrons
->find( $borrowernumber );
138 for my $itm (@all_items) {
139 push @items, $itm unless ( $itm->{itemlost
} && $patron->category->hidelostitems && !$showallitems);
142 # flag indicating existence of at least one item linked via a host record
144 # adding items linked via host biblios
145 my @hostitems = GetHostItemsInfo
($record);
148 push (@items,@hostitems);
151 my $dat = &GetBiblioData
($biblionumber);
153 #coping with subscriptions
154 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
155 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
158 foreach my $subscription (@subscriptions) {
160 my $serials_to_display;
161 $cell{subscriptionid
} = $subscription->{subscriptionid
};
162 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
163 $cell{missinglist
} = $subscription->{missinglist
};
164 $cell{librariannote
} = $subscription->{librariannote
};
165 $cell{branchcode
} = $subscription->{branchcode
};
166 $cell{hasalert
} = $subscription->{hasalert
};
167 $cell{callnumber
} = $subscription->{callnumber
};
168 $cell{closed
} = $subscription->{closed
};
169 #get the three latest serials.
170 $serials_to_display = $subscription->{staffdisplaycount
};
171 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
172 $cell{staffdisplaycount
} = $serials_to_display;
173 $cell{latestserials
} =
174 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
179 # Get acquisition details
180 if ( C4
::Context
->preference('AcquisitionDetails') ) {
181 my $orders = C4
::Acquisition
::GetHistory
( biblionumber
=> $biblionumber, get_canceled_order
=> 1 );
187 if ( defined $dat->{'itemtype'} ) {
188 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
191 $dat->{'count'} = scalar @all_items + @hostitems;
192 $dat->{'showncount'} = scalar @items + @hostitems;
193 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
196 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.location' } ) };
198 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
200 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
201 my (@itemloop, @otheritemloop, %itemfields);
204 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> { not => undef } });
206 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
208 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> { not => undef } });
210 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
213 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.materials', authorised_value
=> { not => undef } });
216 my $materials_authvals = GetAuthorisedValues
($mss->next->authorised_value);
217 if ($materials_authvals) {
218 foreach my $value (@
$materials_authvals) {
219 $materials_map{$value->{authorised_value
}} = $value->{lib
};
225 my $materials_flag; # set this if the items have anything in the materials field
226 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
227 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
228 $template->param(SeparateHoldings
=> 1);
230 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
231 foreach my $item (@items) {
232 my $itembranchcode = $item->{$separatebranch};
234 # can place holds defaults to yes
235 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
237 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
240 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
242 #get shelf location and collection code description if they are authorised value.
243 # same thing for copy number
244 my $shelfcode = $item->{'location'};
245 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
246 my $ccode = $item->{'ccode'};
247 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
248 my $copynumber = $item->{'copynumber'};
249 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
250 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) {
251 $itemfields{$_} = 1 if ( $item->{$_} );
255 my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber
($item->{itemnumber
});
256 my $ItemBorrowerReserveInfo = C4
::Members
::GetMember
( borrowernumber
=> $reservedfor);
258 if (C4
::Context
->preference('HidePatronName')){
259 $item->{'hidepatronname'} = 1;
262 if ( defined $reservedate ) {
263 $item->{backgroundcolor
} = 'reserved';
264 $item->{reservedate
} = $reservedate;
265 $item->{ReservedForBorrowernumber
} = $reservedfor;
266 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
267 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
268 $item->{ExpectedAtLibrary
} = $expectedAt;
269 $item->{Reservedcardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
270 # Check waiting status
271 $item->{waitingdate
} = $wait;
275 # Check the transit status
276 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
277 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
278 $item->{transfertwhen
} = $transfertwhen;
279 $item->{transfertfrom
} = $transfertfrom;
280 $item->{transfertto
} = $transfertto;
281 $item->{nocancel
} = 1;
284 foreach my $f (qw( itemnotes )) {
286 $item->{$f} =~ s
|\n|<br
/>|g
;
291 #item has a host number if its biblio number does not match the current bib
293 if ($item->{biblionumber
} ne $biblionumber){
294 $item->{hostbiblionumber
} = $item->{biblionumber
};
295 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
298 #count if item is used in analytical bibliorecords
299 my $countanalytics= GetAnalyticsCount
($item->{itemnumber
});
300 if ($countanalytics > 0){
302 $item->{countanalytics
} = $countanalytics;
305 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
307 if (defined $materials_map{ $item->{materials
} }) {
308 $item->{materials
} = $materials_map{ $item->{materials
} };
312 if ( C4
::Context
->preference('UseCourseReserves') ) {
313 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
316 if ( C4
::Context
->preference('IndependentBranches') ) {
317 my $userenv = C4
::Context
->userenv();
318 if ( not C4
::Context
->IsSuperLibrarian()
319 and $userenv->{branch
} ne $item->{homebranch
} ) {
320 $item->{cannot_be_edited
} = 1;
324 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
325 and C4
::Context
->preference('SeparateHoldings')) {
326 if ($itembranchcode and $itembranchcode eq $currentbranch) {
327 push @itemloop, $item;
329 push @otheritemloop, $item;
332 push @itemloop, $item;
336 # Display only one tab if one items list is empty
337 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
338 $template->param(SeparateHoldings
=> 0);
339 if (scalar(@itemloop) == 0) {
340 @itemloop = @otheritemloop;
344 $template->param( norequests
=> $norequests );
346 MARCNOTES
=> $marcnotesarray,
347 MARCSUBJCTS
=> $marcsubjctsarray,
348 MARCAUTHORS
=> $marcauthorsarray,
349 MARCSERIES
=> $marcseriesarray,
350 MARCURLS
=> $marcurlsarray,
351 MARCISBNS
=> $marcisbnsarray,
352 MARCHOSTS
=> $marchostsarray,
353 subtitle
=> $subtitle,
354 itemdata_ccode
=> $itemfields{ccode
},
355 itemdata_enumchron
=> $itemfields{enumchron
},
356 itemdata_uri
=> $itemfields{uri
},
357 itemdata_copynumber
=> $itemfields{copynumber
},
358 itemdata_stocknumber
=> $itemfields{stocknumber
},
359 volinfo
=> $itemfields{enumchron
},
360 itemdata_itemnotes
=> $itemfields{itemnotes
},
361 itemdata_nonpublicnotes
=> $itemfields{itemnotes_nonpublic
},
362 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
363 hostrecords
=> $hostrecords,
364 analytics_flag
=> $analytics_flag,
365 C4
::Search
::enabled_staff_search_views
,
366 materials
=> $materials_flag,
369 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
370 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
371 my $subfields = substr $fieldspec, 3;
372 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
373 my @alternateholdingsinfo = ();
374 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
376 for my $field (@holdingsfields) {
377 my %holding = ( holding
=> '' );
378 my $havesubfield = 0;
379 for my $subfield ($field->subfields()) {
380 if ((index $subfields, $$subfield[0]) >= 0) {
381 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
382 $holding{'holding'} .= $$subfield[1];
387 push(@alternateholdingsinfo, \
%holding);
392 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
396 my @results = ( $dat, );
397 foreach ( keys %{$dat} ) {
398 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
401 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
402 # method query not found?!?!
403 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
405 itemloop
=> \
@itemloop,
406 otheritemloop
=> \
@otheritemloop,
407 biblionumber
=> $biblionumber,
408 ($analyze?
'analyze':'detailview') =>1,
409 subscriptions
=> \
@subs,
410 subscriptionsnumber
=> $subscriptionsnumber,
411 subscriptiontitle
=> $dat->{title
},
412 searchid
=> scalar $query->param('searchid'),
415 # $debug and $template->param(debug_display => 1);
419 if (C4
::Context
->preference("virtualshelves") ) {
420 my $shelves = Koha
::Virtualshelves
->search(
422 biblionumber
=> $biblionumber,
426 join => 'virtualshelfcontents',
429 $template->param( 'shelves' => $shelves );
433 if (C4
::Context
->preference("FRBRizeEditions")==1) {
436 XISBNS
=> get_xisbns
($isbn)
439 if ($@
) { warn "XISBN Failed $@"; }
442 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
443 my @images = ListImagesForBiblio
($biblionumber);
444 $template->{VARS
}->{localimages
} = \
@images;
448 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
449 $template->param( C4
::HTML5Media
->gethtml5media($record));
455 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
458 TagsShowOnDetail
=> $tag_quantity
460 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
461 'sort'=>'-weight', limit
=>$tag_quantity}));
464 #we only need to pass the number of holds to the template
465 my $biblio = Koha
::Biblios
->find( $biblionumber );
466 my $holds = $biblio->holds;
467 $template->param( holdcount
=> $holds->count );
469 my $StaffDetailItemSelection = C4
::Context
->preference('StaffDetailItemSelection');
470 if ($StaffDetailItemSelection) {
471 # Only enable item selection if user can execute at least one action
473 $flags->{superlibrarian
}
475 ref $flags->{tools
} eq 'HASH' && (
476 $flags->{tools
}->{items_batchmod
} # Modify selected items
477 || $flags->{tools
}->{items_batchdel
} # Delete selected items
480 || ( ref $flags->{tools
} eq '' && $flags->{tools
} )
484 StaffDetailItemSelection
=> $StaffDetailItemSelection );
488 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
489 my @deletedorders_using_biblio;
490 my @orders_using_biblio;
492 my @baskets_deletedorders;
494 foreach my $myorder (@allorders_using_biblio) {
495 my $basket = $myorder->{'basketno'};
496 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
497 push @deletedorders_using_biblio, $myorder;
498 unless (grep(/^$basket$/, @baskets_deletedorders)){
499 push @baskets_deletedorders,$myorder->{'basketno'};
503 push @orders_using_biblio, $myorder;
504 unless (grep(/^$basket$/, @baskets_orders)){
505 push @baskets_orders,$myorder->{'basketno'};
510 my $count_orders_using_biblio = scalar @orders_using_biblio ;
511 $template->param (countorders
=> $count_orders_using_biblio);
513 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
514 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
516 $template->param (basketsorders
=> \
@baskets_orders);
517 $template->param (basketsdeletedorders
=> \
@baskets_deletedorders);
519 output_html_with_http_headers
$query, $cookie, $template->output;