From 338ed175eff13bb63fc51af0978588329e701f60 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Sun, 28 Feb 2021 14:39:53 +0000
Subject: [PATCH] Bug 26247: Make retaining search terms in staff client
 optional

This patch adds a new system preference 'StaffRetainSearchTerms' - if enabled
header searches will be retained on the results page as current behvaiour. If disabled
the search box will be empty after searching

To test:
1 - Search in staff client from header
2 - Confirm search terms are retained
3 - Apply patch, update database
4 - Search again, terms still retained
5 - Disable StaffRetainSearchTerms preference
6 - Search again
7 - Search box is cleared

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

diff --git a/catalogue/search.pl b/catalogue/search.pl
index 4ce6b4f9ed..6bc9723877 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -366,8 +366,8 @@ if ($indexes[0] && (!$indexes[1] || $params->{'scan'})) {
 # an operand can be a single term, a phrase, or a complete ccl query
 my @operands = map uri_unescape($_), $cgi->multi_param('q');
 
-# if a simple search, display the value in the search box
-if ($operands[0] && !$operands[1]) {
+# if a simple search and StaffRetainSearchTerms, display the value in the search box
+if (C4::Context->preference('StaffRetainSearchTerms') && $operands[0] && !$operands[1]) {
     my $ms_query = $operands[0];
     $ms_query =~ s/ #\S+//;
     $template->param(ms_value => $ms_query);
diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql
index f163912142..a306486790 100644
--- a/installer/data/mysql/mandatory/sysprefs.sql
+++ b/installer/data/mysql/mandatory/sysprefs.sql
@@ -633,6 +633,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('StaffDetailItemSelection', '1', NULL, 'Enable item selection in record detail page', 'YesNo'),
 ('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff interface','Choice'),
 ('StaffLoginInstructions', '', NULL, 'HTML to go into the login box for the staff interface','Free'),
+('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'),
 ('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'),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index bb438f901f..34724f2a68 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -23267,7 +23267,6 @@ if( CheckVersion( $DBversion ) ) {
 $DBversion = '20.06.00.063';
 if( CheckVersion( $DBversion ) ) {
     $dbh->do(q{INSERT IGNORE INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value) VALUES (NULL, NULL, NULL, 'decreaseloanholds', NULL) });
-
     NewVersion( $DBversion, 14866, "Add decreaseloanholds circulation rule" );
 }
 
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 04a77f8085..0ab3afa278 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
@@ -261,6 +261,13 @@ Searching:
                   0: "don't search"
             - on all variations of the ISBN.
         -
+            - When searching from the header in the staff client
+            - pref: StaffRetainSearchTerms
+              choices:
+                  yes: "retain"
+                  no: "don't retain"
+            - search terms between searches.
+        -
             - pref: BiblioItemtypeInfo
               choices:
                   1: "Display"
-- 
2.11.0