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);
43 use C4
::CourseReserves
qw(GetItemCourseReservesInfo);
44 use C4
::Acquisition
qw(GetOrdersByBiblionumber);
45 use Koha
::Virtualshelves
;
47 my $query = CGI
->new();
49 my $analyze = $query->param('analyze');
51 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user
(
53 template_name
=> 'catalogue/detail.tt',
57 flagsrequired
=> { catalogue
=> 1 },
61 my $biblionumber = $query->param('biblionumber');
62 my $record = GetMarcBiblio
($biblionumber);
64 if ( not defined $record ) {
65 # biblionumber invalid -> report and exit
66 $template->param( unknownbiblionumber
=> 1,
67 biblionumber
=> $biblionumber );
68 output_html_with_http_headers
$query, $cookie, $template->output;
72 if($query->cookie("holdfor")){
73 my $holdfor_patron = GetMember
('borrowernumber' => $query->cookie("holdfor"));
75 holdfor
=> $query->cookie("holdfor"),
76 holdfor_surname
=> $holdfor_patron->{'surname'},
77 holdfor_firstname
=> $holdfor_patron->{'firstname'},
78 holdfor_cardnumber
=> $holdfor_patron->{'cardnumber'},
82 my $fw = GetFrameworkCode
($biblionumber);
83 my $showallitems = $query->param('showallitems');
84 my $marcflavour = C4
::Context
->preference("marcflavour");
86 # XSLT processing of some stuff
87 if (C4
::Context
->preference("XSLTDetailsDisplay") ) {
88 $template->param('XSLTDetailsDisplay' =>'1',
89 'XSLTBloc' => XSLTParse4Display
($biblionumber, $record, "XSLTDetailsDisplay") );
92 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
93 $template->param( ocoins
=> GetCOinSBiblio
($record) );
95 # some useful variables for enhanced content;
96 # in each case, we're grabbing the first value we find in
97 # the record and normalizing it
98 my $upc = GetNormalizedUPC
($record,$marcflavour);
99 my $ean = GetNormalizedEAN
($record,$marcflavour);
100 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
101 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
104 normalized_upc
=> $upc,
105 normalized_ean
=> $ean,
106 normalized_oclc
=> $oclc,
107 normalized_isbn
=> $isbn,
110 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
111 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
112 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
113 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
114 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
115 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
116 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
117 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
119 # Get Branches, Itemtypes and Locations
120 my $branches = GetBranches
();
121 my $itemtypes = GetItemTypes
();
122 my $dbh = C4
::Context
->dbh;
124 my @all_items = GetItemsInfo
( $biblionumber );
126 for my $itm (@all_items) {
127 push @items, $itm unless ( $itm->{itemlost
} && GetHideLostItemsPreference
($borrowernumber) && !$showallitems);
130 # flag indicating existence of at least one item linked via a host record
132 # adding items linked via host biblios
133 my @hostitems = GetHostItemsInfo
($record);
136 push (@items,@hostitems);
139 my $dat = &GetBiblioData
($biblionumber);
141 #coping with subscriptions
142 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
143 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
146 foreach my $subscription (@subscriptions) {
148 my $serials_to_display;
149 $cell{subscriptionid
} = $subscription->{subscriptionid
};
150 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
151 $cell{missinglist
} = $subscription->{missinglist
};
152 $cell{librariannote
} = $subscription->{librariannote
};
153 $cell{branchcode
} = $subscription->{branchcode
};
154 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
155 $cell{hasalert
} = $subscription->{hasalert
};
156 $cell{callnumber
} = $subscription->{callnumber
};
157 $cell{closed
} = $subscription->{closed
};
158 #get the three latest serials.
159 $serials_to_display = $subscription->{staffdisplaycount
};
160 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
161 $cell{staffdisplaycount
} = $serials_to_display;
162 $cell{latestserials
} =
163 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
168 # Get acquisition details
169 if ( C4
::Context
->preference('AcquisitionDetails') ) {
170 my $orders = C4
::Acquisition
::GetHistory
( biblionumber
=> $biblionumber, get_canceled_order
=> 1 );
176 if ( defined $dat->{'itemtype'} ) {
177 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
180 $dat->{'count'} = scalar @all_items + @hostitems;
181 $dat->{'showncount'} = scalar @items + @hostitems;
182 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
184 my $shelflocations = GetKohaAuthorisedValues
('items.location', $fw);
185 my $collections = GetKohaAuthorisedValues
('items.ccode' , $fw);
186 my $copynumbers = GetKohaAuthorisedValues
('items.copynumber', $fw);
187 my (@itemloop, @otheritemloop, %itemfields);
189 my $authvalcode_items_itemlost = GetAuthValCode
('items.itemlost',$fw);
190 my $authvalcode_items_damaged = GetAuthValCode
('items.damaged', $fw);
192 my $materials_authvalcode = GetAuthValCode
('items.materials', $fw);
194 if ($materials_authvalcode) {
195 my $materials_authvals = GetAuthorisedValues
($materials_authvalcode);
196 if ($materials_authvals) {
197 foreach my $value (@
$materials_authvals) {
198 $materials_map{$value->{authorised_value
}} = $value->{lib
};
204 my $materials_flag; # set this if the items have anything in the materials field
205 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
206 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
207 $template->param(SeparateHoldings
=> 1);
209 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
210 foreach my $item (@items) {
211 my $itembranchcode = $item->{$separatebranch};
213 # can place holds defaults to yes
214 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
216 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
219 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
220 # item damaged, lost, withdrawn loops
221 $item->{itemlostloop
} = GetAuthorisedValues
($authvalcode_items_itemlost, $item->{itemlost
}) if $authvalcode_items_itemlost;
222 if ($item->{damaged
}) {
223 $item->{itemdamagedloop
} = GetAuthorisedValues
($authvalcode_items_damaged, $item->{damaged
}) if $authvalcode_items_damaged;
225 #get shelf location and collection code description if they are authorised value.
226 # same thing for copy number
227 my $shelfcode = $item->{'location'};
228 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
229 my $ccode = $item->{'ccode'};
230 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
231 my $copynumber = $item->{'copynumber'};
232 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
233 foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri)) {
234 $itemfields{$_} = 1 if ( $item->{$_} );
238 my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber
($item->{itemnumber
});
239 my $ItemBorrowerReserveInfo = C4
::Members
::GetMember
( borrowernumber
=> $reservedfor);
241 if (C4
::Context
->preference('HidePatronName')){
242 $item->{'hidepatronname'} = 1;
245 if ( defined $reservedate ) {
246 $item->{backgroundcolor
} = 'reserved';
247 $item->{reservedate
} = $reservedate;
248 $item->{ReservedForBorrowernumber
} = $reservedfor;
249 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
250 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
251 $item->{ExpectedAtLibrary
} = $branches->{$expectedAt}{branchname
};
252 $item->{Reservedcardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
253 # Check waiting status
254 $item->{waitingdate
} = $wait;
258 # Check the transit status
259 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
260 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
261 $item->{transfertwhen
} = $transfertwhen;
262 $item->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
263 $item->{transfertto
} = $branches->{$transfertto}{branchname
};
264 $item->{nocancel
} = 1;
267 foreach my $f (qw( itemnotes )) {
269 $item->{$f} =~ s
|\n|<br
/>|g
;
274 #item has a host number if its biblio number does not match the current bib
276 if ($item->{biblionumber
} ne $biblionumber){
277 $item->{hostbiblionumber
} = $item->{biblionumber
};
278 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
281 #count if item is used in analytical bibliorecords
282 my $countanalytics= GetAnalyticsCount
($item->{itemnumber
});
283 if ($countanalytics > 0){
285 $item->{countanalytics
} = $countanalytics;
288 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
290 if (defined $materials_map{ $item->{materials
} }) {
291 $item->{materials
} = $materials_map{ $item->{materials
} };
295 if ( C4
::Context
->preference('UseCourseReserves') ) {
296 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
299 if ( C4
::Context
->preference('IndependentBranches') ) {
300 my $userenv = C4
::Context
->userenv();
301 if ( not C4
::Context
->IsSuperLibrarian()
302 and $userenv->{branch
} ne $item->{homebranch
} ) {
303 $item->{cannot_be_edited
} = 1;
307 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
308 and C4
::Context
->preference('SeparateHoldings')) {
309 if ($itembranchcode and $itembranchcode eq $currentbranch) {
310 push @itemloop, $item;
312 push @otheritemloop, $item;
315 push @itemloop, $item;
319 # Display only one tab if one items list is empty
320 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
321 $template->param(SeparateHoldings
=> 0);
322 if (scalar(@itemloop) == 0) {
323 @itemloop = @otheritemloop;
327 $template->param( norequests
=> $norequests );
329 MARCNOTES
=> $marcnotesarray,
330 MARCSUBJCTS
=> $marcsubjctsarray,
331 MARCAUTHORS
=> $marcauthorsarray,
332 MARCSERIES
=> $marcseriesarray,
333 MARCURLS
=> $marcurlsarray,
334 MARCISBNS
=> $marcisbnsarray,
335 MARCHOSTS
=> $marchostsarray,
336 subtitle
=> $subtitle,
337 itemdata_ccode
=> $itemfields{ccode
},
338 itemdata_enumchron
=> $itemfields{enumchron
},
339 itemdata_uri
=> $itemfields{uri
},
340 itemdata_copynumber
=> $itemfields{copynumber
},
341 itemdata_stocknumber
=> $itemfields{stocknumber
},
342 volinfo
=> $itemfields{enumchron
},
343 itemdata_itemnotes
=> $itemfields{itemnotes
},
344 itemdata_nonpublicnotes
=> $itemfields{itemnotes_nonpublic
},
345 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
346 hostrecords
=> $hostrecords,
347 analytics_flag
=> $analytics_flag,
348 C4
::Search
::enabled_staff_search_views
,
349 materials
=> $materials_flag,
352 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
353 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
354 my $subfields = substr $fieldspec, 3;
355 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
356 my @alternateholdingsinfo = ();
357 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
359 for my $field (@holdingsfields) {
360 my %holding = ( holding
=> '' );
361 my $havesubfield = 0;
362 for my $subfield ($field->subfields()) {
363 if ((index $subfields, $$subfield[0]) >= 0) {
364 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
365 $holding{'holding'} .= $$subfield[1];
370 push(@alternateholdingsinfo, \
%holding);
375 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
379 my @results = ( $dat, );
380 foreach ( keys %{$dat} ) {
381 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
384 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
385 # method query not found?!?!
386 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
388 itemloop
=> \
@itemloop,
389 otheritemloop
=> \
@otheritemloop,
390 biblionumber
=> $biblionumber,
391 ($analyze?
'analyze':'detailview') =>1,
392 subscriptions
=> \
@subs,
393 subscriptionsnumber
=> $subscriptionsnumber,
394 subscriptiontitle
=> $dat->{title
},
395 searchid
=> $query->param('searchid'),
398 # $debug and $template->param(debug_display => 1);
402 if (C4
::Context
->preference("virtualshelves") ) {
403 my $shelves = Koha
::Virtualshelves
->search(
405 biblionumber
=> $biblionumber,
409 join => 'virtualshelfcontents',
412 $template->param( 'shelves' => $shelves );
416 if (C4
::Context
->preference("FRBRizeEditions")==1) {
419 XISBNS
=> get_xisbns
($isbn)
422 if ($@
) { warn "XISBN Failed $@"; }
425 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
426 my @images = ListImagesForBiblio
($biblionumber);
427 $template->{VARS
}->{localimages
} = \
@images;
431 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
432 $template->param( C4
::HTML5Media
->gethtml5media($record));
438 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
441 TagsShowOnDetail
=> $tag_quantity
443 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
444 'sort'=>'-weight', limit
=>$tag_quantity}));
447 #we only need to pass the number of holds to the template
448 my $holds = C4
::Reserves
::GetReservesFromBiblionumber
({ biblionumber
=> $biblionumber, all_dates
=> 1 });
449 $template->param( holdcount
=> scalar ( @
$holds ) );
451 my $StaffDetailItemSelection = C4
::Context
->preference('StaffDetailItemSelection');
452 if ($StaffDetailItemSelection) {
453 # Only enable item selection if user can execute at least one action
455 $flags->{superlibrarian
}
457 ref $flags->{tools
} eq 'HASH' && (
458 $flags->{tools
}->{items_batchmod
} # Modify selected items
459 || $flags->{tools
}->{items_batchdel
} # Delete selected items
462 || ( ref $flags->{tools
} eq '' && $flags->{tools
} )
466 StaffDetailItemSelection
=> $StaffDetailItemSelection );
470 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
471 my @deletedorders_using_biblio;
472 my @orders_using_biblio;
474 my @baskets_deletedorders;
476 foreach my $myorder (@allorders_using_biblio) {
477 my $basket = $myorder->{'basketno'};
478 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
479 push @deletedorders_using_biblio, $myorder;
480 unless (grep(/^$basket$/, @baskets_deletedorders)){
481 push @baskets_deletedorders,$myorder->{'basketno'};
485 push @orders_using_biblio, $myorder;
486 unless (grep(/^$basket$/, @baskets_orders)){
487 push @baskets_orders,$myorder->{'basketno'};
492 my $count_orders_using_biblio = scalar @orders_using_biblio ;
493 $template->param (countorders
=> $count_orders_using_biblio);
495 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
496 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
498 $template->param (basketsorders
=> \
@baskets_orders);
499 $template->param (basketsdeletedorders
=> \
@baskets_deletedorders);
501 output_html_with_http_headers
$query, $cookie, $template->output;