From e2c8d882c0dbb836de88bd44199e880a32e73970 Mon Sep 17 00:00:00 2001
From: Magnus Enger <magnus@libriotech.no>
Date: Thu, 21 Apr 2016 14:58:11 +0200
Subject: [PATCH] Bug 16316 - Limit patron search to surname
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch makes it possible to limit a patron search to
search just for surnames.

To test:
- Apply the patch
- Add two patrons, called e.g. "John Doe" and "Doe John"
- Go to Patrons in the Intranet
- Make sure you have selected "Search fields" = Standard
- Search for "john" and verify both patrons show up
- Search for "doe" and verify both patrons show up
- Set "Search fields" = Surname and search for "john".
  "Doe John" should show up, but not "John Doe"
- Set "Search fields" = Surname and search for "doe".
  Neither "Doe John" nor "John Doe" should show up.

Sponsored-by: Alingsås Public Library, Sweden
---
 C4/Utils/DataTables/Members.pm                             | 1 +
 koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc | 5 +++++
 koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt  | 5 +++++
 3 files changed, 11 insertions(+)

diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm
index 1ebecd7..090eb97 100644
--- a/C4/Utils/DataTables/Members.pm
+++ b/C4/Utils/DataTables/Members.pm
@@ -61,6 +61,7 @@ sub search {
 
     my $searchfields = {
         standard => 'surname,firstname,othernames,cardnumber,userid',
+        surname => 'surname',
         email => 'email,emailpro,B_email',
         borrowernumber => 'borrowernumber',
         userid => 'userid',
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
index 4765e03..1b3abe7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
@@ -22,6 +22,11 @@
               [% 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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
index cfe6f21..560d9f7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
@@ -423,6 +423,11 @@ function filterByFirstLetterSurname(letter) {
                 [% 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 %]
-- 
1.9.1