Bug 17374: Make use of fields from syspref 'DefaultPatronSearchFields' in patron...
authorNick Clemens <nick@bywatersolutions.com>
Thu, 27 Oct 2016 14:21:02 +0000 (14:21 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 10 Mar 2020 15:18:29 +0000 (15:18 +0000)
This patch preserves the current dropdown choices for patron search and adds fields from
the DefaultPatronSearchFields system preference

To test:
1 - View the regular patron search and note fields in dropdown
2 - Apply patch, ensure dropdown has not changed
3 - Add fields to DefaultPatronSearchFields, note they are available in
dropdown
4 - Ensure existing and new fields search properly

Signed-off-by: Kelly <kelly@bywatersolutions.com>
Signed-off-by: Maxime Dufresne <maxime.dufresne@inlibro.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Utils/DataTables/Members.pm
installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt

index 4504bd3..c4726ec 100644 (file)
@@ -85,15 +85,10 @@ sub search {
 
     my $searchfields = {
         standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid',
-        surname => 'surname',
         email => 'email,emailpro,B_email',
         borrowernumber => 'borrowernumber',
-        userid => 'userid',
         phone => 'phone,phonepro,B_phone,altcontactphone,mobile',
         address => 'streetnumber,streettype,address,address2,city,state,zipcode,country',
-        dateofbirth => 'dateofbirth',
-        sort1 => 'sort1',
-        sort2 => 'sort2',
     };
 
     # * is replaced with % for sql
@@ -124,11 +119,17 @@ sub search {
         }
 
         my @where_strs_or;
-        for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) {
-            push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?";
+        if ( defined $searchfields->{$searchfieldstype} ) {
+            for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) {
+                push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?";
+                push @where_args, $term;
+            }
+        } else {
+            push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfieldstype) . " LIKE ?";
             push @where_args, $term;
         }
 
+
         if ( $searchfieldstype eq 'standard' and C4::Context->preference('ExtendedPatronAttributes') and $searchmember ) {
             my $matching_borrowernumbers = C4::Members::Attributes::SearchIdMatchingAttribute($searchmember);
 
diff --git a/installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl b/installer/data/mysql/atomicupdate/bug17374_update_DefaultPatronSearchFields_description.perl
new file mode 100644 (file)
index 0000000..2a8122a
--- /dev/null
@@ -0,0 +1,7 @@
+$DBversion = 'XXX';  # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "UPDATE systempreferences SET  explanation = 'Comma separated list defining the default fields to be used during a patron search using the \"standard\" option. If empty Koha will default to \"surname,firstname,othernames,cardnumber,userid\". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.' WHERE variable='DefaultPatronSearchFields' " );
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17374 - update description of DefaultPatronSearchFields)\n";
+}
index 62283f1..fc6cb88 100644 (file)
@@ -148,7 +148,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'),
 ('DefaultLongOverdueDays', '', NULL, "Set the LOST value of an item when the item has been overdue for more than n days.", 'integer'),
 ('DefaultLongOverdueLostValue', '', NULL, "Set the LOST value of an item to n when the item has been overdue for more than defaultlongoverduedays days.", 'integer'),
-('DefaultPatronSearchFields',    'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search','free'),
+('DefaultPatronSearchFields',    'surname,firstname,othernames,cardnumber,userid',NULL,'Comma separated list defining the default fields to be used during a patron search using the "standard" option. If empty Koha will default to "surname,firstname,othernames,cardnumber,userid". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page.','free'),
 ('defaultSortField','relevance','relevance|popularity|call_number|pubdate|acqdate|title|author','Specify the default field used for sorting','Choice'),
 ('defaultSortOrder','dsc','asc|dsc|az|za','Specify the default sort order','Choice'),
 ('DefaultToLoggedInLibraryCircRules',  '0', NULL ,  'If enabled, circ rules editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.',  'YesNo'),
index 7490849..68a894f 100644 (file)
@@ -1,7 +1,9 @@
 [% USE Koha %]
 [% USE Branches %]
 [% USE Categories %]
+[% USE raw %]
 [% PROCESS 'html_helpers.inc' %]
+[% PROCESS 'patronfields.inc' %]
 <div class="gradient">
 <h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName | html %]</a></h1><!-- Begin Patrons Resident Search Box -->
 <div id="header_search">
     </div>
 
 
+
     <div id="filters">
         <p><label for="searchfieldstype">Search fields:</label>
             <select name="searchfieldstype" id="searchfieldstype">
-              [% IF searchfieldstype == "standard" %]
-                <option selected="selected" value='standard'>Standard</option>
-              [% ELSE %]
-                <option value='standard'>Standard</option>
-              [% END %]
-              [% IF searchfieldstype == "surname" %]
-                <option selected="selected" value='surname'>Surname</option>
-              [% ELSE %]
-                <option value='surname'>Surname</option>
-              [% END %]
-              [% IF searchfieldstype == "email" %]
-                <option selected="selected" value='email'>Email</option>
-              [% ELSE %]
-                <option value='email'>Email</option>
-              [% END %]
-              [% IF searchfieldstype == "borrowernumber" %]
-                <option selected="selected" value='borrowernumber'>Borrower number</option>
-              [% ELSE %]
-                <option value='borrowernumber'>Borrower number</option>
-              [% END %]
-              [% IF searchfieldstype == "userid" %]
-                <option selected="selected" value='userid'>Username</option>
-              [% ELSE %]
-                <option value='userid'>Username</option>
-              [% END %]
-              [% IF searchfieldstype == "phone" %]
-                <option selected="selected" value='phone'>Phone number</option>
-              [% ELSE %]
-                <option value='phone'>Phone number</option>
-              [% END %]
-              [% IF searchfieldstype == "address" %]
-                <option selected="selected" value='address'>Street address</option>
-              [% ELSE %]
-                <option value='address'>Street address</option>
-              [% END %]
-              [% IF searchfieldstype == "dateofbirth" %]
-                <option selected="selected" value='dateofbirth'>Date of birth</option>
-              [% ELSE %]
-                <option value='dateofbirth'>Date of birth</option>
-              [% END %]
-              [% IF searchfieldstype == "sort1" %]
-                <option selected="selected" value='sort1'>Sort field 1</option>
-              [% ELSE %]
-                <option value='sort1'>Sort field 1</option>
-              [% END %]
-              [% IF searchfieldstype == "sort2" %]
-                <option selected="selected" value='sort2'>Sort field 2</option>
-              [% ELSE %]
-                <option value='sort2'>Sort field 2</option>
+              [% pref_fields = Koha.Preference('DefaultPatronSearchFields').split(',') %]
+              [% default_fields = [ 'standard', 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
+              [% search_options = default_fields.merge(pref_fields).unique %]
+              [% FOREACH s_o IN search_options %]
+                  [% display_name = PROCESS patron_fields name=s_o %]
+                  [% NEXT IF display_name.length == 5 %]
+                  [% IF searchfieldstype == s_o %]
+                      <option selected="selected" value=[% s_o | html %]>[% display_name | $raw %]</option>
+                  [% ELSE %]
+                      <option value=[% s_o | html %]>[% display_name | $raw %]</option>
+                  [% END %]
               [% END %]
             </select>
         </p>
-
         <p>
             <label for="searchtype">Search type:</label>
             <select name="searchtype" id="searchtype">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc
new file mode 100644 (file)
index 0000000..ca790d8
--- /dev/null
@@ -0,0 +1,75 @@
+[%- BLOCK patron_fields -%]
+     [%- SWITCH name -%]
+     [%- CASE 'standard' -%]<span>Standard</span>
+     [%- CASE 'borrowernumber' -%]<span>Borrower number</span>
+     [%- CASE 'cardnumber' -%]<span>Card number</span>
+     [%- CASE 'surname' -%]<span>Surname</span>
+     [%- CASE 'firstname' -%]<span>First name</span>
+     [%- CASE 'title' -%]<span>Title</span>
+     [%- CASE 'othernames' -%]<span>Other names</span>
+     [%- CASE 'initials' -%]<span>Initials</span>
+     [%- CASE 'streetnumber' -%]<span>Street number</span>
+     [%- CASE 'streettype' -%]<span>Street type</span>
+     [%- CASE 'address' -%]<span>Address</span>
+     [%- CASE 'address2' -%]<span>Address line 2</span>
+     [%- CASE 'city' -%]<span>City</span>
+     [%- CASE 'state' -%]<span>State</span>
+     [%- CASE 'zipcode' -%]<span>Zip code</span>
+     [%- CASE 'country' -%]<span>Country</span>
+     [%- CASE 'email' -%]<span>Email</span>
+     [%- CASE 'phone' -%]<span>Phone</span>
+     [%- CASE 'mobile' -%]<span>Mobile phone</span>
+     [%- CASE 'fax' -%]<span>Fax</span>
+     [%- CASE 'emailpro' -%]<span>Secondary email</span>
+     [%- CASE 'phonepro' -%]<span>Secondary phone</span>
+     [%- CASE 'B_streetnumber' -%]<span>Alternate street number</span>
+     [%- CASE 'B_streettype' -%]<span>Alternate street type</span>
+     [%- CASE 'B_address' -%]<span>Alternate address</span>
+     [%- CASE 'B_address2' -%]<span>Alternate address line 2</span>
+     [%- CASE 'B_city' -%]<span>Alternate city</span>
+     [%- CASE 'B_state' -%]<span>Alternate state</span>
+     [%- CASE 'B_zipcode' -%]<span>Alternate zip code</span>
+     [%- CASE 'B_country' -%]<span>Alternate Country</span>
+     [%- CASE 'B_email' -%]<span>Alternate email</span>
+     [%- CASE 'B_phone' -%]<span>Alternate phone</span>
+     [%- CASE 'dateofbirth' -%]<span>Date of birth</span>
+     [%- CASE 'branchcode' -%]<span>Branch code</span>
+     [%- CASE 'categorycode' -%]<span>Category code</span>
+     [%- CASE 'dateenrolled' -%]<span>Registration date</span>
+     [%- CASE 'dateexpiry' -%]<span>Expiration date</span>
+     [%- CASE 'gonenoaddress' -%]<span>Gone no address</span>
+     [%- CASE 'lost' -%]<span>Lost card</span>
+     [%- CASE 'debarred' -%]<span>Restricted</span>
+     [%- CASE 'debarredcomment' -%]<span>Restriction reason</span>
+     [%- CASE 'contactname' -%]<span>Guarantor surname</span>
+     [%- CASE 'contactfirstname' -%]<span>Guarantor firstname</span>
+     [%- CASE 'contacttitle' -%]<span>Guarantor title</span>
+     [%- CASE 'guarantorid' -%]<span>Guarantor ID</span>
+     [%- CASE 'borrowernotes' -%]<span>Circulation Note</span>
+     [%- CASE 'relationship' -%]<span>Guarantor relationship</span>
+     [%- CASE 'sex' -%]<span>Sex</span>
+     [%- CASE 'flags' -%]<span>Permissions (code)</span>
+     [%- CASE 'userid' -%]<span>User name</span>
+     [%- CASE 'opacnote' -%]<span>OPAC note</span>
+     [%- CASE 'contactnote' -%]<span>Contact note</span>
+     [%- CASE 'sort1' -%]<span>Sort field 1</span>
+     [%- CASE 'sort2' -%]<span>Sort field 2</span>
+     [%- CASE 'altcontactfirstname' -%]<span>Alternate contact first name</span>
+     [%- CASE 'altcontactsurname' -%]<span>Alternate contact surname</span>
+     [%- CASE 'altcontactaddress1' -%]<span>Alternate contact address</span>
+     [%- CASE 'altcontactaddress2' -%]<span>Alternate contact address line 2</span>
+     [%- CASE 'altcontactaddress3' -%]<span>Alternate contact city</span>
+     [%- CASE 'altcontactstate' -%]<span>Alternate contact state</span>
+     [%- CASE 'altcontactzipcode' -%]<span>Alternate contact zip code</span>
+     [%- CASE 'altcontactcountry' -%]<span>Alternate contact country</span>
+     [%- CASE 'altcontactphone' -%]<span>Alternate contact phone</span>
+     [%- CASE 'smsalertnumber' -%]<span>SMS alert number</span>
+     [%- CASE 'sms_provider_id' -%]<span>SMS provider</span>
+     [%- CASE 'privacy' -%]<span>Privacy (code)</span>
+     [%- CASE 'privacy_guarantor_checkouts' -%]<span>Guarantor can view checkouts</span>
+     [%- CASE 'updated_on' -%]<span>Last updated</span>
+     [%- CASE 'lastseen' -%]<span>Last seen</span>
+     [%- CASE 'checkprevcheckout' -%]<span>Check previous checkout</span>
+     [%- CASE DEFAULT -%]
+     [%- END -%]
+[%- END -%]
index 9e37372..99ea6bd 100644 (file)
@@ -129,7 +129,7 @@ Patrons:
      -
          - pref: DefaultPatronSearchFields
            class: multi
-         - "Comma separated list defining the default fields to be used during a patron search"
+         - "Comma separated list defining the default fields to be used during a patron search using the \"standard\" option. If empty Koha will default to \"surname,firstname,othernames,cardnumber,userid\". Additional fields added to this preference will be added as search options in the dropdown menu on the patron search page."
      -
          - pref: PatronQuickAddFields
            class: multi
index 3d79c56..37c5f5f 100644 (file)
@@ -5,6 +5,7 @@
 [% USE Branches %]
 [% USE Categories %]
 [% SET footerjs = 1 %]
+[% PROCESS 'patronfields.inc' %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Patrons [% IF ( searching ) %]&rsaquo; Search results[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
                       <li>
                         <label for="searchfieldstype_filter">Search fields:</label>
                         <select name="searchfieldstype" id="searchfieldstype_filter">
-                          [% IF searchfieldstype == "standard" %]
-                            <option selected="selected" value='standard'>Standard</option>
-                          [% ELSE %]
-                            <option value='standard'>Standard</option>
-                          [% END %]
-                          [% IF searchfieldstype == "surname" %]
-                            <option selected="selected" value='surname'>Surname</option>
-                          [% ELSE %]
-                            <option value='surname'>Surname</option>
-                          [% END %]
-                          [% IF searchfieldstype == "email" %]
-                            <option selected="selected" value='email'>Email</option>
-                          [% ELSE %]
-                            <option value='email'>Email</option>
-                          [% END %]
-                          [% IF searchfieldstype == "borrowernumber" %]
-                            <option selected="selected" value='borrowernumber'>Borrower number</option>
-                          [% ELSE %]
-                            <option value='borrowernumber'>Borrower number</option>
-                          [% END %]
-                          [% IF searchfieldstype == "userid" %]
-                            <option selected="selected" value='userid'>Username</option>
-                          [% ELSE %]
-                            <option value='userid'>Username</option>
-                          [% END %]
-                          [% IF searchfieldstype == "phone" %]
-                            <option selected="selected" value='phone'>Phone number</option>
-                          [% ELSE %]
-                            <option value='phone'>Phone number</option>
-                          [% END %]
-                          [% IF searchfieldstype == "address" %]
-                            <option selected="selected" value='address'>Street address</option>
-                          [% ELSE %]
-                            <option value='address'>Street address</option>
-                          [% END %]
-                          [% IF searchfieldstype == "dateofbirth" %]
-                            <option selected="selected" value='dateofbirth'>Date of birth</option>
-                          [% ELSE %]
-                            <option value='dateofbirth'>Date of birth</option>
-                          [% END %]
-                          [% IF searchfieldstype == "sort1" %]
-                            <option selected="selected" value='sort1'>Sort field 1</option>
-                          [% ELSE %]
-                            <option value='sort1'>Sort field 1</option>
-                          [% END %]
-                          [% IF searchfieldstype == "sort2" %]
-                            <option selected="selected" value='sort2'>Sort field 2</option>
-                          [% ELSE %]
-                            <option value='sort2'>Sort field 2</option>
-                          [% END %]
+                            [% pref_fields = Koha.Preference('DefaultPatronSearchFields').split(',') %]
+                            [% default_fields = [ 'standard', 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
+                            [% search_options = default_fields.merge(pref_fields).unique %]
+                            [% FOREACH s_o IN search_options %]
+                                [% display_name = PROCESS patron_fields name=s_o %]
+                                [% NEXT IF display_name.length == 5 %]
+                                [% IF searchfieldstype == s_o %]
+                                    <option selected="selected" value=[% s_o | html %]>[% display_name | $raw %]</option>
+                                [% ELSE %]
+                                    <option value=[% s_o | html %]>[% display_name | $raw %]</option>
+                                [% END %]
+                            [% END %]
                         </select>
                       </li>
                       <li>