From fb05b82e66d654a3eb5b626c9b99111ba7f81ffb Mon Sep 17 00:00:00 2001
From: Liquidsoul <liquidsoul@liquidsoul.fr>
Date: Wed, 17 Apr 2019 16:50:39 +0200
Subject: [PATCH] Use NotificationService to send poll creation mails

---
 create_classic_poll.php | 12 +++---------
 create_date_poll.php    | 20 ++++----------------
 2 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/create_classic_poll.php b/create_classic_poll.php
index 5c8be305..15966ad2 100644
--- a/create_classic_poll.php
+++ b/create_classic_poll.php
@@ -21,6 +21,7 @@ use Framadate\Form;
 use Framadate\Services\InputService;
 use Framadate\Services\LogService;
 use Framadate\Services\MailService;
+use Framadate\Services\NotificationService;
 use Framadate\Services\PollService;
 use Framadate\Services\PurgeService;
 use Framadate\Services\SessionService;
@@ -33,6 +34,7 @@ include_once __DIR__ . '/app/inc/init.php';
 $logService = new LogService();
 $pollService = new PollService($connect, $logService);
 $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']);
+$notificationService = new NotificationService($mailService, $smarty);
 $purgeService = new PurgeService($connect, $logService);
 $sessionService = new SessionService();
 
@@ -185,15 +187,7 @@ switch ($step) {
 
         // Send confirmation by mail if enabled
         if ($config['use_smtp'] === true && $mailService->isValidEmail($form->admin_mail)) {
-            $smarty->assign('poll_creator_name', Utils::htmlMailEscape($form->admin_name));
-            $smarty->assign('poll_name', Utils::htmlMailEscape($form->title));
-            $smarty->assign('poll_url', Utils::getUrlSondage($poll_id));
-            $message_participants = $smarty->fetch('mail/participants_forward_email.html.tpl');
-            $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_participants);
-
-            $smarty->assign('poll_admin_url', Utils::getUrlSondage($admin_poll_id, true));
-            $message_admin = $smarty->fetch('mail/creation_notification_email.html.tpl');
-            $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin);
+            $notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id);
         }
 
         // Clean Form data in $_SESSION
diff --git a/create_date_poll.php b/create_date_poll.php
index af3378ca..998653f1 100644
--- a/create_date_poll.php
+++ b/create_date_poll.php
@@ -21,6 +21,7 @@ use Framadate\Form;
 use Framadate\Services\InputService;
 use Framadate\Services\LogService;
 use Framadate\Services\MailService;
+use Framadate\Services\NotificationService;
 use Framadate\Services\PollService;
 use Framadate\Services\PurgeService;
 use Framadate\Services\SessionService;
@@ -33,6 +34,7 @@ include_once __DIR__ . '/app/inc/init.php';
 $logService = new LogService();
 $pollService = new PollService($connect, $logService);
 $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']);
+$notificationService = new NotificationService($mailService, $smarty);
 $purgeService = new PurgeService($connect, $logService);
 $inputService = new InputService();
 $sessionService = new SessionService();
@@ -223,22 +225,8 @@ switch ($step) {
         $admin_poll_id = $ids[1];
 
         // Send confirmation by mail if enabled
-        if ($config['use_smtp'] === true) {
-            $message = __('Mail', "This is the message to forward to the poll participants.");
-            $message .= '<br/><br/>';
-            $message .= Utils::htmlEscape($form->admin_name) . ' ' . __('Mail', 'has just created a poll called') . ' : "' . Utils::htmlEscape($form->title) . '".<br/>';
-            $message .= __('Mail', 'Thank you for participating in the poll at the following link') . ' :<br/><br/><a href="%1$s">%1$s</a>';
-
-            $message_admin = __('Mail', "This message should NOT be sent to the poll participants. You should keep it private. <br/><br/>You can modify your poll at the following link");
-            $message_admin .= ' :<br/><br/><a href="%1$s">%1$s</a>';
-
-            $message = sprintf($message, Utils::getUrlSondage($poll_id));
-            $message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true));
-
-            if ($mailService->isValidEmail($form->admin_mail)) {
-                $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message_admin);
-                $mailService->send($form->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $form->title, $message);
-            }
+        if ($config['use_smtp'] === true && $mailService->isValidEmail($form->admin_mail)) {
+            $notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id);
         }
 
         // Clean Form data in $_SESSION
-- 
GitLab