From a4ddc514d3e428aa9a2cefe405a7ab59c25267a1 Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 12 Oct 2024 00:22:44 +0200 Subject: [PATCH] add message body to configuration --- app/Console/Commands/SendNotifications.php | 8 +++++--- .../Controllers/ConfigurationController.php | 9 +++++++-- resources/lang/en/cruds.php | 15 ++++++++++++++ resources/lang/fr/cruds.php | 15 ++++++++++++++ resources/views/config.blade.php | 20 ++++++++++++------- 5 files changed, 55 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendNotifications.php b/app/Console/Commands/SendNotifications.php index 19a39396..f8b8b049 100644 --- a/app/Console/Commands/SendNotifications.php +++ b/app/Console/Commands/SendNotifications.php @@ -66,7 +66,7 @@ public function handle() ->get(); if ($controls->count() > 0) { App::setlocale($user->language); - $txt = htmlentities(trans('cruds.notification.subject')) . '

'; + $txt = ''; foreach ($controls as $control) { // Date $txt .= ''; @@ -92,7 +92,7 @@ public function handle() $txt .= "
\n"; } - // send notification + // Create message $mail_from = config('deming.notification.mail-from'); $headers = [ 'MIME-Version: 1.0', @@ -101,7 +101,9 @@ public function handle() ]; $to_email = $user->email; $subject = config('deming.notification.mail-subject'); - $message = $txt; + + // Apply message model + $message = str_replace("%table%",$txt,config('deming.notification.mail-content')); // Send mail if (mail( diff --git a/app/Http/Controllers/ConfigurationController.php b/app/Http/Controllers/ConfigurationController.php index 31e67e0e..34439016 100644 --- a/app/Http/Controllers/ConfigurationController.php +++ b/app/Http/Controllers/ConfigurationController.php @@ -18,6 +18,7 @@ public function index() // Get configuration $mail_from = config('deming.notification.mail-from'); $mail_subject = config('deming.notification.mail-subject'); + $mail_content = config('deming.notification.mail-content'); $frequency = config('deming.notification.frequency'); $expire_delay = config('deming.notification.expire-delay'); $reminder = config('deming.notification.reminder'); @@ -25,7 +26,9 @@ public function index() // Return return view( 'config', - compact('mail_from', 'mail_subject', 'frequency', 'expire_delay', 'reminder') + compact( + 'mail_from', 'mail_subject', 'mail_content', + 'frequency', 'expire_delay', 'reminder') ); } @@ -39,6 +42,7 @@ public function save(Request $request) // read request $mail_from = request('mail_from'); $mail_subject = request('mail_subject'); + $mail_content = request('mail_content'); $frequency = request('frequency'); $expire_delay = request('expire_delay'); $reminder = request('reminder'); @@ -48,6 +52,7 @@ public function save(Request $request) // put in config file config(['deming.notification.mail-from' => $mail_from]); config(['deming.notification.mail-subject' => $mail_subject]); + config(['deming.notification.mail-content' => $mail_content]); config(['deming.notification.frequency' => $frequency]); config(['deming.notification.expire-delay' => $expire_delay]); @@ -89,7 +94,7 @@ public function save(Request $request) return view( 'config', - compact('mail_from', 'mail_subject', 'frequency', 'expire_delay', 'reminder') + compact('mail_from', 'mail_subject', 'mail_content', 'frequency', 'expire_delay', 'reminder') ) ->withErrors($msg); } diff --git a/resources/lang/en/cruds.php b/resources/lang/en/cruds.php index 7ae1603e..5ed58301 100644 --- a/resources/lang/en/cruds.php +++ b/resources/lang/en/cruds.php @@ -209,6 +209,21 @@ 'title_short' => 'Notifications', 'help' => 'This screen allows you to configure the notifications sent by email to users.', 'message_subject' => 'Message subject', + 'message_content' => 'Message content', + 'message_default_content' => ' + + + + + + +

Here is the list of measurement that will be due soon:

+%table% +

This is an automatically generated email

+

Best regards,

+

Deming

+ +', 'sent_from' => 'Sent from', 'to' => 'to', 'delay' => 'for controls that expire within', diff --git a/resources/lang/fr/cruds.php b/resources/lang/fr/cruds.php index d67e88f9..3a40fbf2 100644 --- a/resources/lang/fr/cruds.php +++ b/resources/lang/fr/cruds.php @@ -209,6 +209,21 @@ 'title_short' => 'Notifications', 'help' => 'Cet écran permet de configurer les notifications envoyées par mail aux utilisateurs.', 'message_subject' => 'Sujet du message', + 'message_content' => 'Contenu du message', + 'message_default_content' => ' + + + + + + +

Voici la liste des contrôles dû prochainement :

+%table% +

Ceci est un mail généré automatiquement.

+

Cordialement,

+

Deming

+ +', 'sent_from' => 'Envoyé depuis', 'to' => 'à', 'delay' => 'Pour les contrôles qui arrivent à échéance dans', diff --git a/resources/views/config.blade.php b/resources/views/config.blade.php index f1a22b05..663b354f 100644 --- a/resources/views/config.blade.php +++ b/resources/views/config.blade.php @@ -34,22 +34,30 @@
- {{ trans("cruds.config.notifications.message_subject") }} + {{ trans("cruds.config.notifications.sent_from") }}
- +
- {{ trans("cruds.config.notifications.sent_from") }} + {{ trans("cruds.config.notifications.message_subject") }}
- +
+
+
+ {{ trans("cruds.config.notifications.message_content") }} +
+
+ +
+
@@ -78,7 +86,7 @@
- +
@@ -110,5 +118,3 @@
@endsection - -