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);
46 use Koha
::Virtualshelves
;
48 my $query = CGI
->new();
50 my $analyze = $query->param('analyze');
52 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user
(
54 template_name
=> 'catalogue/detail.tt',
58 flagsrequired
=> { catalogue
=> 1 },
62 my $biblionumber = $query->param('biblionumber');
63 my $record = GetMarcBiblio
($biblionumber);
65 if ( not defined $record ) {
66 # biblionumber invalid -> report and exit
67 $template->param( unknownbiblionumber
=> 1,
68 biblionumber
=> $biblionumber );
69 output_html_with_http_headers
$query, $cookie, $template->output;
73 if($query->cookie("holdfor")){
74 my $holdfor_patron = GetMember
('borrowernumber' => $query->cookie("holdfor"));
76 holdfor
=> $query->cookie("holdfor"),
77 holdfor_surname
=> $holdfor_patron->{'surname'},
78 holdfor_firstname
=> $holdfor_patron->{'firstname'},
79 holdfor_cardnumber
=> $holdfor_patron->{'cardnumber'},
83 my $fw = GetFrameworkCode
($biblionumber);
84 my $showallitems = $query->param('showallitems');
85 my $marcflavour = C4
::Context
->preference("marcflavour");
87 # XSLT processing of some stuff
88 if (C4
::Context
->preference("XSLTDetailsDisplay") ) {
89 $template->param('XSLTDetailsDisplay' =>'1',
90 'XSLTBloc' => XSLTParse4Display
($biblionumber, $record, "XSLTDetailsDisplay") );
93 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4
::Context
->preference("SpineLabelShowPrintOnBibDetails") );
94 $template->param( ocoins
=> GetCOinSBiblio
($record) );
96 # some useful variables for enhanced content;
97 # in each case, we're grabbing the first value we find in
98 # the record and normalizing it
99 my $upc = GetNormalizedUPC
($record,$marcflavour);
100 my $ean = GetNormalizedEAN
($record,$marcflavour);
101 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
102 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
105 normalized_upc
=> $upc,
106 normalized_ean
=> $ean,
107 normalized_oclc
=> $oclc,
108 normalized_isbn
=> $isbn,
111 my $marcnotesarray = GetMarcNotes
( $record, $marcflavour );
112 my $marcisbnsarray = GetMarcISBN
( $record, $marcflavour );
113 my $marcauthorsarray = GetMarcAuthors
( $record, $marcflavour );
114 my $marcsubjctsarray = GetMarcSubjects
( $record, $marcflavour );
115 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
116 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
117 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
118 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
120 # Get Branches, Itemtypes and Locations
121 my $branches = GetBranches
();
122 my $itemtypes = GetItemTypes
();
123 my $dbh = C4
::Context
->dbh;
125 my @all_items = GetItemsInfo
( $biblionumber );
127 for my $itm (@all_items) {
128 push @items, $itm unless ( $itm->{itemlost
} && GetHideLostItemsPreference
($borrowernumber) && !$showallitems);
131 # flag indicating existence of at least one item linked via a host record
133 # adding items linked via host biblios
134 my @hostitems = GetHostItemsInfo
($record);
137 push (@items,@hostitems);
140 my $dat = &GetBiblioData
($biblionumber);
142 #coping with subscriptions
143 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
144 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
147 foreach my $subscription (@subscriptions) {
149 my $serials_to_display;
150 $cell{subscriptionid
} = $subscription->{subscriptionid
};
151 $cell{subscriptionnotes
} = $subscription->{internalnotes
};
152 $cell{missinglist
} = $subscription->{missinglist
};
153 $cell{librariannote
} = $subscription->{librariannote
};
154 $cell{branchcode
} = $subscription->{branchcode
};
155 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
156 $cell{hasalert
} = $subscription->{hasalert
};
157 $cell{callnumber
} = $subscription->{callnumber
};
158 $cell{closed
} = $subscription->{closed
};
159 #get the three latest serials.
160 $serials_to_display = $subscription->{staffdisplaycount
};
161 $serials_to_display = C4
::Context
->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
162 $cell{staffdisplaycount
} = $serials_to_display;
163 $cell{latestserials
} =
164 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
169 # Get acquisition details
170 if ( C4
::Context
->preference('AcquisitionDetails') ) {
171 my $orders = C4
::Acquisition
::GetHistory
( biblionumber
=> $biblionumber, get_canceled_order
=> 1 );
177 if ( defined $dat->{'itemtype'} ) {
178 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
181 $dat->{'count'} = scalar @all_items + @hostitems;
182 $dat->{'showncount'} = scalar @items + @hostitems;
183 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
185 my $shelflocations = GetKohaAuthorisedValues
('items.location', $fw);
186 my $collections = GetKohaAuthorisedValues
('items.ccode' , $fw);
187 my $copynumbers = GetKohaAuthorisedValues
('items.copynumber', $fw);
188 my (@itemloop, @otheritemloop, %itemfields);
190 my $authvalcode_items_itemlost = GetAuthValCode
('items.itemlost',$fw);
191 my $authvalcode_items_damaged = GetAuthValCode
('items.damaged', $fw);
194 my $materials_flag; # set this if the items have anything in the materials field
195 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
196 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
197 $template->param(SeparateHoldings
=> 1);
199 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
200 foreach my $item (@items) {
201 my $itembranchcode = $item->{$separatebranch};
203 # can place holds defaults to yes
204 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
206 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
209 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
210 # item damaged, lost, withdrawn loops
211 $item->{itemlostloop
} = GetAuthorisedValues
($authvalcode_items_itemlost, $item->{itemlost
}) if $authvalcode_items_itemlost;
212 if ($item->{damaged
}) {
213 $item->{itemdamagedloop
} = GetAuthorisedValues
($authvalcode_items_damaged, $item->{damaged
}) if $authvalcode_items_damaged;
215 #get shelf location and collection code description if they are authorised value.
216 # same thing for copy number
217 my $shelfcode = $item->{'location'};
218 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
219 my $ccode = $item->{'ccode'};
220 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
221 my $copynumber = $item->{'copynumber'};
222 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
223 foreach (qw(ccode enumchron copynumber stocknumber itemnotes uri)) {
224 $itemfields{$_} = 1 if ( $item->{$_} );
228 my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber
($item->{itemnumber
});
229 my $ItemBorrowerReserveInfo = GetMemberDetails
( $reservedfor, 0);
231 if (C4
::Context
->preference('HidePatronName')){
232 $item->{'hidepatronname'} = 1;
235 if ( defined $reservedate ) {
236 $item->{backgroundcolor
} = 'reserved';
237 $item->{reservedate
} = $reservedate;
238 $item->{ReservedForBorrowernumber
} = $reservedfor;
239 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
240 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
241 $item->{ExpectedAtLibrary
} = $branches->{$expectedAt}{branchname
};
242 $item->{Reservedcardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
243 # Check waiting status
244 $item->{waitingdate
} = $wait;
248 # Check the transit status
249 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
250 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
251 $item->{transfertwhen
} = $transfertwhen;
252 $item->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
253 $item->{transfertto
} = $branches->{$transfertto}{branchname
};
254 $item->{nocancel
} = 1;
257 # item has a host number if its biblio number does not match the current bib
258 if ($item->{biblionumber
} ne $biblionumber){
259 $item->{hostbiblionumber
} = $item->{biblionumber
};
260 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
263 #count if item is used in analytical bibliorecords
264 my $countanalytics= GetAnalyticsCount
($item->{itemnumber
});
265 if ($countanalytics > 0){
267 $item->{countanalytics
} = $countanalytics;
270 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
274 if ( C4
::Context
->preference('UseCourseReserves') ) {
275 $item->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $item->{'itemnumber'} );
278 if ( C4
::Context
->preference('IndependentBranches') ) {
279 my $userenv = C4
::Context
->userenv();
280 if ( not C4
::Context
->IsSuperLibrarian()
281 and $userenv->{branch
} ne $item->{homebranch
} ) {
282 $item->{cannot_be_edited
} = 1;
286 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
287 and C4
::Context
->preference('SeparateHoldings')) {
288 if ($itembranchcode and $itembranchcode eq $currentbranch) {
289 push @itemloop, $item;
291 push @otheritemloop, $item;
294 push @itemloop, $item;
298 # Display only one tab if one items list is empty
299 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
300 $template->param(SeparateHoldings
=> 0);
301 if (scalar(@itemloop) == 0) {
302 @itemloop = @otheritemloop;
306 $template->param( norequests
=> $norequests );
308 MARCNOTES
=> $marcnotesarray,
309 MARCSUBJCTS
=> $marcsubjctsarray,
310 MARCAUTHORS
=> $marcauthorsarray,
311 MARCSERIES
=> $marcseriesarray,
312 MARCURLS
=> $marcurlsarray,
313 MARCISBNS
=> $marcisbnsarray,
314 MARCHOSTS
=> $marchostsarray,
315 subtitle
=> $subtitle,
316 itemdata_ccode
=> $itemfields{ccode
},
317 itemdata_enumchron
=> $itemfields{enumchron
},
318 itemdata_uri
=> $itemfields{uri
},
319 itemdata_copynumber
=> $itemfields{copynumber
},
320 itemdata_stocknumber
=> $itemfields{stocknumber
},
321 volinfo
=> $itemfields{enumchron
},
322 itemdata_itemnotes
=> $itemfields{itemnotes
},
323 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
324 hostrecords
=> $hostrecords,
325 analytics_flag
=> $analytics_flag,
326 C4
::Search
::enabled_staff_search_views
,
327 materials
=> $materials_flag,
330 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
331 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
332 my $subfields = substr $fieldspec, 3;
333 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
334 my @alternateholdingsinfo = ();
335 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
337 for my $field (@holdingsfields) {
338 my %holding = ( holding
=> '' );
339 my $havesubfield = 0;
340 for my $subfield ($field->subfields()) {
341 if ((index $subfields, $$subfield[0]) >= 0) {
342 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
343 $holding{'holding'} .= $$subfield[1];
348 push(@alternateholdingsinfo, \
%holding);
353 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
357 my @results = ( $dat, );
358 foreach ( keys %{$dat} ) {
359 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
362 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
363 # method query not found?!?!
364 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
366 itemloop
=> \
@itemloop,
367 otheritemloop
=> \
@otheritemloop,
368 biblionumber
=> $biblionumber,
369 ($analyze?
'analyze':'detailview') =>1,
370 subscriptions
=> \
@subs,
371 subscriptionsnumber
=> $subscriptionsnumber,
372 subscriptiontitle
=> $dat->{title
},
373 searchid
=> $query->param('searchid'),
376 # $debug and $template->param(debug_display => 1);
380 if (C4
::Context
->preference("virtualshelves") ) {
381 my $shelves = Koha
::Virtualshelves
->search(
383 biblionumber
=> $biblionumber,
387 join => 'virtualshelfcontents',
390 $template->param( 'shelves' => $shelves );
394 if (C4
::Context
->preference("FRBRizeEditions")==1) {
397 XISBNS
=> get_xisbns
($isbn)
400 if ($@
) { warn "XISBN Failed $@"; }
403 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
404 my @images = ListImagesForBiblio
($biblionumber);
405 $template->{VARS
}->{localimages
} = \
@images;
409 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
410 $template->param( C4
::HTML5Media
->gethtml5media($record));
416 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
419 TagsShowOnDetail
=> $tag_quantity
421 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
422 'sort'=>'-weight', limit
=>$tag_quantity}));
425 #we only need to pass the number of holds to the template
426 my $holds = C4
::Reserves
::GetReservesFromBiblionumber
({ biblionumber
=> $biblionumber, all_dates
=> 1 });
427 $template->param( holdcount
=> scalar ( @
$holds ) );
429 my $StaffDetailItemSelection = C4
::Context
->preference('StaffDetailItemSelection');
430 if ($StaffDetailItemSelection) {
431 # Only enable item selection if user can execute at least one action
433 $flags->{superlibrarian
}
435 ref $flags->{tools
} eq 'HASH' && (
436 $flags->{tools
}->{items_batchmod
} # Modify selected items
437 || $flags->{tools
}->{items_batchdel
} # Delete selected items
440 || ( ref $flags->{tools
} eq '' && $flags->{tools
} )
444 StaffDetailItemSelection
=> $StaffDetailItemSelection );
448 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
449 my @deletedorders_using_biblio;
450 my @orders_using_biblio;
452 my @baskets_deletedorders;
454 foreach my $myorder (@allorders_using_biblio) {
455 my $basket = $myorder->{'basketno'};
456 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
457 push @deletedorders_using_biblio, $myorder;
458 unless (grep(/^$basket$/, @baskets_deletedorders)){
459 push @baskets_deletedorders,$myorder->{'basketno'};
463 push @orders_using_biblio, $myorder;
464 unless (grep(/^$basket$/, @baskets_orders)){
465 push @baskets_orders,$myorder->{'basketno'};
470 my $count_orders_using_biblio = scalar @orders_using_biblio ;
471 $template->param (countorders
=> $count_orders_using_biblio);
473 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
474 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
476 $template->param (basketsorders
=> \
@baskets_orders);
477 $template->param (basketsdeletedorders
=> \
@baskets_deletedorders);
479 output_html_with_http_headers
$query, $cookie, $template->output;