Bug 10671: Add missing patron lists help
[koha.git] / opac / opac-detail.pl
blob5bbf0fb673222118dffd49b3d3c3263dee0c3687
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 @all_items = GetItemsInfo($biblionumber);
77 my @hiddenitems;
78 if (scalar @all_items >= 1) {
79 push @hiddenitems, GetHiddenItemnumbers(@all_items);
81 if (scalar @hiddenitems == scalar @all_items ) {
82 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
83 exit;
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 $itemtypes = GetItemTypes;
158 my @servers;
159 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
160 @servers = ("biblioserver") unless (@servers);
162 my ($default_sort_by, @sort_by);
163 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
164 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
165 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
166 my ($error, $results_hashref, $facets);
167 eval {
168 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
170 my $hits;
171 my @newresults;
172 for (my $i=0;$i<@servers;$i++) {
173 my $server = $servers[$i];
174 $hits = $results_hashref->{$server}->{"hits"};
175 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
177 return \@newresults;
178 }#searchAgain
180 # Build the current list of biblionumbers in this search
181 sub buildListBiblios
183 my ($newresultsRef, $results_per_page) = @_;
185 my $listBiblios = '';
186 my $j = 0;
187 foreach (@$newresultsRef) {
188 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
189 $listBiblios .= $bibnum . ',';
190 $j++;
191 last if ($j == $results_per_page);
193 chop $listBiblios if ($listBiblios =~ /,$/);
194 return $listBiblios;
195 }#buildListBiblios
197 my $busc = $session->param("busc");
198 my @arrBusc = split(/\&(?:amp;)?/, $busc);
199 my ($key, $value);
200 my %arrParamsBusc = ();
201 for (@arrBusc) {
202 ($key, $value) = split(/=/, $_, 2);
203 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
204 $arrParamsBusc{$key} = $value;
205 } else {
206 unless (exists($arrParamsBusc{$key})) {
207 $arrParamsBusc{$key} = [];
209 push @{$arrParamsBusc{$key}}, $value;
212 my $searchAgain = 0;
213 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
214 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
215 $arrParamsBusc{'count'} = $results_per_page;
216 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
217 # The value OPACnumSearchResults has changed and the search has to be rebuild
218 if ($count != $results_per_page) {
219 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
220 my $indexBiblio = 0;
221 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
222 for (@arrBibliosAux) {
223 last if ($_ == $biblionumber);
224 $indexBiblio++;
226 $indexBiblio += $offset;
227 $offset = int($indexBiblio / $count) * $count;
228 $arrParamsBusc{'offset'} = $offset;
230 $arrParamsBusc{'count'} = $count;
231 $results_per_page = $count;
232 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
233 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
234 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
235 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
236 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
237 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
238 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
239 $session->param("busc" => $newbusc);
240 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
241 } else {
242 my $modifyListBiblios = 0;
243 # We come from a previous click
244 if (exists($arrParamsBusc{'previous'})) {
245 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
246 delete $arrParamsBusc{'previous'};
247 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
248 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
249 delete $arrParamsBusc{'next'};
251 if ($modifyListBiblios) {
252 if (exists($arrParamsBusc{'newlistBiblios'})) {
253 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
254 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
255 my @arrAux = split(',', $listBibliosAux);
256 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
257 if ($modifyListBiblios == 1) {
258 $arrParamsBusc{'next'} = $arrAux[0];
259 $paging{'next'}->{biblionumber} = $arrAux[0];
260 }else {
261 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
262 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
264 } else {
265 delete $arrParamsBusc{'listBiblios'};
267 my $offsetAux = $arrParamsBusc{'offset'};
268 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
269 $arrParamsBusc{'offsetSearch'} = $offsetAux;
270 $offset = $arrParamsBusc{'offset'};
271 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
272 $session->param("busc" => $newbusc);
273 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
276 my $buscParam = '';
277 my $j = 0;
278 # Rebuild the query for the button "back to results"
279 for (@arrBusc) {
280 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
281 $buscParam .= '&amp;' unless ($j == 0);
282 $buscParam .= $_;
283 $j++;
286 $template->param('busc' => $buscParam);
287 my $offsetSearch;
288 my @arrBiblios;
289 # We are inside the list of biblios and we don't have to search
290 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
291 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
292 if (@arrBiblios) {
293 # We are at the first item of the list
294 if ($arrBiblios[0] == $biblionumber) {
295 if (@arrBiblios > 1) {
296 for (my $j = 1; $j < @arrBiblios; $j++) {
297 next unless ($arrBiblios[$j]);
298 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
299 last;
302 # search again if we are not at the first searching list
303 if ($offset && !$arrParamsBusc{'previous'}) {
304 $searchAgain = 1;
305 $offsetSearch = $offset - $results_per_page;
307 # we are at the last item of the list
308 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
309 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
310 next unless ($arrBiblios[$j]);
311 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
312 last;
314 if (!$offset) {
315 # search again if we are at the first list and there is more results
316 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
317 } else {
318 # search again if we aren't at the first list and there is more results
319 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
321 $offsetSearch = $offset + $results_per_page if ($searchAgain);
322 } else {
323 for (my $j = 1; $j < $#arrBiblios; $j++) {
324 if ($arrBiblios[$j] == $biblionumber) {
325 for (my $z = $j - 1; $z >= 0; $z--) {
326 next unless ($arrBiblios[$z]);
327 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
328 last;
330 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
331 next unless ($arrBiblios[$z]);
332 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
333 last;
335 last;
340 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
342 if ($searchAgain) {
343 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
344 my @newresults = @$newresultsRef;
345 # build the new listBiblios
346 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
347 unless (exists($arrParamsBusc{'listBiblios'})) {
348 $arrParamsBusc{'listBiblios'} = $listBiblios;
349 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
350 } else {
351 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
353 # From the new list we build again the next and previous result
354 if (@arrBiblios) {
355 if ($arrBiblios[0] == $biblionumber) {
356 for (my $j = $#newresults; $j >= 0; $j--) {
357 next unless ($newresults[$j]);
358 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
359 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
360 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
361 last;
363 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
364 for (my $j = 0; $j < @newresults; $j++) {
365 next unless ($newresults[$j]);
366 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
367 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
368 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
369 last;
373 # build new busc param
374 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
375 $session->param("busc" => $newbusc);
377 my ($previous, $next, $dataBiblioPaging);
378 # Previous biblio
379 if ($paging{'previous'}->{biblionumber}) {
380 $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
381 $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
382 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
384 # Next biblio
385 if ($paging{'next'}->{biblionumber}) {
386 $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
387 $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
388 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
390 $template->param('previous' => $previous, 'next' => $next);
391 # Partial list of biblio results
392 my @listResults;
393 for (my $j = 0; $j < @arrBiblios; $j++) {
394 next unless ($arrBiblios[$j]);
395 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
396 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]};
398 $template->param('listResults' => \@listResults) if (@listResults);
399 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
405 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
406 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
410 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
411 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
413 # adding items linked via host biblios
415 my $analyticfield = '773';
416 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
417 $analyticfield = '773';
418 } elsif ($marcflavour eq 'UNIMARC') {
419 $analyticfield = '461';
421 foreach my $hostfield ( $record->field($analyticfield)) {
422 my $hostbiblionumber = $hostfield->subfield("0");
423 my $linkeditemnumber = $hostfield->subfield("9");
424 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
425 foreach my $hostitemInfo (@hostitemInfos){
426 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
427 push(@all_items, $hostitemInfo);
432 my @items;
434 # Are there items to hide?
435 my $hideitems;
436 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
438 # Hide items
439 if ($hideitems) {
440 for my $itm (@all_items) {
441 if ( C4::Context->preference('hidelostitems') ) {
442 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
443 } else {
444 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
447 } else {
448 # Or not
449 @items = @all_items;
452 my $branches = GetBranches();
453 my $branch = '';
454 if (C4::Context->userenv){
455 $branch = C4::Context->userenv->{branch};
457 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
458 if (
459 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
461 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
463 my $branchname;
464 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
465 $branchname = $branches->{$branch}->{'branchname'};
467 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
468 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
471 my @our_items;
472 my @other_items;
474 foreach my $item ( @items ) {
475 if ( $item->{'branchname'} eq $branchname ) {
476 $item->{'this_branch'} = 1;
477 push( @our_items, $item );
478 } else {
479 push( @other_items, $item );
483 @items = ( @our_items, @other_items );
487 my $dat = &GetBiblioData($biblionumber);
489 my $itemtypes = GetItemTypes();
490 # imageurl:
491 my $itemtype = $dat->{'itemtype'};
492 if ( $itemtype ) {
493 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
494 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
496 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
497 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
498 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
500 #coping with subscriptions
501 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
502 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
504 my @subs;
505 $dat->{'serial'}=1 if $subscriptionsnumber;
506 foreach my $subscription (@subscriptions) {
507 my $serials_to_display;
508 my %cell;
509 $cell{subscriptionid} = $subscription->{subscriptionid};
510 $cell{subscriptionnotes} = $subscription->{notes};
511 $cell{missinglist} = $subscription->{missinglist};
512 $cell{opacnote} = $subscription->{opacnote};
513 $cell{histstartdate} = $subscription->{histstartdate};
514 $cell{histenddate} = $subscription->{histenddate};
515 $cell{branchcode} = $subscription->{branchcode};
516 $cell{branchname} = GetBranchName($subscription->{branchcode});
517 $cell{hasalert} = $subscription->{hasalert};
518 $cell{callnumber} = $subscription->{callnumber};
519 $cell{closed} = $subscription->{closed};
520 #get the three latest serials.
521 $serials_to_display = $subscription->{opacdisplaycount};
522 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
523 $cell{opacdisplaycount} = $serials_to_display;
524 $cell{latestserials} =
525 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
526 push @subs, \%cell;
529 $dat->{'count'} = scalar(@items);
532 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
534 my (%item_reserves, %priority);
535 my ($show_holds_count, $show_priority);
536 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
537 m/holds/o and $show_holds_count = 1;
538 m/priority/ and $show_priority = 1;
540 my $has_hold;
541 if ( $show_holds_count || $show_priority) {
542 my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber);
543 $template->param( holds_count => $reserve_count ) if $show_holds_count;
544 foreach (@$reserves) {
545 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
546 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
547 $has_hold = 1;
548 $_->{itemnumber}
549 ? ($priority{ $_->{itemnumber} } = $_->{priority})
550 : ($template->param( priority => $_->{priority} ));
554 $template->param( show_priority => $has_hold ) ;
556 my $norequests = 1;
557 my %itemfields;
558 my (@itemloop, @otheritemloop);
559 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
560 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
561 $template->param(SeparateHoldings => 1);
563 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
564 for my $itm (@items) {
565 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
566 $itm->{priority} = $priority{ $itm->{itemnumber} };
567 $norequests = 0
568 if ( (not $itm->{'withdrawn'} )
569 && (not $itm->{'itemlost'} )
570 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
571 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
572 && ($itm->{'itemnumber'} ) );
574 # get collection code description, too
575 my $ccode = $itm->{'ccode'};
576 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
577 my $copynumber = $itm->{'copynumber'};
578 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
579 if ( defined $itm->{'location'} ) {
580 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
582 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
583 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
584 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
586 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
587 $itemfields{$_} = 1 if ($itm->{$_});
590 # walk through the item-level authorised values and populate some images
591 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
592 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
594 if ( $itm->{'itemlost'} ) {
595 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
596 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
597 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
599 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
600 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
601 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
603 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
604 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
605 $itm->{transfertwhen} = $transfertwhen;
606 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
607 $itm->{transfertto} = $branches->{$transfertto}{branchname};
609 my $itembranch = $itm->{$separatebranch};
610 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
611 if ($itembranch and $itembranch eq $currentbranch) {
612 push @itemloop, $itm;
613 } else {
614 push @otheritemloop, $itm;
616 } else {
617 push @itemloop, $itm;
621 # Display only one tab if one items list is empty
622 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
623 $template->param(SeparateHoldings => 0);
624 if (scalar(@itemloop) == 0) {
625 @itemloop = @otheritemloop;
629 # If there is a lot of items, and the user has not decided
630 # to view them all yet, we first warn him
631 # TODO: The limit of 50 could be a syspref
632 my $viewallitems = $query->param('viewallitems');
633 if (scalar(@itemloop) >= 50 && !$viewallitems) {
634 $template->param('lotsofitems' => 1);
637 ## get notes and subjects from MARC record
638 my $dbh = C4::Context->dbh;
639 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
640 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
641 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
642 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
643 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
644 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
645 my $marchostsarray = GetMarcHosts($record,$marcflavour);
646 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
648 $template->param(
649 MARCNOTES => $marcnotesarray,
650 MARCSUBJCTS => $marcsubjctsarray,
651 MARCAUTHORS => $marcauthorsarray,
652 MARCSERIES => $marcseriesarray,
653 MARCURLS => $marcurlsarray,
654 MARCISBNS => $marcisbnsarray,
655 MARCHOSTS => $marchostsarray,
656 norequests => $norequests,
657 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
658 itemdata_ccode => $itemfields{ccode},
659 itemdata_enumchron => $itemfields{enumchron},
660 itemdata_uri => $itemfields{uri},
661 itemdata_copynumber => $itemfields{copynumber},
662 itemdata_itemnotes => $itemfields{itemnotes},
663 authorised_value_images => $biblio_authorised_value_images,
664 subtitle => $subtitle,
665 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
668 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
669 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
670 my $subfields = substr $fieldspec, 3;
671 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
672 my @alternateholdingsinfo = ();
673 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
675 for my $field (@holdingsfields) {
676 my %holding = ( holding => '' );
677 my $havesubfield = 0;
678 for my $subfield ($field->subfields()) {
679 if ((index $subfields, $$subfield[0]) >= 0) {
680 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
681 $holding{'holding'} .= $$subfield[1];
682 $havesubfield++;
685 if ($havesubfield) {
686 push(@alternateholdingsinfo, \%holding);
690 $template->param(
691 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
695 foreach ( keys %{$dat} ) {
696 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
699 # some useful variables for enhanced content;
700 # in each case, we're grabbing the first value we find in
701 # the record and normalizing it
702 my $upc = GetNormalizedUPC($record,$marcflavour);
703 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
704 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
705 my $content_identifier_exists;
706 if ( $isbn or $ean or $oclc or $upc ) {
707 $content_identifier_exists = 1;
709 $template->param(
710 normalized_upc => $upc,
711 normalized_ean => $ean,
712 normalized_oclc => $oclc,
713 normalized_isbn => $isbn,
714 content_identifier_exists => $content_identifier_exists,
717 # COinS format FIXME: for books Only
718 $template->param(
719 ocoins => GetCOinSBiblio($record),
722 my $libravatar_enabled = 0;
723 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
724 eval {
725 require Libravatar::URL;
726 Libravatar::URL->import();
728 if (!$@ ) {
729 $libravatar_enabled = 1;
733 my $reviews = getreviews( $biblionumber, 1 );
734 my $loggedincommenter;
739 foreach ( @$reviews ) {
740 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
741 # setting some borrower info into this hash
742 $_->{title} = $borrowerData->{'title'};
743 $_->{surname} = $borrowerData->{'surname'};
744 $_->{firstname} = $borrowerData->{'firstname'};
745 if ($libravatar_enabled and $borrowerData->{'email'}) {
746 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
748 $_->{userid} = $borrowerData->{'userid'};
749 $_->{cardnumber} = $borrowerData->{'cardnumber'};
751 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
752 $_->{your_comment} = 1;
753 $loggedincommenter = 1;
758 if(C4::Context->preference("ISBD")) {
759 $template->param(ISBD => 1);
762 $template->param(
763 itemloop => \@itemloop,
764 otheritemloop => \@otheritemloop,
765 subscriptionsnumber => $subscriptionsnumber,
766 biblionumber => $biblionumber,
767 subscriptions => \@subs,
768 subscriptionsnumber => $subscriptionsnumber,
769 reviews => $reviews,
770 loggedincommenter => $loggedincommenter
773 # Lists
775 if (C4::Context->preference("virtualshelves") ) {
776 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
780 # XISBN Stuff
781 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
782 eval {
783 $template->param(
784 XISBNS => get_xisbns($isbn)
787 if ($@) { warn "XISBN Failed $@"; }
790 # Serial Collection
791 my @sc_fields = $record->field(955);
792 my @lc_fields = $marcflavour eq 'UNIMARC'
793 ? $record->field(930)
794 : $record->field(852);
795 my @serialcollections = ();
797 foreach my $sc_field (@sc_fields) {
798 my %row_data;
800 $row_data{text} = $sc_field->subfield('r');
801 $row_data{branch} = $sc_field->subfield('9');
802 foreach my $lc_field (@lc_fields) {
803 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
804 ? $lc_field->subfield('a') # 930$a
805 : $lc_field->subfield('h') # 852$h
806 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
809 if ($row_data{text} && $row_data{branch}) {
810 push (@serialcollections, \%row_data);
814 if (scalar(@serialcollections) > 0) {
815 $template->param(
816 serialcollection => 1,
817 serialcollections => \@serialcollections);
820 # Local cover Images stuff
821 if (C4::Context->preference("OPACLocalCoverImages")){
822 $template->param(OPACLocalCoverImages => 1);
825 # HTML5 Media
826 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
827 $template->param( C4::HTML5Media->gethtml5media($record));
830 my $syndetics_elements;
832 if ( C4::Context->preference("SyndeticsEnabled") ) {
833 $template->param("SyndeticsEnabled" => 1);
834 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
835 eval {
836 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
837 for my $element (values %$syndetics_elements) {
838 $template->param("Syndetics$element"."Exists" => 1 );
839 #warn "Exists: "."Syndetics$element"."Exists";
842 warn $@ if $@;
845 if ( C4::Context->preference("SyndeticsEnabled")
846 && C4::Context->preference("SyndeticsSummary")
847 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
848 eval {
849 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
850 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
852 warn $@ if $@;
856 if ( C4::Context->preference("SyndeticsEnabled")
857 && C4::Context->preference("SyndeticsTOC")
858 && exists($syndetics_elements->{'TOC'}) ) {
859 eval {
860 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
861 $template->param( SYNDETICS_TOC => $syndetics_toc );
863 warn $@ if $@;
866 if ( C4::Context->preference("SyndeticsEnabled")
867 && C4::Context->preference("SyndeticsExcerpt")
868 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
869 eval {
870 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
871 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
873 warn $@ if $@;
876 if ( C4::Context->preference("SyndeticsEnabled")
877 && C4::Context->preference("SyndeticsReviews")) {
878 eval {
879 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
880 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
882 warn $@ if $@;
885 if ( C4::Context->preference("SyndeticsEnabled")
886 && C4::Context->preference("SyndeticsAuthorNotes")
887 && exists($syndetics_elements->{'ANOTES'}) ) {
888 eval {
889 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
890 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
892 warn $@ if $@;
895 # LibraryThingForLibraries ID Code and Tabbed View Option
896 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
898 $template->param(LibraryThingForLibrariesID =>
899 C4::Context->preference('LibraryThingForLibrariesID') );
900 $template->param(LibraryThingForLibrariesTabbedView =>
901 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
904 # Novelist Select
905 if( C4::Context->preference('NovelistSelectEnabled') )
907 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
908 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
909 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
913 # Babelthèque
914 if ( C4::Context->preference("Babeltheque") ) {
915 $template->param(
916 Babeltheque => 1,
917 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
921 # Social Networks
922 if ( C4::Context->preference( "SocialNetworks" ) ) {
923 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
924 $template->param( SocialNetworks => 1 );
927 # Shelf Browser Stuff
928 if (C4::Context->preference("OPACShelfBrowser")) {
929 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
930 if (defined($starting_itemnumber)) {
931 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
932 my $nearby = GetNearbyItems($starting_itemnumber);
934 $template->param(
935 starting_itemnumber => $starting_itemnumber,
936 starting_homebranch => $nearby->{starting_homebranch}->{description},
937 starting_location => $nearby->{starting_location}->{description},
938 starting_ccode => $nearby->{starting_ccode}->{description},
939 shelfbrowser_prev_item => $nearby->{prev_item},
940 shelfbrowser_next_item => $nearby->{next_item},
941 shelfbrowser_items => $nearby->{items},
944 # in which tab shelf browser should open ?
945 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
946 $template->param(shelfbrowser_tab => 'holdings');
947 } else {
948 $template->param(shelfbrowser_tab => 'otherholdings');
953 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
955 if (C4::Context->preference("BakerTaylorEnabled")) {
956 $template->param(
957 BakerTaylorEnabled => 1,
958 BakerTaylorImageURL => &image_url(),
959 BakerTaylorLinkURL => &link_url(),
960 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
962 my ($bt_user, $bt_pass);
963 if ($isbn and
964 $bt_user = C4::Context->preference('BakerTaylorUsername') and
965 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
967 $template->param(
968 BakerTaylorContentURL =>
969 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
970 $bt_user,$bt_pass,$isbn)
975 my $tag_quantity;
976 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
977 $template->param(
978 TagsEnabled => 1,
979 TagsShowOnDetail => $tag_quantity,
980 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
982 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
983 'sort'=>'-weight', limit=>$tag_quantity}));
986 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
987 # These values are going to be read by Javascript, at least in the case
988 # of the google covers
989 $template->param(covernewwindow => 'true');
990 } else {
991 $template->param(covernewwindow => 'false');
994 #Export options
995 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
996 my @export_options = split(/\|/,$OpacExportOptions);
997 $template->{VARS}->{'export_options'} = \@export_options;
999 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1000 my $rating = GetRating( $biblionumber, $borrowernumber );
1001 $template->param(
1002 rating_value => $rating->{'rating_value'},
1003 rating_total => $rating->{'rating_total'},
1004 rating_avg => $rating->{'rating_avg'},
1005 rating_avg_int => $rating->{'rating_avg_int'},
1006 borrowernumber => $borrowernumber
1010 #Search for title in links
1011 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1012 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1013 my $issn = $marcissns->[0] || '';
1015 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1016 $dat->{title} =~ s/\/+$//; # remove trailing slash
1017 $dat->{title} =~ s/\s+$//; # remove trailing space
1018 $search_for_title = parametrized_url(
1019 $search_for_title,
1021 TITLE => $dat->{title},
1022 AUTHOR => $dat->{author},
1023 ISBN => $isbn,
1024 ISSN => $issn,
1025 CONTROLNUMBER => $marccontrolnumber,
1026 BIBLIONUMBER => $biblionumber,
1029 $template->param('OPACSearchForTitleIn' => $search_for_title);
1032 # We try to select the best default tab to show, according to what
1033 # the user wants, and what's available for display
1034 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1035 my $defaulttab =
1036 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1037 ? 'subscriptions' :
1038 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1039 ? 'serialcollection' :
1040 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1041 ? 'holdings' :
1042 $subscriptionsnumber
1043 ? 'subscriptions' :
1044 @serialcollections > 0
1045 ? 'serialcollection' : 'subscriptions';
1046 $template->param('defaulttab' => $defaulttab);
1048 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1049 my @images = ListImagesForBiblio($biblionumber);
1050 $template->{VARS}->{localimages} = \@images;
1053 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1054 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1055 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1056 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1058 if (C4::Context->preference('OpacHighlightedWords')) {
1059 $template->{VARS}->{query_desc} = $query->param('query_desc');
1061 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1063 if ( C4::Context->preference('UseCourseReserves') ) {
1064 foreach my $i ( @items ) {
1065 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1069 output_html_with_http_headers $query, $cookie, $template->output;