From 894e001c5f239242332cde4f33ed0cedf4cf82c8 Mon Sep 17 00:00:00 2001
From: Lee Jamison <ldjamison@marywood.edu>
Date: Tue, 23 Aug 2016 11:55:12 -0400
Subject: [PATCH] Bug 17153: Simplified redirect

---
 C4/Output.pm      | 12 ++++++++++--
 opac/opac-user.pl |  7 ++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/C4/Output.pm b/C4/Output.pm
index af7dd5a..6d110cf 100644
--- a/C4/Output.pm
+++ b/C4/Output.pm
@@ -43,13 +43,13 @@ BEGIN {
     %EXPORT_TAGS = ( all =>[qw(setlanguagecookie pagination_bar parametrized_url
                                 &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
                     ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
-                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
+                    html =>[qw(&output_with_http_headers &output_html_with_http_headers &output_with_redirect)]
                 );
     push @EXPORT, qw(
         setlanguagecookie getlanguagecookie pagination_bar parametrized_url
     );
     push @EXPORT, qw(
-        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers
+        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers &output_with_redirect
     );
 
 }
@@ -284,6 +284,14 @@ sub output_with_http_headers {
     print $query->header($options), $data;
 }
 
+sub output_with_redirect {
+	my ( $query, $url, $cookie ) = @_;
+	print $query->redirect(
+		-URL    => $url,
+		-COOKIE => $cookie,
+	);
+}
+
 sub output_html_with_http_headers {
     my ( $query, $cookie, $data, $status, $extra_options ) = @_;
     output_with_http_headers( $query, $cookie, $data, 'html', $status, $extra_options );
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 0087a6a..7e25268 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -356,4 +356,9 @@ $template->param(
     failed_holds             => scalar $query->param('failed_holds'),
 );
 
-output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
+if ( !$ENV{HTTP_REFERER} =~ /opac-search.pl/ ) {
+    output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
+}
+else {
+    output_with_redirect( $query, $ENV{HTTP_REFERER}, $cookie );
+}
\ No newline at end of file
-- 
2.1.4