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;
44 # use Smart::Comments;
46 my $query = CGI->new();
48 my $analyze = $query->param('analyze');
50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
52 template_name => 'catalogue/detail.tmpl',
56 flagsrequired => { catalogue => 1 },
60 my $biblionumber = $query->param('biblionumber');
61 my $record = GetMarcBiblio($biblionumber);
63 if ( not defined $record ) {
64 # biblionumber invalid -> report and exit
65 $template->param( unknownbiblionumber => 1,
66 biblionumber => $biblionumber );
67 output_html_with_http_headers $query, $cookie, $template->output;
71 if($query->cookie("holdfor")){
72 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
74 holdfor => $query->cookie("holdfor"),
75 holdfor_surname => $holdfor_patron->{'surname'},
76 holdfor_firstname => $holdfor_patron->{'firstname'},
77 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
81 my $fw = GetFrameworkCode($biblionumber);
82 my $showallitems = $query->param('showallitems');
83 my $marcflavour = C4::Context->preference("marcflavour");
85 # XSLT processing of some stuff
86 if (C4::Context->preference("XSLTDetailsDisplay") ) {
87 $template->param('XSLTDetailsDisplay' =>'1',
88 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "XSLTDetailsDisplay") );
91 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
92 $template->param( ocoins => GetCOinSBiblio($record) );
94 # some useful variables for enhanced content;
95 # in each case, we're grabbing the first value we find in
96 # the record and normalizing it
97 my $upc = GetNormalizedUPC($record,$marcflavour);
98 my $ean = GetNormalizedEAN($record,$marcflavour);
99 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
100 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
103 normalized_upc => $upc,
104 normalized_ean => $ean,
105 normalized_oclc => $oclc,
106 normalized_isbn => $isbn,
109 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
110 my $marcisbnsarray = GetMarcISBN( $record, $marcflavour );
111 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
112 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
113 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
114 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
115 my $marchostsarray = GetMarcHosts($record,$marcflavour);
116 my $subtitle = GetRecordValue('subtitle', $record, $fw);
118 # Get Branches, Itemtypes and Locations
119 my $branches = GetBranches();
120 my $itemtypes = GetItemTypes();
121 my $dbh = C4::Context->dbh;
123 my @all_items = GetItemsInfo( $biblionumber );
125 for my $itm (@all_items) {
126 push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems);
129 # flag indicating existence of at least one item linked via a host record
131 # adding items linked via host biblios
132 my @hostitems = GetHostItemsInfo($record);
135 push (@items,@hostitems);
138 my $dat = &GetBiblioData($biblionumber);
141 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
143 #coping with subscriptions
144 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
145 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
148 foreach my $subscription (@subscriptions) {
150 my $serials_to_display;
151 $cell{subscriptionid} = $subscription->{subscriptionid};
152 $cell{subscriptionnotes} = $subscription->{internalnotes};
153 $cell{missinglist} = $subscription->{missinglist};
154 $cell{librariannote} = $subscription->{librariannote};
155 $cell{branchcode} = $subscription->{branchcode};
156 $cell{branchname} = GetBranchName($subscription->{branchcode});
157 $cell{hasalert} = $subscription->{hasalert};
158 $cell{callnumber} = $subscription->{callnumber};
159 $cell{closed} = $subscription->{closed};
160 #get the three latest serials.
161 $serials_to_display = $subscription->{staffdisplaycount};
162 $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
163 $cell{staffdisplaycount} = $serials_to_display;
164 $cell{latestserials} =
165 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
169 if ( defined $dat->{'itemtype'} ) {
170 $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
173 $dat->{'count'} = scalar @all_items + @hostitems;
174 $dat->{'showncount'} = scalar @items + @hostitems;
175 $dat->{'hiddencount'} = scalar @all_items + @hostitems - scalar @items;
177 my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
178 my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
179 my $copynumbers = GetKohaAuthorisedValues('items.copynumber', $fw);
180 my (@itemloop, @otheritemloop, %itemfields);
182 my $authvalcode_items_itemlost = GetAuthValCode('items.itemlost',$fw);
183 my $authvalcode_items_damaged = GetAuthValCode('items.damaged', $fw);
186 my $materials_flag; # set this if the items have anything in the materials field
187 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
188 if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
189 $template->param(SeparateHoldings => 1);
191 foreach my $item (@items) {
193 my $homebranchcode = $item->{homebranch};
194 $item->{homebranch} = GetBranchName($item->{homebranch});
196 # can place holds defaults to yes
197 $norequests = 0 unless ( ( $item->{'notforloan'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
199 # format some item fields for display
200 if ( defined $item->{'publictype'} ) {
201 $item->{ $item->{'publictype'} } = 1;
203 $item->{imageurl} = defined $item->{itype} ? getitemtypeimagelocation('intranet', $itemtypes->{ $item->{itype} }{imageurl})
206 foreach (qw(datelastseen onloan)) {
207 $item->{$_} = format_date($item->{$_});
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 itemnotes uri)) {
224 $itemfields{$_} = 1 if ( $item->{$_} );
228 my ($reservedate,$reservedfor,$expectedAt) = 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} = format_date($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'};
245 # Check the transit status
246 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
247 if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
248 $item->{transfertwhen} = format_date($transfertwhen);
249 $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
250 $item->{transfertto} = $branches->{$transfertto}{branchname};
251 $item->{nocancel} = 1;
254 # FIXME: move this to a pm, check waiting status for holds
255 my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
256 $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
257 while (my $wait_hashref = $sth2->fetchrow_hashref) {
258 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
261 # item has a host number if its biblio number does not match the current bib
262 if ($item->{biblionumber} ne $biblionumber){
263 $item->{hostbiblionumber} = $item->{biblionumber};
264 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
267 #count if item is used in analytical bibliorecords
268 my $countanalytics= GetAnalyticsCount($item->{itemnumber});
269 if ($countanalytics > 0){
271 $item->{countanalytics} = $countanalytics;
273 if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){
276 if ($currentbranch and $currentbranch ne "NO_LIBRARY_SET" and C4::Context->preference('SeparateHoldings')) {
277 if ($homebranchcode and $homebranchcode 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('OPACBaseURL')){
381 $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') );
387 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
390 TagsShowOnDetail => $tag_quantity
392 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
393 'sort'=>'-weight', limit=>$tag_quantity}));
396 output_html_with_http_headers $query, $cookie, $template->output;