From 5262843e63ae734c2df3ae54491cb816afe20cc0 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Sun, 5 Sep 2021 14:49:52 -0400
Subject: [PATCH] Add redirect URL parameter to contact batch

- This allows redirection to the correct contact tab after a batch action
---
 src/Module/Contact.php                          | 2 +-
 view/templates/contacts-template.tpl            | 1 +
 view/theme/frio/templates/contacts-template.tpl | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Module/Contact.php b/src/Module/Contact.php
index 4233be4625..bfed6495ae 100644
--- a/src/Module/Contact.php
+++ b/src/Module/Contact.php
@@ -88,7 +88,7 @@ class Contact extends BaseModule
 			info(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions));
 		}
 
-		DI::baseUrl()->redirect('contact');
+		DI::baseUrl()->redirect($_POST['redirect_url'] ?? 'contact');
 	}
 
 	public static function post(array $parameters = [])
diff --git a/view/templates/contacts-template.tpl b/view/templates/contacts-template.tpl
index 1631640a0a..9253b862aa 100644
--- a/view/templates/contacts-template.tpl
+++ b/view/templates/contacts-template.tpl
@@ -15,6 +15,7 @@
 {{$tabs nofilter}}
 
 <form action="{{$baseurl}}/contact/batch/" method="POST">
+	<input type="hidden" name="redirect_url" value="{{$cmd}}"/>
 {{foreach $contacts as $contact}}
 	{{include file="contact_template.tpl"}}
 {{/foreach}}
diff --git a/view/theme/frio/templates/contacts-template.tpl b/view/theme/frio/templates/contacts-template.tpl
index ad8a267927..c6a9865a01 100644
--- a/view/theme/frio/templates/contacts-template.tpl
+++ b/view/theme/frio/templates/contacts-template.tpl
@@ -29,6 +29,7 @@
 
 	{{* we need the form container to make batch actions work *}}
 	<form name="batch_actions_submit" action="{{$baseurl}}/contact/batch/" method="POST">
+		<input type="hidden" name="redirect_url" value="{{$cmd}}"/>
 
 		{{* we put here a hidden input element. This is needed to transmit the batch actions with javascript*}}
 		<input type="hidden" class="batch-action no-input fakelist" name="batch_submit" value="{{$l}}">
-- 
2.39.5