3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
24 use C4::Dates qw/format_date/;
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;
45 # use Smart::Comments;
47 my $query = CGI->new();
49 my $analyze = $query->param('analyze');
51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
53 template_name => 'catalogue/detail.tmpl',
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);
142 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
144 #coping with subscriptions
145 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
146 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
149 foreach my $subscription (@subscriptions) {
151 my $serials_to_display;
152 $cell{subscriptionid} = $subscription->{subscriptionid};
153 $cell{subscriptionnotes} = $subscription->{internalnotes};
154 $cell{missinglist} = $subscription->{missinglist};
155 $cell{librariannote} = $subscription->{librariannote};
156 $cell{branchcode} = $subscription->{branchcode};
157 $cell{branchname} = GetBranchName($subscription->{branchcode});
158 $cell{hasalert} = $subscription->{hasalert};
159 $cell{callnumber} = $subscription->{callnumber};
160 $cell{closed} = $subscription->{closed};
161 #get the three latest serials.
162 $serials_to_display = $subscription->{staffdisplaycount};
163 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
164 $cell{staffdisplaycount} = $serials_to_display;
165 $cell{latestserials} =
166 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
170 if ( defined $dat->{'itemtype'} ) {
171 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
174 $dat->{'count'} = scalar @all_items + @hostitems;
175 $dat->{'showncount'} = scalar @items + @hostitems;
176 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
178 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
179 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
180 my $copynumbers = GetKohaAuthorisedValues('items.copynumber', $fw);
181 my (@itemloop, @otheritemloop, %itemfields);
183 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
184 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
187 my $materials_flag; # set this if the items have anything in the materials field
188 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
189 if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
190 $template->param(SeparateHoldings => 1);
192 my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch';
193 foreach my $item (@items) {
194 my $itembranchcode = $item->{$separatebranch};
195 $item->{homebranch} = GetBranchName($item->{homebranch});
197 # can place holds defaults to yes
198 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
200 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
203 foreach (qw(datelastseen onloan)) {
204 $item->{$_} = format_date($item->{$_});
206 $item->{datedue} = format_sqldatetime($item->{datedue});
207 # item damaged, lost, withdrawn loops
208 $item->{itemlostloop} = GetAuthorisedValues($authvalcode_items_itemlost, $item->{itemlost}) if $authvalcode_items_itemlost;
209 if ($item->{damaged}) {
210 $item->{itemdamagedloop} = GetAuthorisedValues($authvalcode_items_damaged, $item->{damaged}) if $authvalcode_items_damaged;
212 #get shelf location and collection code description if they are authorised value.
213 # same thing for copy number
214 my $shelfcode = $item->{'location'};
215 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
216 my $ccode = $item->{'ccode'};
217 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
218 my $copynumber = $item->{'copynumber'};
219 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
220 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
221 $itemfields{$_} = 1 if ( $item->{$_} );
225 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
226 my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
228 if (C4::Context->preference('HidePatronName')){
229 $item->{'hidepatronname'} = 1;
232 if ( defined $reservedate ) {
233 $item->{backgroundcolor} = 'reserved';
234 $item->{reservedate} = format_date($reservedate);
235 $item->{ReservedForBorrowernumber} = $reservedfor;
236 $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
237 $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
238 $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
239 $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
242 # Check the transit status
243 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
244 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
245 $item->{transfertwhen} = format_date($transfertwhen);
246 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
247 $item->{transfertto} = $branches->{$transfertto}{branchname};
248 $item->{nocancel} = 1;
251 # FIXME: move this to a pm, check waiting status for holds
252 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
253 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
254 while (my $wait_hashref = $sth2->fetchrow_hashref) {
255 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
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 ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
276 and C4::Context->preference('SeparateHoldings')) {
277 if ($itembranchcode and $itembranchcode eq $currentbranch) {
278 push @itemloop, $item;
280 push @otheritemloop, $item;
283 push @itemloop, $item;
287 $template->param( norequests => $norequests );
289 MARCNOTES => $marcnotesarray,
290 MARCSUBJCTS => $marcsubjctsarray,
291 MARCAUTHORS => $marcauthorsarray,
292 MARCSERIES => $marcseriesarray,
293 MARCURLS => $marcurlsarray,
294 MARCISBNS => $marcisbnsarray,
295 MARCHOSTS => $marchostsarray,
296 subtitle => $subtitle,
297 itemdata_ccode => $itemfields{ccode},
298 itemdata_enumchron => $itemfields{enumchron},
299 itemdata_uri => $itemfields{uri},
300 itemdata_copynumber => $itemfields{copynumber},
301 volinfo => $itemfields{enumchron},
302 itemdata_itemnotes => $itemfields{itemnotes},
303 z3950_search_params => C4::Search::z3950_search_args($dat),
304 holdcount => $holdcount,
305 hostrecords => $hostrecords,
306 analytics_flag => $analytics_flag,
307 C4::Search::enabled_staff_search_views,
308 materials => $materials_flag,
311 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
312 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
313 my $subfields = substr $fieldspec, 3;
314 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
315 my @alternateholdingsinfo = ();
316 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
318 for my $field (@holdingsfields) {
319 my %holding = ( holding => '' );
320 my $havesubfield = 0;
321 for my $subfield ($field->subfields()) {
322 if ((index $subfields, $$subfield[0]) >= 0) {
323 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
324 $holding{'holding'} .= $$subfield[1];
329 push(@alternateholdingsinfo, \%holding);
334 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
338 my @results = ( $dat, );
339 foreach ( keys %{$dat} ) {
340 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
343 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
344 # method query not found?!?!
345 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages"));
347 itemloop => \@itemloop,
348 otheritemloop => \@otheritemloop,
349 biblionumber => $biblionumber,
350 ($analyze? 'analyze':'detailview') =>1,
351 subscriptions => \@subs,
352 subscriptionsnumber => $subscriptionsnumber,
353 subscriptiontitle => $dat->{title},
356 # $debug and $template->param(debug_display => 1);
360 if (C4::Context->preference("virtualshelves") ) {
361 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
365 if (C4::Context->preference("FRBRizeEditions")==1) {
368 XISBNS => get_xisbns($isbn)
371 if ($@) { warn "XISBN Failed $@"; }
374 if ( C4::Context->preference("LocalCoverImages") == 1 ) {
375 my @images = ListImagesForBiblio($biblionumber);
376 $template->{VARS}->{localimages} = \@images;
380 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'staff') ) {
381 $template->param( C4::HTML5Media->gethtml5media($record));
386 if (C4::Context->preference('OPACBaseURL')){
387 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
393 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
396 TagsShowOnDetail => $tag_quantity
398 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
399 'sort'=>'-weight', limit=>$tag_quantity}));
402 output_html_with_http_headers $query, $cookie, $template->output;