Bug 10331 - Little errors in unimarc_field_4XX.pl (punctuation)
[koha.git] / opac / opac-detail.pl
blob7873f78ae099884354c3b1f30db76c032ca1d0cd
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2011 KohaAloha, NZ
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
26 use CGI;
27 use C4::Auth qw(:DEFAULT get_session);
28 use C4::Branch;
29 use C4::Koha;
30 use C4::Serials; #uses getsubscriptionfrom biblionumber
31 use C4::Output;
32 use C4::Biblio;
33 use C4::Items;
34 use C4::Circulation;
35 use C4::Tags qw(get_tags);
36 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
37 use C4::External::Amazon;
38 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39 use C4::Review;
40 use C4::Ratings;
41 use C4::Members;
42 use C4::VirtualShelves;
43 use C4::XSLT;
44 use C4::ShelfBrowser;
45 use C4::Reserves;
46 use C4::Charset;
47 use MARC::Record;
48 use MARC::Field;
49 use List::MoreUtils qw/any none/;
50 use C4::Images;
51 use Koha::DateUtils;
52 use C4::HTML5Media;
53 use C4::CourseReserves qw(GetItemCourseReservesInfo);
55 BEGIN {
56 if (C4::Context->preference('BakerTaylorEnabled')) {
57 require C4::External::BakerTaylor;
58 import C4::External::BakerTaylor qw(&image_url &link_url);
62 my $query = new CGI;
63 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
65 template_name => "opac-detail.tmpl",
66 query => $query,
67 type => "opac",
68 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69 flagsrequired => { borrow => 1 },
73 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
74 $biblionumber = int($biblionumber);
76 my @itemsmatchingbiblionumber = GetItemsInfo($biblionumber);
77 if (scalar @itemsmatchingbiblionumber >= 1) {
78 my @items2hide = GetHiddenItemnumbers(@itemsmatchingbiblionumber);
80 if (scalar @items2hide == scalar @itemsmatchingbiblionumber ) {
81 # biblionumber=0 effectively hides the biblio record
82 # since there is no such biblionumber.
83 $biblionumber = 0;
87 my $record = GetMarcBiblio($biblionumber);
88 if ( ! $record ) {
89 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90 exit;
92 $template->param( biblionumber => $biblionumber );
94 # get biblionumbers stored in the cart
95 my @cart_list;
97 if($query->cookie("bib_list")){
98 my $cart_list = $query->cookie("bib_list");
99 @cart_list = split(/\//, $cart_list);
100 if ( grep {$_ eq $biblionumber} @cart_list) {
101 $template->param( incart => 1 );
106 SetUTF8Flag($record);
107 my $marcflavour = C4::Context->preference("marcflavour");
108 my $ean = GetNormalizedEAN( $record, $marcflavour );
110 # XSLT processing of some stuff
111 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
112 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
115 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
116 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
118 # We look for the busc param to build the simple paging from the search
119 if ($OpacBrowseResults) {
120 my $session = get_session($query->cookie("CGISESSID"));
121 my %paging = (previous => {}, next => {});
122 if ($session->param('busc')) {
123 use C4::Search;
125 # Rebuild the string to store on session
126 sub rebuildBuscParam
128 my $arrParamsBusc = shift;
130 my $pasarParams = '';
131 my $j = 0;
132 for (keys %$arrParamsBusc) {
133 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
134 if (defined($arrParamsBusc->{$_})) {
135 $pasarParams .= '&' if ($j);
136 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
137 $j++;
139 } else {
140 for my $value (@{$arrParamsBusc->{$_}}) {
141 $pasarParams .= '&' if ($j);
142 $pasarParams .= $_ . '=' . $value;
143 $j++;
147 return $pasarParams;
148 }#rebuildBuscParam
150 # Search given the current values from the busc param
151 sub searchAgain
153 my ($arrParamsBusc, $offset, $results_per_page) = @_;
155 my $expanded_facet = $arrParamsBusc->{'expand'};
156 my $branches = GetBranches();
157 my @servers;
158 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
159 @servers = ("biblioserver") unless (@servers);
161 my ($default_sort_by, @sort_by);
162 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
163 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
164 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
165 my ($error, $results_hashref, $facets);
166 eval {
167 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
169 my $hits;
170 my @newresults;
171 for (my $i=0;$i<@servers;$i++) {
172 my $server = $servers[$i];
173 $hits = $results_hashref->{$server}->{"hits"};
174 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
176 return \@newresults;
177 }#searchAgain
179 # Build the current list of biblionumbers in this search
180 sub buildListBiblios
182 my ($newresultsRef, $results_per_page) = @_;
184 my $listBiblios = '';
185 my $j = 0;
186 foreach (@$newresultsRef) {
187 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
188 $listBiblios .= $bibnum . ',';
189 $j++;
190 last if ($j == $results_per_page);
192 chop $listBiblios if ($listBiblios =~ /,$/);
193 return $listBiblios;
194 }#buildListBiblios
196 my $busc = $session->param("busc");
197 my @arrBusc = split(/\&(?:amp;)?/, $busc);
198 my ($key, $value);
199 my %arrParamsBusc = ();
200 for (@arrBusc) {
201 ($key, $value) = split(/=/, $_, 2);
202 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
203 $arrParamsBusc{$key} = $value;
204 } else {
205 unless (exists($arrParamsBusc{$key})) {
206 $arrParamsBusc{$key} = [];
208 push @{$arrParamsBusc{$key}}, $value;
211 my $searchAgain = 0;
212 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
213 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
214 $arrParamsBusc{'count'} = $results_per_page;
215 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
216 # The value OPACnumSearchResults has changed and the search has to be rebuild
217 if ($count != $results_per_page) {
218 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
219 my $indexBiblio = 0;
220 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
221 for (@arrBibliosAux) {
222 last if ($_ == $biblionumber);
223 $indexBiblio++;
225 $indexBiblio += $offset;
226 $offset = int($indexBiblio / $count) * $count;
227 $arrParamsBusc{'offset'} = $offset;
229 $arrParamsBusc{'count'} = $count;
230 $results_per_page = $count;
231 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
232 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
233 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
234 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
235 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
236 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
237 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
238 $session->param("busc" => $newbusc);
239 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
240 } else {
241 my $modifyListBiblios = 0;
242 # We come from a previous click
243 if (exists($arrParamsBusc{'previous'})) {
244 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
245 delete $arrParamsBusc{'previous'};
246 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
247 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
248 delete $arrParamsBusc{'next'};
250 if ($modifyListBiblios) {
251 if (exists($arrParamsBusc{'newlistBiblios'})) {
252 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
253 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
254 my @arrAux = split(',', $listBibliosAux);
255 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
256 if ($modifyListBiblios == 1) {
257 $arrParamsBusc{'next'} = $arrAux[0];
258 $paging{'next'}->{biblionumber} = $arrAux[0];
259 }else {
260 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
261 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
263 } else {
264 delete $arrParamsBusc{'listBiblios'};
266 my $offsetAux = $arrParamsBusc{'offset'};
267 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
268 $arrParamsBusc{'offsetSearch'} = $offsetAux;
269 $offset = $arrParamsBusc{'offset'};
270 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
271 $session->param("busc" => $newbusc);
272 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
275 my $buscParam = '';
276 my $j = 0;
277 # Rebuild the query for the button "back to results"
278 for (@arrBusc) {
279 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
280 $buscParam .= '&amp;' unless ($j == 0);
281 $buscParam .= $_;
282 $j++;
285 $template->param('busc' => $buscParam);
286 my $offsetSearch;
287 my @arrBiblios;
288 # We are inside the list of biblios and we don't have to search
289 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
290 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
291 if (@arrBiblios) {
292 # We are at the first item of the list
293 if ($arrBiblios[0] == $biblionumber) {
294 if (@arrBiblios > 1) {
295 for (my $j = 1; $j < @arrBiblios; $j++) {
296 next unless ($arrBiblios[$j]);
297 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
298 last;
301 # search again if we are not at the first searching list
302 if ($offset && !$arrParamsBusc{'previous'}) {
303 $searchAgain = 1;
304 $offsetSearch = $offset - $results_per_page;
306 # we are at the last item of the list
307 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
308 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
309 next unless ($arrBiblios[$j]);
310 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
311 last;
313 if (!$offset) {
314 # search again if we are at the first list and there is more results
315 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
316 } else {
317 # search again if we aren't at the first list and there is more results
318 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
320 $offsetSearch = $offset + $results_per_page if ($searchAgain);
321 } else {
322 for (my $j = 1; $j < $#arrBiblios; $j++) {
323 if ($arrBiblios[$j] == $biblionumber) {
324 for (my $z = $j - 1; $z >= 0; $z--) {
325 next unless ($arrBiblios[$z]);
326 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
327 last;
329 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
330 next unless ($arrBiblios[$z]);
331 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
332 last;
334 last;
339 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
341 if ($searchAgain) {
342 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
343 my @newresults = @$newresultsRef;
344 # build the new listBiblios
345 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
346 unless (exists($arrParamsBusc{'listBiblios'})) {
347 $arrParamsBusc{'listBiblios'} = $listBiblios;
348 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
349 } else {
350 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
352 # From the new list we build again the next and previous result
353 if (@arrBiblios) {
354 if ($arrBiblios[0] == $biblionumber) {
355 for (my $j = $#newresults; $j >= 0; $j--) {
356 next unless ($newresults[$j]);
357 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
358 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
359 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
360 last;
362 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
363 for (my $j = 0; $j < @newresults; $j++) {
364 next unless ($newresults[$j]);
365 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
366 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
367 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
368 last;
372 # build new busc param
373 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
374 $session->param("busc" => $newbusc);
376 my ($previous, $next, $dataBiblioPaging);
377 # Previous biblio
378 if ($paging{'previous'}->{biblionumber}) {
379 $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
380 $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
381 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
383 # Next biblio
384 if ($paging{'next'}->{biblionumber}) {
385 $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
386 $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
387 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
389 $template->param('previous' => $previous, 'next' => $next);
390 # Partial list of biblio results
391 my @listResults;
392 for (my $j = 0; $j < @arrBiblios; $j++) {
393 next unless ($arrBiblios[$j]);
394 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
395 push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->{title}, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->{author})?$dataBiblioPaging->{author}:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j]};
397 $template->param('listResults' => \@listResults) if (@listResults);
398 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
404 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
405 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
409 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
410 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
411 # change back when ive fixed request.pl
412 my @all_items = GetItemsInfo( $biblionumber );
414 # adding items linked via host biblios
416 my $analyticfield = '773';
417 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
418 $analyticfield = '773';
419 } elsif ($marcflavour eq 'UNIMARC') {
420 $analyticfield = '461';
422 foreach my $hostfield ( $record->field($analyticfield)) {
423 my $hostbiblionumber = $hostfield->subfield("0");
424 my $linkeditemnumber = $hostfield->subfield("9");
425 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
426 foreach my $hostitemInfo (@hostitemInfos){
427 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
428 push(@all_items, $hostitemInfo);
433 my @items;
435 # Getting items to be hidden
436 my @hiddenitems = GetHiddenItemnumbers(@all_items);
438 # Are there items to hide?
439 my $hideitems;
440 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
442 # Hide items
443 if ($hideitems) {
444 for my $itm (@all_items) {
445 if ( C4::Context->preference('hidelostitems') ) {
446 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
447 } else {
448 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
451 } else {
452 # Or not
453 @items = @all_items;
456 my $branches = GetBranches();
457 my $branch = '';
458 if (C4::Context->userenv){
459 $branch = C4::Context->userenv->{branch};
461 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
462 if (
463 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
465 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
467 my $branchname;
468 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
469 $branchname = $branches->{$branch}->{'branchname'};
471 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
472 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
475 my @our_items;
476 my @other_items;
478 foreach my $item ( @items ) {
479 if ( $item->{'branchname'} eq $branchname ) {
480 $item->{'this_branch'} = 1;
481 push( @our_items, $item );
482 } else {
483 push( @other_items, $item );
487 @items = ( @our_items, @other_items );
491 my $dat = &GetBiblioData($biblionumber);
493 my $itemtypes = GetItemTypes();
494 # imageurl:
495 my $itemtype = $dat->{'itemtype'};
496 if ( $itemtype ) {
497 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
498 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
500 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
501 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
502 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
504 #coping with subscriptions
505 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
506 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
508 my @subs;
509 $dat->{'serial'}=1 if $subscriptionsnumber;
510 foreach my $subscription (@subscriptions) {
511 my $serials_to_display;
512 my %cell;
513 $cell{subscriptionid} = $subscription->{subscriptionid};
514 $cell{subscriptionnotes} = $subscription->{notes};
515 $cell{missinglist} = $subscription->{missinglist};
516 $cell{opacnote} = $subscription->{opacnote};
517 $cell{histstartdate} = $subscription->{histstartdate};
518 $cell{histenddate} = $subscription->{histenddate};
519 $cell{branchcode} = $subscription->{branchcode};
520 $cell{branchname} = GetBranchName($subscription->{branchcode});
521 $cell{hasalert} = $subscription->{hasalert};
522 $cell{callnumber} = $subscription->{callnumber};
523 $cell{closed} = $subscription->{closed};
524 #get the three latest serials.
525 $serials_to_display = $subscription->{opacdisplaycount};
526 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
527 $cell{opacdisplaycount} = $serials_to_display;
528 $cell{latestserials} =
529 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
530 push @subs, \%cell;
533 $dat->{'count'} = scalar(@items);
536 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
538 my (%item_reserves, %priority);
539 my ($show_holds_count, $show_priority);
540 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
541 m/holds/o and $show_holds_count = 1;
542 m/priority/ and $show_priority = 1;
544 my $has_hold;
545 if ( $show_holds_count || $show_priority) {
546 my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber);
547 $template->param( holds_count => $reserve_count ) if $show_holds_count;
548 foreach (@$reserves) {
549 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
550 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
551 $has_hold = 1;
552 $_->{itemnumber}
553 ? ($priority{ $_->{itemnumber} } = $_->{priority})
554 : ($template->param( priority => $_->{priority} ));
558 $template->param( show_priority => $has_hold ) ;
560 my $norequests = 1;
561 my %itemfields;
562 my (@itemloop, @otheritemloop);
563 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
564 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
565 $template->param(SeparateHoldings => 1);
567 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
568 for my $itm (@items) {
569 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
570 $itm->{priority} = $priority{ $itm->{itemnumber} };
571 $norequests = 0
572 if ( (not $itm->{'withdrawn'} )
573 && (not $itm->{'itemlost'} )
574 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
575 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
576 && ($itm->{'itemnumber'} ) );
578 # get collection code description, too
579 my $ccode = $itm->{'ccode'};
580 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
581 my $copynumber = $itm->{'copynumber'};
582 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
583 if ( defined $itm->{'location'} ) {
584 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
586 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
587 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
588 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
590 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
591 $itemfields{$_} = 1 if ($itm->{$_});
594 # walk through the item-level authorised values and populate some images
595 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
596 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
598 if ( $itm->{'itemlost'} ) {
599 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
600 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
601 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
603 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
604 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
605 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
607 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
608 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
609 $itm->{transfertwhen} = $transfertwhen;
610 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
611 $itm->{transfertto} = $branches->{$transfertto}{branchname};
613 my $itembranch = $itm->{$separatebranch};
614 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
615 if ($itembranch and $itembranch eq $currentbranch) {
616 push @itemloop, $itm;
617 } else {
618 push @otheritemloop, $itm;
620 } else {
621 push @itemloop, $itm;
625 # Display only one tab if one items list is empty
626 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
627 $template->param(SeparateHoldings => 0);
628 if (scalar(@itemloop) == 0) {
629 @itemloop = @otheritemloop;
633 # If there is a lot of items, and the user has not decided
634 # to view them all yet, we first warn him
635 # TODO: The limit of 50 could be a syspref
636 my $viewallitems = $query->param('viewallitems');
637 if (scalar(@itemloop) >= 50 && !$viewallitems) {
638 $template->param('lotsofitems' => 1);
641 ## get notes and subjects from MARC record
642 my $dbh = C4::Context->dbh;
643 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
644 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
645 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
646 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
647 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
648 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
649 my $marchostsarray = GetMarcHosts($record,$marcflavour);
650 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
652 $template->param(
653 MARCNOTES => $marcnotesarray,
654 MARCSUBJCTS => $marcsubjctsarray,
655 MARCAUTHORS => $marcauthorsarray,
656 MARCSERIES => $marcseriesarray,
657 MARCURLS => $marcurlsarray,
658 MARCISBNS => $marcisbnsarray,
659 MARCHOSTS => $marchostsarray,
660 norequests => $norequests,
661 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
662 itemdata_ccode => $itemfields{ccode},
663 itemdata_enumchron => $itemfields{enumchron},
664 itemdata_uri => $itemfields{uri},
665 itemdata_copynumber => $itemfields{copynumber},
666 itemdata_itemnotes => $itemfields{itemnotes},
667 authorised_value_images => $biblio_authorised_value_images,
668 subtitle => $subtitle,
669 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
672 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
673 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
674 my $subfields = substr $fieldspec, 3;
675 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
676 my @alternateholdingsinfo = ();
677 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
679 for my $field (@holdingsfields) {
680 my %holding = ( holding => '' );
681 my $havesubfield = 0;
682 for my $subfield ($field->subfields()) {
683 if ((index $subfields, $$subfield[0]) >= 0) {
684 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
685 $holding{'holding'} .= $$subfield[1];
686 $havesubfield++;
689 if ($havesubfield) {
690 push(@alternateholdingsinfo, \%holding);
694 $template->param(
695 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
699 foreach ( keys %{$dat} ) {
700 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
703 # some useful variables for enhanced content;
704 # in each case, we're grabbing the first value we find in
705 # the record and normalizing it
706 my $upc = GetNormalizedUPC($record,$marcflavour);
707 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
708 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
709 my $content_identifier_exists;
710 if ( $isbn or $ean or $oclc or $upc ) {
711 $content_identifier_exists = 1;
713 $template->param(
714 normalized_upc => $upc,
715 normalized_ean => $ean,
716 normalized_oclc => $oclc,
717 normalized_isbn => $isbn,
718 content_identifier_exists => $content_identifier_exists,
721 # COinS format FIXME: for books Only
722 $template->param(
723 ocoins => GetCOinSBiblio($record),
726 my $libravatar_enabled = 0;
727 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
728 eval {
729 require Libravatar::URL;
730 Libravatar::URL->import();
732 if (!$@ ) {
733 $libravatar_enabled = 1;
737 my $reviews = getreviews( $biblionumber, 1 );
738 my $loggedincommenter;
743 foreach ( @$reviews ) {
744 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
745 # setting some borrower info into this hash
746 $_->{title} = $borrowerData->{'title'};
747 $_->{surname} = $borrowerData->{'surname'};
748 $_->{firstname} = $borrowerData->{'firstname'};
749 if ($libravatar_enabled and $borrowerData->{'email'}) {
750 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
752 $_->{userid} = $borrowerData->{'userid'};
753 $_->{cardnumber} = $borrowerData->{'cardnumber'};
755 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
756 $_->{your_comment} = 1;
757 $loggedincommenter = 1;
762 if(C4::Context->preference("ISBD")) {
763 $template->param(ISBD => 1);
766 $template->param(
767 itemloop => \@itemloop,
768 otheritemloop => \@otheritemloop,
769 subscriptionsnumber => $subscriptionsnumber,
770 biblionumber => $biblionumber,
771 subscriptions => \@subs,
772 subscriptionsnumber => $subscriptionsnumber,
773 reviews => $reviews,
774 loggedincommenter => $loggedincommenter
777 # Lists
779 if (C4::Context->preference("virtualshelves") ) {
780 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
784 # XISBN Stuff
785 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
786 eval {
787 $template->param(
788 XISBNS => get_xisbns($isbn)
791 if ($@) { warn "XISBN Failed $@"; }
794 # Serial Collection
795 my @sc_fields = $record->field(955);
796 my @lc_fields = $marcflavour eq 'UNIMARC'
797 ? $record->field(930)
798 : $record->field(852);
799 my @serialcollections = ();
801 foreach my $sc_field (@sc_fields) {
802 my %row_data;
804 $row_data{text} = $sc_field->subfield('r');
805 $row_data{branch} = $sc_field->subfield('9');
806 foreach my $lc_field (@lc_fields) {
807 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
808 ? $lc_field->subfield('a') # 930$a
809 : $lc_field->subfield('h') # 852$h
810 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
813 if ($row_data{text} && $row_data{branch}) {
814 push (@serialcollections, \%row_data);
818 if (scalar(@serialcollections) > 0) {
819 $template->param(
820 serialcollection => 1,
821 serialcollections => \@serialcollections);
824 # Local cover Images stuff
825 if (C4::Context->preference("OPACLocalCoverImages")){
826 $template->param(OPACLocalCoverImages => 1);
829 # HTML5 Media
830 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
831 $template->param( C4::HTML5Media->gethtml5media($record));
834 my $syndetics_elements;
836 if ( C4::Context->preference("SyndeticsEnabled") ) {
837 $template->param("SyndeticsEnabled" => 1);
838 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
839 eval {
840 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
841 for my $element (values %$syndetics_elements) {
842 $template->param("Syndetics$element"."Exists" => 1 );
843 #warn "Exists: "."Syndetics$element"."Exists";
846 warn $@ if $@;
849 if ( C4::Context->preference("SyndeticsEnabled")
850 && C4::Context->preference("SyndeticsSummary")
851 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
852 eval {
853 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
854 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
856 warn $@ if $@;
860 if ( C4::Context->preference("SyndeticsEnabled")
861 && C4::Context->preference("SyndeticsTOC")
862 && exists($syndetics_elements->{'TOC'}) ) {
863 eval {
864 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
865 $template->param( SYNDETICS_TOC => $syndetics_toc );
867 warn $@ if $@;
870 if ( C4::Context->preference("SyndeticsEnabled")
871 && C4::Context->preference("SyndeticsExcerpt")
872 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
873 eval {
874 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
875 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
877 warn $@ if $@;
880 if ( C4::Context->preference("SyndeticsEnabled")
881 && C4::Context->preference("SyndeticsReviews")) {
882 eval {
883 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
884 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
886 warn $@ if $@;
889 if ( C4::Context->preference("SyndeticsEnabled")
890 && C4::Context->preference("SyndeticsAuthorNotes")
891 && exists($syndetics_elements->{'ANOTES'}) ) {
892 eval {
893 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
894 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
896 warn $@ if $@;
899 # LibraryThingForLibraries ID Code and Tabbed View Option
900 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
902 $template->param(LibraryThingForLibrariesID =>
903 C4::Context->preference('LibraryThingForLibrariesID') );
904 $template->param(LibraryThingForLibrariesTabbedView =>
905 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
908 # Novelist Select
909 if( C4::Context->preference('NovelistSelectEnabled') )
911 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
912 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
913 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
917 # Babelthèque
918 if ( C4::Context->preference("Babeltheque") ) {
919 $template->param(
920 Babeltheque => 1,
921 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
925 # Social Networks
926 if ( C4::Context->preference( "SocialNetworks" ) ) {
927 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
928 $template->param( SocialNetworks => 1 );
931 # Shelf Browser Stuff
932 if (C4::Context->preference("OPACShelfBrowser")) {
933 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
934 if (defined($starting_itemnumber)) {
935 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
936 my $nearby = GetNearbyItems($starting_itemnumber,3);
938 $template->param(
939 starting_homebranch => $nearby->{starting_homebranch}->{description},
940 starting_location => $nearby->{starting_location}->{description},
941 starting_ccode => $nearby->{starting_ccode}->{description},
942 starting_itemnumber => $nearby->{starting_itemnumber},
943 shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
944 shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
945 shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
946 shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
947 PREVIOUS_SHELF_BROWSE => $nearby->{prev},
948 NEXT_SHELF_BROWSE => $nearby->{next},
951 # in which tab shelf browser should open ?
952 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
953 $template->param(shelfbrowser_tab => 'holdings');
954 } else {
955 $template->param(shelfbrowser_tab => 'otherholdings');
960 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
962 if (C4::Context->preference("BakerTaylorEnabled")) {
963 $template->param(
964 BakerTaylorEnabled => 1,
965 BakerTaylorImageURL => &image_url(),
966 BakerTaylorLinkURL => &link_url(),
967 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
969 my ($bt_user, $bt_pass);
970 if ($isbn and
971 $bt_user = C4::Context->preference('BakerTaylorUsername') and
972 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
974 $template->param(
975 BakerTaylorContentURL =>
976 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
977 $bt_user,$bt_pass,$isbn)
982 my $tag_quantity;
983 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
984 $template->param(
985 TagsEnabled => 1,
986 TagsShowOnDetail => $tag_quantity,
987 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
989 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
990 'sort'=>'-weight', limit=>$tag_quantity}));
993 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
994 # These values are going to be read by Javascript, at least in the case
995 # of the google covers
996 $template->param(covernewwindow => 'true');
997 } else {
998 $template->param(covernewwindow => 'false');
1001 #Export options
1002 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
1003 my @export_options = split(/\|/,$OpacExportOptions);
1004 $template->{VARS}->{'export_options'} = \@export_options;
1006 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1007 my $rating = GetRating( $biblionumber, $borrowernumber );
1008 $template->param(
1009 rating_value => $rating->{'rating_value'},
1010 rating_total => $rating->{'rating_total'},
1011 rating_avg => $rating->{'rating_avg'},
1012 rating_avg_int => $rating->{'rating_avg_int'},
1013 borrowernumber => $borrowernumber
1017 #Search for title in links
1018 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1019 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1020 my $issn = $marcissns->[0] || '';
1022 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1023 $dat->{title} =~ s/\/+$//; # remove trailing slash
1024 $dat->{title} =~ s/\s+$//; # remove trailing space
1025 $search_for_title = parametrized_url(
1026 $search_for_title,
1028 TITLE => $dat->{title},
1029 AUTHOR => $dat->{author},
1030 ISBN => $isbn,
1031 ISSN => $issn,
1032 CONTROLNUMBER => $marccontrolnumber,
1033 BIBLIONUMBER => $biblionumber,
1036 $template->param('OPACSearchForTitleIn' => $search_for_title);
1039 # We try to select the best default tab to show, according to what
1040 # the user wants, and what's available for display
1041 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1042 my $defaulttab =
1043 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1044 ? 'subscriptions' :
1045 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1046 ? 'serialcollection' :
1047 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1048 ? 'holdings' :
1049 $subscriptionsnumber
1050 ? 'subscriptions' :
1051 @serialcollections > 0
1052 ? 'serialcollection' : 'subscriptions';
1053 $template->param('defaulttab' => $defaulttab);
1055 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1056 my @images = ListImagesForBiblio($biblionumber);
1057 $template->{VARS}->{localimages} = \@images;
1060 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1061 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1062 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1063 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1065 if (C4::Context->preference('OpacHighlightedWords')) {
1066 $template->{VARS}->{query_desc} = $query->param('query_desc');
1068 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1070 if ( C4::Context->preference('UseCourseReserves') ) {
1071 foreach my $i ( @items ) {
1072 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1076 output_html_with_http_headers $query, $cookie, $template->output;