From cb9c3a13644b00c021a2907e9b3554225e8a6415 Mon Sep 17 00:00:00 2001
From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Date: Thu, 3 Oct 2019 15:13:27 +0100
Subject: [PATCH] Bug 23681: Allow for selection of restriction type

This patch displays a restriction type select box (when appropriate)
when adding manual patron restrictions

Signed-off-by: Benjamin Veasey <B.T.Veasey@lboro.ac.uk>
Sponsored-by: Loughborough University
---
 .../intranet-tmpl/prog/en/includes/borrower_debarments.inc    | 11 +++++++++++
 .../intranet-tmpl/prog/en/modules/members/memberentrygen.tt   | 10 ++++++++++
 members/memberentry.pl                                        |  4 ++--
 members/mod_debarment.pl                                      |  3 ++-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
index 9dde40aa7d..1edec9ca19 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
@@ -1,4 +1,5 @@
 [% USE raw %]
+[% USE Koha %]
 <div id="reldebarments">
     [% IF ( not debarments.defined || debarments.size < 1 ) %]
         <p>Patron is currently unrestricted.</p>
@@ -51,6 +52,16 @@
             <fieldset class="rows" id="manual_restriction_form">
                 <legend>Add manual restriction</legend>
                 <ol>
+                    [% IF Koha.Preference('PatronRestrictionTypes') %]
+                    <li>
+                        <label for="debarred_type">Type:</label>
+                        <select name="debarred_type">
+                            [% FOREACH code IN restriction_types.keys %]
+                                <option value="[% code | html %]">[% restriction_types.$code.display_text | html %]</option>
+                            [% END %]
+                        </select>
+                    </li>
+                    [% END %]
                     <li><label for="rcomment">Comment:</label> <input type="text" id="rcomment" name="comment" /></li>
                     <li><label for="rexpiration">Expiration:</label> <input name="expiration" id="rexpiration" size="10" value="" class="datepicker" type="text" />
                         <a href="#" class="clear-date" id="clear-date-rexpiration">Clear date</a></li>
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 c650cd2ef2..6f8234289e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -1044,6 +1044,16 @@
                         <input type="hidden" id="add_debarment" name="add_debarment" value="0" />
                         <legend id="manual_restriction_lgd">Add manual restriction</legend>
                         <ol>
+                            [% IF Koha.Preference('PatronRestrictionTypes') %]
+                            <li>
+                                <label for="debarred_type">Type:</label>
+                                <select name="debarred_type">
+                                    [% FOREACH code IN restriction_types.keys %]
+                                        <option value="[% code | html %]">[% restriction_types.$code.display_text | html %]</option>
+                                    [% END %]
+                                </select>
+                            </li>
+                            [% END %]
                             <li><label for="debarred_comment">Comment: </label><input type="text" id="debarred_comment" name="debarred_comment" onchange="$('#add_debarment').val(1);" /></li>
                             <li><label for="debarred_expiration">Expiration: </label><input name="debarred_expiration" id="debarred_expiration" size="10" value="" class="datepicker" onchange="$('#add_debarment').val(1);" type="text" />
                                     <a href='javascript:void(0)' onclick="$('#debarred_expiration').val('');">Clear date</a></li>
diff --git a/members/memberentry.pl b/members/memberentry.pl
index 3415bc50d9..16d895f17a 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -139,7 +139,7 @@ if ( $input->param('add_debarment') ) {
     AddDebarment(
         {
             borrowernumber => $borrowernumber,
-            type           => 'MANUAL',
+            type           => scalar $input->param('debarred_type') // 'MANUAL',
             comment        => scalar $input->param('debarred_comment'),
             expiration     => $expiration,
         }
@@ -236,7 +236,7 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' )
         qr/^\d+-DAYS/,
         qr/^patron_attr_/,
         qr/^csrf_token$/,
-        qr/^add_debarment$/, qr/^debarred_expiration$/, qr/^remove_debarment$/, # We already dealt with debarments previously
+        qr/^add_debarment$/, qr/^debarred_expiration$/, qr/^debarred_type$/, qr/^remove_debarment$/, # We already dealt with debarments previously
         qr/^housebound_chooser$/, qr/^housebound_deliverer$/,
         qr/^select_city$/,
         qr/^new_guarantor_/,
diff --git a/members/mod_debarment.pl b/members/mod_debarment.pl
index bc155e54a3..03889351d5 100755
--- a/members/mod_debarment.pl
+++ b/members/mod_debarment.pl
@@ -44,6 +44,7 @@ if ( $action eq 'del' ) {
     DelDebarment( scalar $cgi->param('borrower_debarment_id') );
 } elsif ( $action eq 'add' ) {
     my $expiration = $cgi->param('expiration');
+    my $type = $cgi->param('debarred_type') // 'MANUAL';
     if ($expiration) {
         $expiration = dt_from_string($expiration);
         $expiration = $expiration->ymd();
@@ -51,7 +52,7 @@ if ( $action eq 'del' ) {
 
     AddDebarment(
         {   borrowernumber => $borrowernumber,
-            type           => 'MANUAL',
+            type           => $type,
             comment        => scalar $cgi->param('comment'),
             expiration     => $expiration,
         }
-- 
2.11.0