From b9f322972fc85df1c946fc52ce1900070cb0e318 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
---
 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 1419759c85..ddcfcf2a12 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -362,8 +362,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 f09947e71b..a1c2cae039 100644
--- a/installer/data/mysql/mandatory/sysprefs.sql
+++ b/installer/data/mysql/mandatory/sysprefs.sql
@@ -622,6 +622,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 0cad111f93..cbbd2b73c6 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -23255,7 +23255,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 eaaf56344b..fc40ab7b52 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:
                   no: "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:
                   yes: "Display"
-- 
2.11.0