From 390470337077c58b6d4fd1dd64e2090421a53f36 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Fri, 26 Jun 2020 20:12:58 +0000
Subject: [PATCH] Bug 25654: Make the contact and non-patron guarantor sections
 separate on patron entry form

This patch reverses what I think was an unintended change made by Bug
14570 in which the non-patron guarantor fields are shown for all patron
types (not just child patrons) and  grouped with the patron contact fields.

This patch creates a new "Non-patron guarantor" fieldset to show along
with "Patron guarantor" when adding or editing child patrons.

To test, apply the patch check that the  BorrowerUnwantedField system
preference does not contain contactname, contactfirstname,
or relationship.

 - Open an adult patron for editing. You should see no guarantor-related
   fields.
 - Open a child patron for editing. There should be two guarantor
   sections: "Patron guarantor" and "Non-patron guarantor."
   - Test that adding patron guarantors and non-patron guarantors works
     correctly.
   - Add "contactname|contactfirstname|relationship" to the
     BorrowerUnwantedField system preference.
   - Reload the child patron entry form. The non-patron guarantor
     section should now be hidden.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Christopher Brannon <cbrannon@cdalibrary.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 .../prog/en/modules/members/memberentrygen.tt      | 113 +++++++++++----------
 1 file changed, 60 insertions(+), 53 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
index 3c218b00ff..5f5978b0a8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -409,7 +409,7 @@ legend:hover {
                                     [% SET possible_relationships = Koha.Preference('borrowerRelationship') %]
                                     <div id="memberentry_guarantor_anchor">
                                         <fieldset id="memberentry_guarantor" class="rows">
-                                            <legend>Guarantor information</legend>
+                                            <legend>Patron guarantor</legend>
 
                                             <div id="guarantor_relationships">
                                                 [% FOREACH r IN relationships %]
@@ -560,6 +560,65 @@ legend:hover {
                                             </ol>
                                         </fieldset> <!-- /#memberentry_guarantor -->
                                     </div> <!-- #/memberentry_guarantor_anchor -->
+
+                                    [% UNLESS nocontactname && nocontactfirstname && norelationship %]
+                                        <fieldset class="rows" id="non_patron_guarantor">
+                                            <legend>Non-patron guarantor</legend>
+                                            <ol>
+                                                [% UNLESS nocontactname %]
+                                                    <li>
+                                                        [% IF ( mandatorycontactname ) %]
+                                                            <label for="contactname" class="required">
+                                                        [% ELSE %]
+                                                            <label for="contactname">
+                                                        [% END %]
+                                                            Guarantor surname:
+                                                        </label>
+                                                        <input type="text" id="contactname" name="contactname" value="[% patron.contactname | html %]" />
+                                                        [% IF ( mandatorycontactname ) %]
+                                                            <span class="required">Required</span>
+                                                        [% END %]
+                                                        <div class="hint">Non-patron guarantor surname</div>
+                                                    </li>
+                                                [% END # /UNLESS nocontactname %]
+
+                                                [% UNLESS nocontactfirstname %]
+                                                    <li>
+                                                        [% IF ( mandatorycontactfirstname ) %]
+                                                            <label for="contactfirstname" class="required">
+                                                        [% ELSE %]
+                                                            <label for="contactfirstname">
+                                                        [% END %]
+                                                            Guarantor first name:
+                                                        </label>
+                                                        <input type="text" id="contactfirstname" name="contactfirstname" value="[% patron.contactfirstname | html %]" />
+                                                        [% IF ( mandatorycontactfirstname ) %]
+                                                            <span class="required">Required</span>
+                                                        [% END %]
+                                                        <div class="hint">Non-patron guarantor first name</div>
+                                                    </li>
+                                                [% END # /UNLESS noaltcontactfirstname %]
+
+                                                [% UNLESS norelationship %]
+                                                    [% IF possible_relationships %]
+                                                        <li>
+                                                            <label for="relationship">Relationship: </label>
+                                                            <select class="relationship" name="relationship">
+                                                                <option value=""></option>
+                                                                [% FOREACH pr IN possible_relationships.split('\|') %]
+                                                                    [% IF pr == relationship %]
+                                                                        <option value="[% pr | html %]" selected="selected">[% pr | html %]</option>
+                                                                    [% ELSE %]
+                                                                        <option value="[% pr | html %]">[% pr | html %]</option>
+                                                                    [% END %]
+                                                                [% END %]
+                                                            </select>
+                                                        </li>
+                                                    [% END #/IF possible_relationships %]
+                                                [% END # /UNLESS norelationship %]
+                                            </ol>
+                                        </fieldset> <!-- /#non_patron_guarantor -->
+                                    [% END # /UNLESS nocontactname && nocontactfirstname && norelationship %]
                                 [% END # /IF show_guarantor || guarantor  %]
 
                                 [% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
@@ -570,58 +629,6 @@ legend:hover {
                                     <fieldset class="rows" id="memberentry_contact">
                                         <legend id="contact_lgd">Contact</legend>
                                         <ol>
-                                            [% UNLESS nocontactname %]
-                                                <li>
-                                                    [% IF ( mandatorycontactname ) %]
-                                                        <label for="contactname" class="required">
-                                                    [% ELSE %]
-                                                        <label for="contactname">
-                                                    [% END %]
-                                                        Guarantor surname:
-                                                    </label>
-                                                    <input type="text" id="contactname" name="contactname" value="[% patron.contactname | html %]" />
-                                                    [% IF ( mandatorycontactname ) %]
-                                                        <span class="required">Required</span>
-                                                    [% END %]
-                                                    <div class="hint">Non-patron guarantor surname</div>
-                                                </li>
-                                            [% END # /UNLESS nocontactname %]
-
-                                            [% UNLESS nocontactfirstname %]
-                                                <li>
-                                                    [% IF ( mandatorycontactfirstname ) %]
-                                                        <label for="contactfirstname" class="required">
-                                                    [% ELSE %]
-                                                        <label for="contactfirstname">
-                                                    [% END %]
-                                                        Guarantor first name:
-                                                    </label>
-                                                    <input type="text" id="contactfirstname" name="contactfirstname" value="[% patron.contactfirstname | html %]" />
-                                                    [% IF ( mandatorycontactfirstname ) %]
-                                                        <span class="required">Required</span>
-                                                    [% END %]
-                                                    <div class="hint">Non-patron guarantor first name</div>
-                                                </li>
-                                            [% END # /UNLESS noaltcontactfirstname %]
-
-                                            [% UNLESS norelationship %]
-                                                [% IF possible_relationships %]
-                                                    <li>
-                                                        <label for="relationship">Relationship: </label>
-                                                        <select class="relationship" name="relationship">
-                                                            <option value=""></option>
-                                                            [% FOREACH pr IN possible_relationships.split('\|') %]
-                                                                [% IF pr == relationship %]
-                                                                    <option value="[% pr | html %]" selected="selected">[% pr | html %]</option>
-                                                                [% ELSE %]
-                                                                    <option value="[% pr | html %]">[% pr | html %]</option>
-                                                                [% END %]
-                                                            [% END %]
-                                                        </select>
-                                                    </li>
-                                                [% END #/IF possible_relationships %]
-                                            [% END # /UNLESS norelationship %]
-
                                             [% UNLESS nophone %]
                                                 <li>
                                                     [% IF ( mandatoryphone ) %]
-- 
2.11.0