Fix for 1863: Result list for 'scan' index searches incorrect after first page
[koha_fer] / catalogue / detail.pl
index 782a10d..24ce451 100755 (executable)
@@ -20,7 +20,7 @@ use strict;
 require Exporter;
 use CGI;
 use C4::Auth;
-use C4::Date qw/format_date/;
+use C4::Dates qw/format_date/;
 use C4::Koha;
 use C4::Serials;    #uses getsubscriptionfrom biblionumber
 use C4::Output;
@@ -63,6 +63,7 @@ my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
 my $marcseriesarray  = GetMarcSeries($record,$marcflavour);
+my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
 my $subtitle         = C4::Biblio::get_koha_field_from_marc('bibliosubtitle', 'subtitle', $record, '');
 
 # Get Branches, Itemtypes and Locations
@@ -79,23 +80,24 @@ my $dat = &GetBiblioData($biblionumber);
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
-
-
-
 my @subs;
+$dat->{'serial'}=1 if $subscriptionsnumber;
 foreach my $subscription (@subscriptions) {
     my %cell;
     $cell{subscriptionid}    = $subscription->{subscriptionid};
     $cell{subscriptionnotes} = $subscription->{notes};
-
+       $cell{branchcode}        = $subscription->{branchcode};
+       $cell{hasalert}          = $subscription->{hasalert};
     #get the three latest serials.
     $cell{latestserials} =
       GetLatestSerials( $subscription->{subscriptionid}, 3 );
     push @subs, \%cell;
 }
 $dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
-$dat->{'count'} = @items;
-my @itemloop;
+$dat->{'count'} = scalar @items;
+my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
+my $collections    = GetKohaAuthorisedValues('items.ccode'   , $fw);
+my (@itemloop, %itemfields);
 my $norequests = 1;
 foreach my $item (@items) {
 
@@ -105,21 +107,22 @@ foreach my $item (@items) {
     # format some item fields for display
     $item->{ $item->{'publictype'} } = 1;
     $item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
-    $item->{datedue} = format_date($item->{datedue});
-    $item->{datelastseen} = format_date($item->{datelastseen});
-    $item->{onloan} = format_date($item->{onloan});
+       foreach (qw(datedue datelastseen onloan)) {
+               $item->{$_} = format_date($item->{$_});
+       }
     # item damaged, lost, withdrawn loops
     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
     if ($item->{damaged}) {
         $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
     }
     #get shelf location and collection code description if they are authorised value.
-       my $shelflocations = GetKohaAuthorisedValues('items.location',$fw );
        my $shelfcode= $item->{'location'};
        $item->{'location'} = $shelflocations->{$shelfcode} if(defined($shelflocations) && exists($shelflocations->{$shelfcode})); 
-    my $collections =  GetKohaAuthorisedValues('items.ccode',$fw );
        my $ccode= $item->{'ccode'};
        $item->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode})); 
+       foreach (qw(ccode enumchron copynumber)) {
+               $itemfields{$_} = 1 if($item->{$_});
+       }
 
     # checking for holds
     my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber});
@@ -130,7 +133,7 @@ foreach my $item (@items) {
         $item->{reservedate}     = format_date($reservedate);
         $item->{ReservedForBorrowernumber}     = $reservedfor;
         $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
-        $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
+        $item->{ReservedForFirstname}   = $ItemBorrowerReserveInfo->{'firstname'};
         $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
     }
 
@@ -139,7 +142,7 @@ foreach my $item (@items) {
     if ( $transfertwhen ne '' ) {
         $item->{transfertwhen} = format_date($transfertwhen);
         $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
-        $item->{transfertto} = $branches->{$transfertto}{branchname};
+        $item->{transfertto}   = $branches->{$transfertto}{branchname};
         $item->{nocancel} = 1;
     }
 
@@ -154,14 +157,17 @@ foreach my $item (@items) {
 }
 
 $template->param( norequests => $norequests );
-
-    $template->param(
-        MARCNOTES   => $marcnotesarray,
-        MARCSUBJCTS => $marcsubjctsarray,
-        MARCAUTHORS => $marcauthorsarray,
-        MARCSERIES  => $marcseriesarray,
-        subtitle    => $subtitle,
-    );
+$template->param(
+       MARCNOTES   => $marcnotesarray,
+       MARCSUBJCTS => $marcsubjctsarray,
+       MARCAUTHORS => $marcauthorsarray,
+       MARCSERIES  => $marcseriesarray,
+       MARCURLS => $marcurlsarray,
+       subtitle    => $subtitle,
+       itemdata_ccode      => $itemfields{ccode},
+       itemdata_enumchron  => $itemfields{enumchron},
+       itemdata_copynumber => $itemfields{copynumber},
+);
 
 my @results = ( $dat, );
 foreach ( keys %{$dat} ) {
@@ -177,6 +183,8 @@ $template->param(
     subscriptiontitle   => $dat->{title},
 );
 
+# $debug and $template->param(debug_display => 1);
+
 # XISBN Stuff
 my $xisbn=$dat->{'isbn'};
 $xisbn =~ s/(p|-| |:)//g;