Bug 21082: Update OverDrive authentication method
[koha.git] / opac / opac-user.pl
index a247ed7..500042d 100755 (executable)
@@ -17,8 +17,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
-use strict;
-#use warnings; FIXME - Bug 2505
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
 
@@ -62,8 +61,9 @@ BEGIN {
     }
 }
 
-my $cas_logout_required = C4::Context->preference('casAuthentication')
-  and C4::Auth_with_ldap::logout_required($query);
+# CAS single logout handling
+# Will print header and exit
+C4::Context->preference('casAuthentication') and C4::Auth_with_cas::logout_if_required($query);
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {
@@ -75,13 +75,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     }
 );
 
-if ($cas_logout_required){
-    print $query->header;
-    exit;
-}
-
-
-my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
+my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') || '' );
 
 my $show_priority;
 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
@@ -93,10 +87,6 @@ my $canrenew = 1;
 
 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
 
-if (!$borrowernumber) {
-    $template->param( adminWarning => 1 );
-}
-
 # get borrower information ....
 my $patron = Koha::Patrons->find( $borrowernumber );
 my $borr = $patron->unblessed;
@@ -172,7 +162,7 @@ if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture')
 # pass on any renew errors to the template for displaying
 my $renew_error = $query->param('renew_error');
 
-$template->param(   BORROWER_INFO     => $borr,
+$template->param(
                     amountoutstanding => $amountoutstanding,
                     borrowernumber    => $borrowernumber,
                     patron_flagged    => $borr->{flagged},
@@ -189,9 +179,10 @@ my $overdues_count = 0;
 my @overdues;
 my @issuedat;
 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
-my $issues = GetPendingIssues($borrowernumber);
-if ($issues){
-    foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
+my $pending_checkouts = $patron->pending_checkouts->search({}, { order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ] });
+if ( $pending_checkouts->count ) { # Useless test
+    while ( my $c = $pending_checkouts->next ) {
+        my $issue = $c->unblessed_all_relateds;
         # check for reserves
         my $restype = GetReserveStatus( $issue->{'itemnumber'} );
         if ( $restype ) {
@@ -222,7 +213,7 @@ if ($issues){
                 as     => ['rental_fines']
             }
         );
-        $issue->{rentalfines} = $charges->count ? $charges->next->get_column('rental_fines') : 0;
+        $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
 
         my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
         $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
@@ -256,7 +247,7 @@ if ($issues){
             }
         }
 
-        if ( $issue->{'overdue'} ) {
+        if ( $c->is_overdue ) {
             push @overdues, $issue;
             $overdues_count++;
             $issue->{'overdue'} = 1;
@@ -314,13 +305,6 @@ $template->param(
     showpriority   => $show_priority,
 );
 
-# current alert subscriptions
-my $alerts = getalert($borrowernumber);
-foreach ( @$alerts ) {
-    $_->{ $_->{type} } = 1;
-    $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
-}
-
 if (C4::Context->preference('BakerTaylorEnabled')) {
     $template->param(
         BakerTaylorEnabled  => 1,
@@ -341,6 +325,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(
@@ -365,7 +350,6 @@ if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor'
 }
 
 $template->param(
-    borrower                 => scalar Koha::Patrons->find($borrowernumber),
     patron_messages          => $patron_messages,
     opacnote                 => $borr->{opacnote},
     patronupdate             => $patronupdate,
@@ -377,4 +361,16 @@ $template->param(
     failed_holds             => scalar $query->param('failed_holds'),
 );
 
+# if not an empty string this indicates to return
+# back to the opac-results page
+my $search_query = $query->param('has-search-query');
+
+if ($search_query) {
+
+    print $query->redirect(
+        -uri    => "/cgi-bin/koha/opac-search.pl?$search_query",
+        -cookie => $cookie,
+    );
+}
+
 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };