From 5bbcb22720d26bc0b302ccd1fc1df621d86f2bd7 Mon Sep 17 00:00:00 2001
From: Fridolin SOMERS <fridolin.somers@biblibre.com>
Date: Fri, 10 Jan 2014 11:42:06 +0100
Subject: [PATCH] Bug 11516 - OPAC highlight lost in results browser

When OpacHighlightedWords syspref is on, the current search terms are highlighted in results and detail pages.
This workes in detail page with the URL param 'query_desc'.
This parameter must be managed in results browser (appears when OpacBrowseResults syspref is on) links.

This patch adds query_desc parameter in results list and changes next and previous links to be build into TT instead of perl to manage query_desc parameter only into TT.

Test plan :
- Edit sysprefs :  OpacHighlightedWords on, OpacBrowseResults on, OPACXSLTDetailsDisplay off, OPACXSLTResultsDisplay off (highlight actually does not work with XSLT)
- Perform a search with a term existing into title
=> You see the term highlighted in search results
- Go to detail of a result with highlight
=> You see the term highlighted
- Click on "Next"
=> you see query_desc in URL, and if search term is present it is highlighted
- Same for "Previous"
- Click on "Browse results"
- Click on a result
=> you see query_desc in URL, and if search term is present it is highlighted
---
 .../opac-tmpl/bootstrap/en/modules/opac-detail.tt  | 13 +++++++++---
 koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 23 +++++++++++++++++++---
 opac/opac-detail.pl                                | 17 ++++++++--------
 3 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
index 867cb74..bcf28b7 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
@@ -1022,14 +1022,16 @@
                         </div>
                         <ul class="pg_menu clearfix">
                             <li class="left_results">
-                                [% IF ( previous ) %]<a href="[% previous |url %]" title="See: [% IF ( previousTitle ) %][% previousTitle |html %][% ELSE %]previous biblio[% END %]">&laquo; Previous</a>
+                                [% IF ( previousBiblionumber ) %]
+                                    <a href="opac-detail.pl?biblionumber=[% previousBiblionumber %][% IF ( query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]" title="See: [% IF ( previousTitle ) %][% previousTitle |html %][% ELSE %]previous biblio[% END %]">&laquo; Previous</a>
                                 [% ELSE %]
                                     <span>Previous</span>
                                 [% END %]
                             </li>
                             <li class="back_results"><a href="opac-search.pl?[% busc |url %]" title="Back to the results search list">Back to results</a></li>
                             <li class="right_results">
-                                [% IF ( next ) %]<a href="[% next %]" title="See: [% IF ( nextTitle ) %][% nextTitle |html %][% ELSE %]next biblio[% END %]">Next &raquo;</a>
+                                [% IF ( nextBiblionumber ) %]
+                                    <a href="opac-detail.pl?biblionumber=[% nextBiblionumber %][% IF ( query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]" title="See: [% IF ( nextTitle ) %][% nextTitle |html %][% ELSE %]next biblio[% END %]">Next &raquo;</a>
                                 [% ELSE %]
                                     <span>Next</span>
                                 [% END %]
@@ -1253,7 +1255,12 @@
         var pag_index_ini = [% indexPag %];
         [% IF ( listResults ) %]
             [% FOREACH listResult IN listResults %]
-                arrPagination[[% listResult.index %]] = {url:"[% listResult.url %]", title:"[% listResult.title|remove('\n')|html %]", author:"[% listResult.author|html %]", biblionumber:[% listResult.biblionumber %]};
+                arrPagination[[% listResult.index %]] = {
+                    url:"[% listResult.url %][% IF ( listResult.url && query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]",
+                    title:"[% listResult.title|remove('\n')|html %]",
+                    author:"[% listResult.author|html %]",
+                    biblionumber:[% listResult.biblionumber %]
+                };
            [% END %]
         [% END %]
     [% END %]
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
index 05c4010..10e600f 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
@@ -43,7 +43,12 @@
         var pag_index_ini = [% indexPag %];
         [% IF ( listResults ) %]
             [% FOREACH listResult IN listResults %]
-                arrPagination[[% listResult.index %]] = {url:"[% listResult.url %]", title:"[% listResult.title|remove('\n')|html %]", author:"[% listResult.author|html %]", biblionumber:[% listResult.biblionumber %]};
+                arrPagination[[% listResult.index %]] = {
+                    url:"[% listResult.url %][% IF ( listResult.url && query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]",
+                    title:"[% listResult.title|remove('\n')|html %]",
+                    author:"[% listResult.author|html %]",
+                    biblionumber:[% listResult.biblionumber %]
+                };
            [% END %]
         [% END %]
     [% END %]
@@ -1423,9 +1428,21 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
     <div class="nav_results">
         <div class="l_Results">[% IF ( listResults ) %]<a href="#" id="a_listResults" title="Show pagination list ([% indexPag %]-[% indexPagEnd %] / [% totalPag %])">Browse results</a>[% ELSE %]<span>Browse results</span>[% END %]</div>
         <ul class="pg_menu clearfix">
-            <li class="left_results">[% IF ( previous ) %]<a href="[% previous %]" title="See: [% IF ( previousTitle ) %][% previousTitle |html %][% ELSE %]previous biblio[% END %]">&laquo; Previous</a>[% ELSE %]<span>Previous</span>[% END %]</li>
+            <li class="left_results">
+                [% IF ( previousBiblionumber ) %]
+                    <a href="opac-detail.pl?biblionumber=[% previousBiblionumber %][% IF ( query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]" title="See: [% IF ( previousTitle ) %][% previousTitle |html %][% ELSE %]previous biblio[% END %]">&laquo; Previous</a>
+                [% ELSE %]
+                    <span>Previous</span>
+                [% END %]
+            </li>
             <li class="back_results"><a href="opac-search.pl?[% busc %]" title="Back to the results search list">Back to results</a></li>
-            <li class="right_results">[% IF ( next ) %]<a href="[% next %]" title="See: [% IF ( nextTitle ) %][% nextTitle |html %][% ELSE %]next biblio[% END %]">Next &raquo;</a>[% ELSE %]<span>Next</span>[% END %]</li>
+            <li class="right_results">
+                [% IF ( nextBiblionumber ) %]
+                    <a href="opac-detail.pl?biblionumber=[% nextBiblionumber %][% IF ( query_desc && OpacHighlightedWords ) %]&query_desc=[% query_desc |uri %][% END %]" title="See: [% IF ( nextTitle ) %][% nextTitle |html %][% ELSE %]next biblio[% END %]">Next &raquo;</a>
+                [% ELSE %]
+                    <span>Next</span>
+                [% END %]
+            </li>
         </ul>
         [% IF ( listResults ) %]
         <div class="pagination">
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 77de12f..a6853b5 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -374,20 +374,21 @@ if ($session->param('busc')) {
         my $newbusc = rebuildBuscParam(\%arrParamsBusc);
         $session->param("busc" => $newbusc);
     }
-    my ($previous, $next, $dataBiblioPaging);
+    my ($numberBiblioPaging, $dataBiblioPaging);
     # Previous biblio
-    if ($paging{'previous'}->{biblionumber}) {
-        $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}  . '&query_desc=' . $query->param('query_desc');
-        $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
+    $numberBiblioPaging = $paging{'previous'}->{biblionumber};
+    if ($numberBiblioPaging) {
+        $template->param( 'previousBiblionumber' => $numberBiblioPaging );
+        $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
         $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
     }
     # Next biblio
-    if ($paging{'next'}->{biblionumber}) {
-        $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber} . '&query_desc=' . $query->param('query_desc');
-        $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
+    $numberBiblioPaging = $paging{'next'}->{biblionumber};
+    if ($numberBiblioPaging) {
+        $template->param( 'nextBiblionumber' => $numberBiblioPaging );
+        $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
         $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
     }
-    $template->param('previous' => $previous, 'next' => $next);
     # Partial list of biblio results
     my @listResults;
     for (my $j = 0; $j < @arrBiblios; $j++) {
-- 
1.8.3.2