From f8341c316d71a00c602238df1776fd97e7e115eb Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Sun, 28 Feb 2021 16:18:45 +0000
Subject: [PATCH] Bug 26247: Make search terms optionally sticky

This patch adds a configurable option for retaining stickiness of search terms
across search tabs

To test:
1 - Apply all patches except this one, enable StaffRetainSearchTerms
2 - Search in staff client from header
3 - Confirm behaviour is that term is retained, but not copied when switching header search tab
4 - Apply this patch, updatedatabase
5 - Search again
6 - Previous behaviour is restored, search terms are sticky between tabs
7 - Disable preference StaffStickySearchTerms
8 - Search again
9 - Search terms retained, but not sticky

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
---
 installer/data/mysql/mandatory/sysprefs.sql                        | 1 +
 koha-tmpl/intranet-tmpl/prog/en/includes/catalog-search-box.inc    | 4 ++++
 .../intranet-tmpl/prog/en/modules/admin/preferences/searching.pref | 7 +++++++
 3 files changed, 12 insertions(+)

diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql
index a306486790..702322c162 100644
--- a/installer/data/mysql/mandatory/sysprefs.sql
+++ b/installer/data/mysql/mandatory/sysprefs.sql
@@ -636,6 +636,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('StaffRetainSearchTerms', '1', NULL, 'If enabled, searches entered into the search bar will be retained', 'YesNo'),
 ('StaffSearchResultsDisplayBranch','holdingbranch','holdingbranch|homebranch','Controls the display of the home or holding branch for staff search results','Choice'),
 ('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the staff interface','Integer'),
+('StaffStickySearchTerms', '1', NULL, 'If enabled, searches entered into the search bar will be copied to other header tabs', 'YesNo'),
 ('StaticHoldsQueueWeight','0',NULL,'Specify a list of library location codes separated by commas -- the list of codes will be traversed and weighted with first values given higher weight for holds fulfillment -- alternatively, if RandomizeHoldsQueueWeight is set, the list will be randomly selective','Integer'),
 ('StatisticsFields','location|itype|ccode', NULL, 'Define Fields (from the items table) used for statistics members','Free'),
 ('StockRotation','0',NULL,'If ON, enables the stock rotation module','YesNo'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-search-box.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-search-box.inc
index 7eca35f0b1..88453ac250 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-search-box.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalog-search-box.inc
@@ -7,7 +7,11 @@
             [% ELSE %]
                 <label class="tip" for="search-form">Enter search keywords:</label>
             [% END %]
+            [% IF ( Koha.Preference('StaffStickySearchTerms') )  %]
+                <input type="text" name="q" id="search-form" size="40" value="[% ms_value | html %]" title="Enter the terms you wish to search for." class="head-searchbox sticky form-text" />
+            [% ELSE %]
                 <input type="text" name="q" id="search-form" size="40" value="[% ms_value | html %]" title="Enter the terms you wish to search for." class="head-searchbox form-text" />
+            [% END %]
 				<input type="submit" value="Submit" class="submit" />
 		</form>
 	</div>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
index 0ab3afa278..2065d5e803 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
@@ -268,6 +268,13 @@ Searching:
                   no: "don't retain"
             - search terms between searches.
         -
+            - When searching from the header in the staff client
+            - pref: StaffStickySearchTerms
+              choices:
+                  yes: "copy"
+                  no: "don't copy"
+            - search terms between search tabs.
+        -
             - pref: BiblioItemtypeInfo
               choices:
                   1: "Display"
-- 
2.11.0