Bug 20639: (follow-up) Fix population of backends
[koha.git] / opac / opac-user.pl
index 3e194c9..1fde24b 100755 (executable)
@@ -75,7 +75,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     }
 );
 
-my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
+my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') || '' );
 
 my $show_priority;
 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
@@ -90,6 +90,8 @@ $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth
 # get borrower information ....
 my $patron = Koha::Patrons->find( $borrowernumber );
 my $borr = $patron->unblessed;
+# unblessed is a hash vs. object/undef. Hence the use of curly braces here.
+my $borcat = $borr ? $borr->{categorycode} : q{};
 
 my (  $today_year,   $today_month,   $today_day) = Today();
 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
@@ -197,9 +199,8 @@ if ( $pending_checkouts->count ) { # Useless test
                 accounttype       => [ 'F', 'FU', 'L' ],
                 itemnumber        => $issue->{itemnumber}
             },
-            { select => [ { sum => 'amountoutstanding' } ], as => ['charges'] }
         );
-        $issue->{charges} = $charges->count ? $charges->next->get_column('charges') : 0;
+        $issue->{charges} = $charges->total_outstanding;
 
         my $rental_fines = Koha::Account::Lines->search(
             {
@@ -207,20 +208,21 @@ if ( $pending_checkouts->count ) { # Useless test
                 amountoutstanding => { '>' => 0 },
                 accounttype       => 'Rent',
                 itemnumber        => $issue->{itemnumber}
-            },
-            {
-                select => [ { sum => 'amountoutstanding' } ],
-                as     => ['rental_fines']
             }
         );
-        $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
+        $issue->{rentalfines} = $rental_fines->total_outstanding;
 
-        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
+        my $marcrecord = GetMarcBiblio({
+            biblionumber => $issue->{'biblionumber'},
+            embed_items  => 1,
+            opac         => 1,
+            borcat       => $borcat });
         $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
         # check if item is renewable
         my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
         ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
         ( $issue->{'renewalfee'}, $issue->{'renewalitemtype'} ) = GetIssuingCharges( $issue->{'itemnumber'}, $borrowernumber );
+        $issue->{itemtype_object} = Koha::ItemTypes->find( Koha::Items->find( $issue->{itemnumber} )->effective_itemtype );
         if($status && C4::Context->preference("OpacRenewalAllowed")){
             $issue->{'status'} = $status;
         }
@@ -235,6 +237,7 @@ if ( $pending_checkouts->count ) { # Useless test
             $issue->{'auto_too_soon'}  = 1 if $renewerror eq 'auto_too_soon';
             $issue->{'auto_too_late'}  = 1 if $renewerror eq 'auto_too_late';
             $issue->{'auto_too_much_oweing'}  = 1 if $renewerror eq 'auto_too_much_oweing';
+            $issue->{'item_denied_renewal'}  = 1 if $renewerror eq 'item_denied_renewal';
 
             if ( $renewerror eq 'too_soon' ) {
                 $issue->{'too_soon'}         = 1;
@@ -325,6 +328,7 @@ $template->param(
     OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0,
     overdrive_error      => scalar $query->param('overdrive_error') || undef,
     overdrive_tab        => scalar $query->param('overdrive_tab') || 0,
+    RecordedBooksCirculation => C4::Context->preference('RecordedBooksClientSecret') && C4::Context->preference('RecordedBooksLibraryID'),
 );
 
 my $patron_messages = Koha::Patron::Messages->search(
@@ -364,7 +368,7 @@ $template->param(
 # back to the opac-results page
 my $search_query = $query->param('has-search-query');
 
-if ($search_query ne '') {
+if ($search_query) {
 
     print $query->redirect(
         -uri    => "/cgi-bin/koha/opac-search.pl?$search_query",