From 3d1ce21d91685132d8bff2da410cf1e2358bc831 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Tue, 19 Feb 2013 14:49:20 +0100
Subject: [PATCH] Bug 9043: [SIGNED-OFF] Changes to the advanced search page

This patch adds 2 new sysprefs: OpacAdvSearchOptions and
OpacAdvSearchMoreOptions.

These sysprefs are multivalued and you can add or remove some elements on
the adv search page.

This patch allows to display/hide some entries in the advanced search
page at the OPAC.
On this way, it is possible to configure the search options to display.

Test plan:
1/
Fill OpacAdvSearchOptions with Item types and Languages.
Fill OpacAdvSearchMoreOptions with Item types, Languages and Location.
On the advanced search page, verify the Location is only displayed for
the "More options" view.
2/ Try different settings for these prefs
3/ Remove all entries for the OpacAdvSearchMoreOptions and verify that
the "More options" does not displayed additional options.
4/ Remove all entries for the OpacAdvSearchOptions and verify that the
"normal view" does not displayed any options.

Note that this patch only affects the bootstrap theme.

Signed-off-by: Koha Team Lyon 3 <koha@univ-lyon3.fr>
Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl>
---
 installer/data/mysql/sysprefs.sql                   |  2 ++
 installer/data/mysql/updatedatabase.pl              | 19 +++++++++++++++++++
 .../prog/en/modules/admin/preferences/opac.pref     | 21 +++++++++++++++++++++
 .../bootstrap/en/modules/opac-advsearch.tt          | 19 ++++++++++++++++---
 opac/opac-search.pl                                 | 14 +++++++++++---
 5 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index d820b94..1004074 100644
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -213,6 +213,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('OCLCAffiliateID','','','Use with FRBRizeEditions and XISBN. You can sign up for an AffiliateID here: http://www.worldcat.org/wcpa/do/AffiliateUserServices?method=initSelfRegister','free'),
 ('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'),
 ('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'),
+('OpacAdvSearchMoreOptions','pubdate|itemtype|language|subtype|sorting|location','Show search options for the expanded view (More options)','pubdate|itemtype|language|subtype|sorting|location','multiple'),
+('OpacAdvSearchOptions','pubdate|itemtype|language|sorting|location','Show search options','pubdate|itemtype|language|subtype|sorting|location','multiple'),
 ('OPACAllowHoldDateInFuture','0','','If set, along with the AllowHoldDateInFuture system preference, OPAC users can set the date of a hold to be in the future.','YesNo'),
 ('OpacAllowPublicListCreation','1',NULL,'If set, allows opac users to create public lists','YesNo'),
 ('OpacAllowSharingPrivateLists','0',NULL,'If set, allows opac users to share private lists with other patrons','YesNo'),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 97a7a47..fa1b857 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -8577,6 +8577,25 @@ if ( CheckVersion($DBversion) ) {
     SetVersion ($DBversion);
 }
 
+
+
+
+
+
+
+$DBversion = "3.17.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacAdvSearchOptions','pubdate|itemtype|language|sorting|location','Show search options','pubdate|itemtype|language|subtype|sorting|location','multiple');
+    });
+
+    $dbh->do(q{
+        INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacAdvSearchMoreOptions','pubdate|itemtype|language|subtype|sorting|location','Show search options for the expanded view (More options)','pubdate|itemtype|language|subtype|sorting|location','multiple');
+   });
+   print "Upgrade to $DBversion done (Bug 9043: Add system preference OpacAdvSearchOptions and OpacAdvSearchMoreOptions)\n";
+   SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
index 9fe3312..9a39c84 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
@@ -663,3 +663,24 @@ OPAC:
             - pref: PatronSelfRegistrationAdditionalInstructions
               type: textarea
               class: html
+    Advanced Search Options:
+        -
+            - Show search options
+            - pref: OpacAdvSearchOptions
+              multiple:
+                pubdate: Publication date
+                itemtype: Item types
+                language: Language
+                subtype: Subtypes
+                sorting: Sorting
+                location: Location and availability
+        -
+            - Show search options for the expanded view
+            - pref: OpacAdvSearchMoreOptions
+              multiple:
+                pubdate: Publication date
+                itemtype: Item types
+                language: Language
+                subtype: Subtypes
+                sorting: Sorting
+                location: Location and availability
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
index d9b2d4b..800c5a1 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
@@ -120,6 +120,7 @@
     <div class="main">
         <div class="container-fluid">
             <div class="row-fluid">
+              [% IF ( ( OpacAdvSearchOptions.grep('itemtype').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('itemtype').size > 0 and expanded_options ) ) %]
                 <div class="span12">
                     <div id="advsearches" class="toptabs">
                         <ul>
@@ -150,8 +151,10 @@
                         [% END # / FOREACH advancedsearchesloop %]
                     </div> <!-- / #advsearches -->
                 </div> <!-- / .span12 -->
+              [% END %]
 
                 <div class="row-fluid">
+                  [% IF ( ( OpacAdvSearchOptions.grep('pubdate').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('pubdate').size > 0 and expanded_options ) ) %]
                     <div class="span3">
                         <div id="pubrange">
                             <!-- PUB RANGE OPTION -->
@@ -164,7 +167,9 @@
                             <!-- /PUB RANGE OPTION -->
                         </div>
                     </div>
+                  [% END %]
 
+                  [% IF ( ( OpacAdvSearchOptions.grep('language').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('language').size > 0 and expanded_options ) ) %]
                     <div class="span3">
                         <div id="langfilter">
                             <fieldset>
@@ -187,7 +192,9 @@
                             </fieldset>
                         </div> <!-- / #langfilter -->
                     </div> <!-- / .span3 -->
+                  [% END %]
 
+                  [% IF ( ( OpacAdvSearchOptions.grep('location').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('location').size > 0 and expanded_options ) ) %]
                     [% UNLESS ( singleBranchMode ) %]
                         <div class="span3">
                             <!-- AVAILABILITY LIMITS -->
@@ -223,7 +230,9 @@
                             <!-- /AVAILABILITY LIMITS -->
                         </div> <!-- / .span3 -->
                     [% END # / UNLESS singleBranchMode %]
+                  [% END %]
 
+                  [% IF ( ( OpacAdvSearchOptions.grep('sorting').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('sorting').size > 0 and expanded_options ) ) %]
                     <div class="span3">
                     <!-- RANK LIMITS -->
                         <div id="sortby">
@@ -237,9 +246,10 @@
                         </div>
                     <!-- RANK LIMITS -->
                     </div> <!-- / .span3 -->
+                  [% END %]
                 </div> <!-- / .row-fluid -->
 
-                [% IF ( expanded_options ) %]
+                [% IF ( ( OpacAdvSearchOptions.grep('subtype').size > 0 and not expanded_options ) or ( OpacAdvSearchMoreOptions.grep('subtype').size > 0 and expanded_options ) ) %]
                     <div class="row-fluid">
                         [% IF ( usmarc ) %]
                             <!-- SUBTYPE LIMITS -->
@@ -340,6 +350,7 @@
         </div> <!-- / .container-fluid -->
     </div> <!-- / .main -->
 
+    [% IF ( OpacAdvSearchMoreOptions.size > 0 and expanded_options ) or ( OpacAdvSearchOptions.size > 0 and not expanded_options ) %]
         <div class="container-fluid">
             <div class="row-fluid">
                 <div class="span12">
@@ -351,15 +362,17 @@
                 </div> <!-- / .span12 -->
             </div> <!-- / .row-fluid -->
         </div> <!-- / .container-fluid -->
+    [% END %]
 </form>
 
 [% INCLUDE 'opac-bottom.inc' %]
 [% BLOCK searchbuttons %]
     <p>
         <input class="btn btn-success" type="submit" accesskey="s" name="do" title="Search" value="Search" />
-        [% IF ( expanded_options ) %]
+
+        [% IF expanded_options %]
             <a href="/cgi-bin/koha/opac-search.pl?expanded_options=0">[Fewer options]</a>
-        [% ELSE %]
+        [% ELSIF not expanded_options %]
             <a href="/cgi-bin/koha/opac-search.pl?expanded_options=1">[More options]</a>
         [% END %]
         <a href="/cgi-bin/koha/opac-search.pl?do=Clear">[New search]</a>
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 3b37b43..7555825 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -295,9 +295,17 @@ if ( $template_type && $template_type eq 'advsearch' ) {
         }
 
     }
-    $template->param(uc(    C4::Context->preference("marcflavour")) => 1,   # we already did this for UNIMARC
-                            advsearch => 1,
-                            search_boxes_loop => \@search_boxes_array);
+
+    my @advsearch_limits = split /\|/, C4::Context->preference('OpacAdvSearchOptions');
+    my @advsearch_more_limits = split /\|/,
+      C4::Context->preference('OpacAdvSearchMoreOptions');
+    $template->param(
+        uc( C4::Context->preference("marcflavour") ) => 1,    # we already did this for UNIMARC
+        advsearch         => 1,
+        search_boxes_loop => \@search_boxes_array,
+        OpacAdvSearchOptions     => \@advsearch_limits,
+        OpacAdvSearchMoreOptions => \@advsearch_more_limits,
+    );
 
     # use the global setting by default
     if ( C4::Context->preference("expandedSearchOption") == 1 ) {
-- 
2.0.0.rc2