diff --git a/action/add_comment.php b/action/add_comment.php index 71b9ca3a9e5d0e03d3f816483879f9c69dbcec16..11c9152d36b42ea2d6c6ffdb716cdeb73cc27c43 100644 --- a/action/add_comment.php +++ b/action/add_comment.php @@ -43,7 +43,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $securityService = new SecurityService(); /* PAGE */ diff --git a/action/send_edit_link_by_email_action.php b/action/send_edit_link_by_email_action.php index 500fab7a72db0ba71b6f851a2ae371c7631c5708..8bf42328155d5381250740d578f4a23de0ddfefe 100644 --- a/action/send_edit_link_by_email_action.php +++ b/action/send_edit_link_by_email_action.php @@ -20,6 +20,7 @@ use Framadate\Message; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; use Framadate\Services\SessionService; use Framadate\Utils; @@ -29,6 +30,7 @@ include_once __DIR__ . '/../app/inc/init.php'; $logService = new LogService(); $sessionService = new SessionService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); +$notificationService = new NotificationService($mailService, $smarty); $pollService = new PollService($connect, $logService); $result = false; @@ -70,16 +72,7 @@ if (is_null($message)) { } if (is_null($message)) { - $url = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId); - - $smarty->assign('poll', $poll); - $smarty->assign('poll_id', $poll_id); - $smarty->assign('editedVoteUniqueId', $editedVoteUniqueId); - $body = $smarty->fetch('mail/remember_edit_link.tpl'); - - $subject = '[' . NOMAPPLICATION . '][' . __('EditLink', 'REMINDER') . '] ' . __f('EditLink', 'Edit link for poll "%s"', $poll->title); - - $mailService->send($email, $subject, $body); + $notificationService->sendEditedVoteNotification($email, $poll, $poll_id, $editedVoteUniqueId); $sessionService->remove("Common", SESSION_EDIT_LINK_TOKEN); $sessionService->set("Common", SESSION_EDIT_LINK_TIME, time()); diff --git a/adminstuds.php b/adminstuds.php index 26a2e2825d8086ba6d5d41df73a680dbe237d9bc..93e7b418bfe259de7941d1d57b79f36c6ee2c73e 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -51,7 +51,7 @@ $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $sessionService = new SessionService(); /* PAGE */ diff --git a/app/classes/Framadate/Services/NotificationService.php b/app/classes/Framadate/Services/NotificationService.php index 615629c3dcb02af643ce902bc9040d37f45a8c7a..e0ae5906c8c29236bc1739e13222cc9ed021038c 100644 --- a/app/classes/Framadate/Services/NotificationService.php +++ b/app/classes/Framadate/Services/NotificationService.php @@ -15,9 +15,11 @@ class NotificationService { const DELETED_POLL = 11; private $mailService; + private $smarty; - function __construct(MailService $mailService) { + function __construct(MailService $mailService, \Smarty $smarty) { $this->mailService = $mailService; + $this->smarty = $smarty; } /** @@ -83,4 +85,36 @@ class NotificationService { { return $type >= self::UPDATE_POLL; } + + function sendPollCreationMails($creator_mail, $creator_name, $poll_name, $poll_id, $admin_poll_id) { + $this->smarty->assign('poll_creator_name', Utils::htmlMailEscape($creator_name)); + $this->smarty->assign('poll_name', Utils::htmlMailEscape($poll_name)); + $this->smarty->assign('poll_url', Utils::getUrlSondage($poll_id)); + $message_participants = $this->smarty->fetch('mail/participants_forward_email.html.tpl'); + $this->mailService->send($creator_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Participant link') . '] ' . __('Generic', 'Poll') . ': ' . $poll_name, $message_participants); + + $this->smarty->assign('poll_admin_url', Utils::getUrlSondage($admin_poll_id, true)); + $message_admin = $this->smarty->fetch('mail/creation_notification_email.html.tpl'); + $this->mailService->send($creator_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Message for the author') . '] ' . __('Generic', 'Poll') . ': ' . $poll_name, $message_admin); + } + + function sendEditedVoteNotification($email, &$poll, $poll_id, $edited_vote_id) { + $url = Utils::getUrlSondage($poll_id, false, $edited_vote_id); + + $this->smarty->assign('poll', $poll); + $this->smarty->assign('poll_id', $poll_id); + $this->smarty->assign('editedVoteUniqueId', $edited_vote_id); + $body = $this->smarty->fetch('mail/remember_edit_link.tpl'); + + $subject = '[' . NOMAPPLICATION . '][' . __('EditLink', 'REMINDER') . '] ' . __f('EditLink', 'Edit link for poll "%s"', $poll->title); + + $this->mailService->send($email, $subject, $body); + } + + function sendFindPollsByMailNotification($mail, &$polls) { + $this->smarty->assign('polls', $polls); + $body = $this->smarty->fetch('mail/find_polls.tpl'); + + $this->mailService->send($mail, __('FindPolls', 'List of your polls') . ' - ' . NOMAPPLICATION, $body, 'SEND_POLLS'); + } } diff --git a/create_classic_poll.php b/create_classic_poll.php index 2950aa9a99811440bae6cfe704b7f574ef80462a..15966ad28ca52259e30dc16c3f72bc4381f4acb3 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(); @@ -184,19 +186,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::htmlMailEscape($form->admin_name) . ' ' . __('Mail', 'has just created a poll called') . ' : "' . Utils::htmlMailEscape($form->title) . '".<br/>'; - $message .= sprintf(__('Mail', 'Thank you for participating in the poll at the following link') . ' :<br/><br/><a href="%1$s">%1$s</a>', Utils::getUrlSondage($poll_id)); - - $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 .= sprintf(' :<br/><br/><a href="%1$s">%1$s</a>', 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 diff --git a/create_date_poll.php b/create_date_poll.php index af3378ca28f18ee24d41b710cd3012413b5aad67..998653f1d4a8b529418e52005098d0ce9d426a26 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 diff --git a/find_polls.php b/find_polls.php index 7fda3b347f9a58005297b2b3f31c3da5114fa540..0a1b3f947031f7ad44221eb20f0a9345216bf889 100644 --- a/find_polls.php +++ b/find_polls.php @@ -20,6 +20,7 @@ use Framadate\Message; use Framadate\Services\LogService; use Framadate\Services\MailService; +use Framadate\Services\NotificationService; use Framadate\Services\PollService; include_once __DIR__ . '/app/inc/init.php'; @@ -29,6 +30,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); /* PAGE */ /* ---- */ @@ -40,10 +42,7 @@ if (!empty($_POST['mail'])) { $polls = $pollService->findAllByAdminMail($mail); if (count($polls) > 0) { - $smarty->assign('polls', $polls); - $body = $smarty->fetch('mail/find_polls.tpl'); - - $mailService->send($mail, __('FindPolls', 'List of your polls') . ' - ' . NOMAPPLICATION, $body, 'SEND_POLLS'); + $notificationService->sendFindPollsByMailNotification($mail, $polls); $message = new Message('success', __('FindPolls', 'Polls sent')); } else { $message = new Message('warning', __('Error', 'No polls found')); diff --git a/studs.php b/studs.php index 5dec7c90e994a2e8e37f552837f2f79595acb421..2d30882058803abc37db0a6cb5deed028f99221f 100644 --- a/studs.php +++ b/studs.php @@ -59,7 +59,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); -$notificationService = new NotificationService($mailService); +$notificationService = new NotificationService($mailService, $smarty); $securityService = new SecurityService(); $sessionService = new SessionService(); diff --git a/tpl/mail/creation_notification_email.html.tpl b/tpl/mail/creation_notification_email.html.tpl new file mode 100644 index 0000000000000000000000000000000000000000..3c46de4294269f7f294ee5f6da3d3e768b8c6d96 --- /dev/null +++ b/tpl/mail/creation_notification_email.html.tpl @@ -0,0 +1,4 @@ +{__('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")}: +<br/> +<br/> +<a href="{$poll_admin_url}">{$poll_admin_url}</a> diff --git a/tpl/mail/participants_forward_email.html.tpl b/tpl/mail/participants_forward_email.html.tpl new file mode 100644 index 0000000000000000000000000000000000000000..dc8c3cf9d9ac4dc2d2ee21c269eef9a4200837a5 --- /dev/null +++ b/tpl/mail/participants_forward_email.html.tpl @@ -0,0 +1 @@ +{__('Mail', "This is the message to forward to the poll participants.")}<br/><br/>{$poll_creator_name} {__('Mail', 'has just created a poll called')} {$poll_name}<br/>{__('Mail', 'Thank you for participating in the poll at the following link')}:<br/><br/><a href="{$poll_url}">{$poll_url}</a>