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);
141 #coping with subscriptions
142 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
143 my @subscriptions = GetSubscriptions
( $dat->{title
}, $dat->{issn
}, undef, $biblionumber );
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 );
167 if ( defined $dat->{'itemtype'} ) {
168 $dat->{imageurl
} = getitemtypeimagelocation
( 'intranet', $itemtypes->{ $dat->{itemtype
} }{imageurl
} );
171 $dat->{'count'} = scalar @all_items + @hostitems;
172 $dat->{'showncount'} = scalar @items + @hostitems;
173 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
175 my $shelflocations = GetKohaAuthorisedValues
('items.location', $fw);
176 my $collections = GetKohaAuthorisedValues
('items.ccode' , $fw);
177 my $copynumbers = GetKohaAuthorisedValues
('items.copynumber', $fw);
178 my (@itemloop, @otheritemloop, %itemfields);
180 my $authvalcode_items_itemlost = GetAuthValCode
('items.itemlost',$fw);
181 my $authvalcode_items_damaged = GetAuthValCode
('items.damaged', $fw);
184 my $materials_flag; # set this if the items have anything in the materials field
185 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
186 if ($currentbranch and C4
::Context
->preference('SeparateHoldings')) {
187 $template->param(SeparateHoldings
=> 1);
189 my $separatebranch = C4
::Context
->preference('SeparateHoldingsBranch') || 'homebranch';
190 foreach my $item (@items) {
191 my $itembranchcode = $item->{$separatebranch};
192 $item->{homebranch
} = GetBranchName
($item->{homebranch
});
194 # can place holds defaults to yes
195 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
197 $item->{imageurl
} = defined $item->{itype
} ? getitemtypeimagelocation
('intranet', $itemtypes->{ $item->{itype
} }{imageurl
})
200 foreach (qw(datelastseen onloan)) {
201 $item->{$_} = format_date
($item->{$_});
203 $item->{datedue
} = format_sqldatetime
($item->{datedue
});
204 # item damaged, lost, withdrawn loops
205 $item->{itemlostloop
} = GetAuthorisedValues
($authvalcode_items_itemlost, $item->{itemlost
}) if $authvalcode_items_itemlost;
206 if ($item->{damaged
}) {
207 $item->{itemdamagedloop
} = GetAuthorisedValues
($authvalcode_items_damaged, $item->{damaged
}) if $authvalcode_items_damaged;
209 #get shelf location and collection code description if they are authorised value.
210 # same thing for copy number
211 my $shelfcode = $item->{'location'};
212 $item->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
213 my $ccode = $item->{'ccode'};
214 $item->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
215 my $copynumber = $item->{'copynumber'};
216 $item->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
217 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
218 $itemfields{$_} = 1 if ( $item->{$_} );
222 my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber
($item->{itemnumber
});
223 my $ItemBorrowerReserveInfo = GetMemberDetails
( $reservedfor, 0);
225 if (C4
::Context
->preference('HidePatronName')){
226 $item->{'hidepatronname'} = 1;
229 if ( defined $reservedate ) {
230 $item->{backgroundcolor
} = 'reserved';
231 $item->{reservedate
} = format_date
($reservedate);
232 $item->{ReservedForBorrowernumber
} = $reservedfor;
233 $item->{ReservedForSurname
} = $ItemBorrowerReserveInfo->{'surname'};
234 $item->{ReservedForFirstname
} = $ItemBorrowerReserveInfo->{'firstname'};
235 $item->{ExpectedAtLibrary
} = $branches->{$expectedAt}{branchname
};
236 $item->{Reservedcardnumber
} = $ItemBorrowerReserveInfo->{'cardnumber'};
239 # Check the transit status
240 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($item->{itemnumber
});
241 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
242 $item->{transfertwhen
} = format_date
($transfertwhen);
243 $item->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
244 $item->{transfertto
} = $branches->{$transfertto}{branchname
};
245 $item->{nocancel
} = 1;
248 # FIXME: move this to a pm, check waiting status for holds
249 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
250 $sth2->execute($item->{ReservedForBorrowernumber
},$item->{itemnumber
});
251 while (my $wait_hashref = $sth2->fetchrow_hashref) {
252 $item->{waitingdate
} = format_date
($wait_hashref->{waitingdate
});
255 # item has a host number if its biblio number does not match the current bib
256 if ($item->{biblionumber
} ne $biblionumber){
257 $item->{hostbiblionumber
} = $item->{biblionumber
};
258 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
261 #count if item is used in analytical bibliorecords
262 my $countanalytics= GetAnalyticsCount
($item->{itemnumber
});
263 if ($countanalytics > 0){
265 $item->{countanalytics
} = $countanalytics;
268 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
272 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET"
273 and C4
::Context
->preference('SeparateHoldings')) {
274 if ($itembranchcode and $itembranchcode eq $currentbranch) {
275 push @itemloop, $item;
277 push @otheritemloop, $item;
280 push @itemloop, $item;
284 # Display only one tab if one items list is empty
285 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
286 $template->param(SeparateHoldings
=> 0);
287 if (scalar(@itemloop) == 0) {
288 @itemloop = @otheritemloop;
292 $template->param( norequests
=> $norequests );
294 MARCNOTES
=> $marcnotesarray,
295 MARCSUBJCTS
=> $marcsubjctsarray,
296 MARCAUTHORS
=> $marcauthorsarray,
297 MARCSERIES
=> $marcseriesarray,
298 MARCURLS
=> $marcurlsarray,
299 MARCISBNS
=> $marcisbnsarray,
300 MARCHOSTS
=> $marchostsarray,
301 subtitle
=> $subtitle,
302 itemdata_ccode
=> $itemfields{ccode
},
303 itemdata_enumchron
=> $itemfields{enumchron
},
304 itemdata_uri
=> $itemfields{uri
},
305 itemdata_copynumber
=> $itemfields{copynumber
},
306 volinfo
=> $itemfields{enumchron
},
307 itemdata_itemnotes
=> $itemfields{itemnotes
},
308 z3950_search_params
=> C4
::Search
::z3950_search_args
($dat),
309 hostrecords
=> $hostrecords,
310 analytics_flag
=> $analytics_flag,
311 C4
::Search
::enabled_staff_search_views
,
312 materials
=> $materials_flag,
315 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
316 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
317 my $subfields = substr $fieldspec, 3;
318 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
319 my @alternateholdingsinfo = ();
320 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
322 for my $field (@holdingsfields) {
323 my %holding = ( holding
=> '' );
324 my $havesubfield = 0;
325 for my $subfield ($field->subfields()) {
326 if ((index $subfields, $$subfield[0]) >= 0) {
327 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
328 $holding{'holding'} .= $$subfield[1];
333 push(@alternateholdingsinfo, \
%holding);
338 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
342 my @results = ( $dat, );
343 foreach ( keys %{$dat} ) {
344 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
347 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
348 # method query not found?!?!
349 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("AmazonCoverImages"));
351 itemloop
=> \
@itemloop,
352 otheritemloop
=> \
@otheritemloop,
353 biblionumber
=> $biblionumber,
354 ($analyze?
'analyze':'detailview') =>1,
355 subscriptions
=> \
@subs,
356 subscriptionsnumber
=> $subscriptionsnumber,
357 subscriptiontitle
=> $dat->{title
},
360 # $debug and $template->param(debug_display => 1);
364 if (C4
::Context
->preference("virtualshelves") ) {
365 $template->param( 'GetShelves' => GetBibliosShelves
( $biblionumber ) );
369 if (C4
::Context
->preference("FRBRizeEditions")==1) {
372 XISBNS
=> get_xisbns
($isbn)
375 if ($@
) { warn "XISBN Failed $@"; }
378 if ( C4
::Context
->preference("LocalCoverImages") == 1 ) {
379 my @images = ListImagesForBiblio
($biblionumber);
380 $template->{VARS
}->{localimages
} = \
@images;
384 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'staff') ) {
385 $template->param( C4
::HTML5Media
->gethtml5media($record));
390 if (C4
::Context
->preference('OPACBaseURL')){
391 $template->param( OpacUrl
=> C4
::Context
->preference('OPACBaseURL') );
397 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
400 TagsShowOnDetail
=> $tag_quantity
402 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
403 'sort'=>'-weight', limit
=>$tag_quantity}));
406 my ( $holdcount, $holds ) = C4
::Reserves
::GetReservesFromBiblionumber
($biblionumber,1);
407 $template->param( holdcount
=> $holdcount, holds
=> $holds );
409 output_html_with_http_headers
$query, $cookie, $template->output;