Send mail to admin when update/delete a poll
This commit is contained in:
parent
b717bee765
commit
c9c45a2d24
@ -16,15 +16,22 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
use Framadate\Services\PollService;
|
use Framadate\Editable;
|
||||||
|
use Framadate\Message;
|
||||||
use Framadate\Services\AdminPollService;
|
use Framadate\Services\AdminPollService;
|
||||||
use Framadate\Services\InputService;
|
use Framadate\Services\InputService;
|
||||||
use Framadate\Services\LogService;
|
use Framadate\Services\LogService;
|
||||||
use Framadate\Message;
|
use Framadate\Services\MailService;
|
||||||
use Framadate\Editable;
|
use Framadate\Services\PollService;
|
||||||
|
use Framadate\Utils;
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
|
/* Constants */
|
||||||
|
/* --------- */
|
||||||
|
const UPDATE_POLL = 1;
|
||||||
|
const DELETED_POLL = 2;
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
/* --------- */
|
/* --------- */
|
||||||
|
|
||||||
@ -41,6 +48,41 @@ $logService = new LogService();
|
|||||||
$pollService = new PollService($connect, $logService);
|
$pollService = new PollService($connect, $logService);
|
||||||
$adminPollService = new AdminPollService($connect, $pollService, $logService);
|
$adminPollService = new AdminPollService($connect, $pollService, $logService);
|
||||||
$inputService = new InputService();
|
$inputService = new InputService();
|
||||||
|
$mailService = new MailService($config['use_smtp']);
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
/*-----------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a notification to the poll admin to notify him about an update.
|
||||||
|
*
|
||||||
|
* @param stdClass $poll The poll
|
||||||
|
* @param MailService $mailService The mail service
|
||||||
|
* @param int $type cf: Constants on the top of this page
|
||||||
|
*/
|
||||||
|
function sendUpdateNotification($poll, $mailService, $type) {
|
||||||
|
if (!isset($_SESSION['mail_sent'])) {
|
||||||
|
$_SESSION['mail_sent'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($poll->receiveNewVotes) {
|
||||||
|
|
||||||
|
$subject = '[' . NOMAPPLICATION . '] ' . __('Mail', 'Notification of poll') . ' : ' . $poll->title;
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
switch ($type) {
|
||||||
|
case UPDATE_POLL:
|
||||||
|
$message = __f('Mail', 'Someone just change your poll available at the following link %s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n";
|
||||||
|
break;
|
||||||
|
case DELETED_POLL:
|
||||||
|
$message = __f('Mail', 'Someone just delete your poll %s.', Utils::htmlEscape($poll->title)) . "\n\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$messageTypeKey = $type . '-' . $poll->id;
|
||||||
|
$mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* PAGE */
|
/* PAGE */
|
||||||
/* ---- */
|
/* ---- */
|
||||||
@ -133,6 +175,7 @@ if (isset($_POST['update_poll_info'])) {
|
|||||||
// Update poll in database
|
// Update poll in database
|
||||||
if ($updated && $adminPollService->updatePoll($poll)) {
|
if ($updated && $adminPollService->updatePoll($poll)) {
|
||||||
$message = new Message('success', __('adminstuds', 'Poll saved'));
|
$message = new Message('success', __('adminstuds', 'Poll saved'));
|
||||||
|
sendUpdateNotification($poll, $mailService, UPDATE_POLL);
|
||||||
} else {
|
} else {
|
||||||
$message = new Message('danger', __('Error', 'Failed to save poll'));
|
$message = new Message('danger', __('Error', 'Failed to save poll'));
|
||||||
$poll = $pollService->findById($poll_id);
|
$poll = $pollService->findById($poll_id);
|
||||||
@ -297,6 +340,7 @@ if (isset($_POST['delete_poll'])) {
|
|||||||
if (isset($_POST['confirm_delete_poll'])) {
|
if (isset($_POST['confirm_delete_poll'])) {
|
||||||
if ($adminPollService->deleteEntirePoll($poll_id)) {
|
if ($adminPollService->deleteEntirePoll($poll_id)) {
|
||||||
$message = new Message('success', __('adminstuds', 'Poll fully deleted'));
|
$message = new Message('success', __('adminstuds', 'Poll fully deleted'));
|
||||||
|
sendUpdateNotification($poll, $mailService, DELETED_POLL);
|
||||||
} else {
|
} else {
|
||||||
$message = new Message('danger', __('Error', 'Failed to delete the poll'));
|
$message = new Message('danger', __('Error', 'Failed to delete the poll'));
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,6 @@
|
|||||||
"Remove the comments": "Entfernen Sie die Kommentare",
|
"Remove the comments": "Entfernen Sie die Kommentare",
|
||||||
"Comment deleted": "Kommentar gelöscht",
|
"Comment deleted": "Kommentar gelöscht",
|
||||||
"All comments deleted": "Alle Kommentare gelöscht",
|
"All comments deleted": "Alle Kommentare gelöscht",
|
||||||
"The poll has been deleted": "Die Umfrage wurde gelöscht",
|
|
||||||
"Keep votes": "Halten Stimmen",
|
"Keep votes": "Halten Stimmen",
|
||||||
"Keep comments": "Halten Sie Kommentare",
|
"Keep comments": "Halten Sie Kommentare",
|
||||||
"Keep this poll": "Halten Sie diese Umfrage"
|
"Keep this poll": "Halten Sie diese Umfrage"
|
||||||
@ -289,9 +288,12 @@
|
|||||||
},
|
},
|
||||||
"Mail": {
|
"Mail": {
|
||||||
"Poll's participation": "Beteiligung an der Umfrage",
|
"Poll's participation": "Beteiligung an der Umfrage",
|
||||||
|
"Notification of poll": "Mitteilung bezüglich der Umfrage",
|
||||||
"filled a vote.\nYou can find your poll at the link": "füllte eine Stimme.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
"filled a vote.\nYou can find your poll at the link": "füllte eine Stimme.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
||||||
"updated a vote.\nYou can find your poll at the link": "eine Abstimmung regelmäßig aktualisiert.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
"updated a vote.\nYou can find your poll at the link": "eine Abstimmung regelmäßig aktualisiert.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
||||||
"wrote a comment.\nYou can find your poll at the link": "hat einen Kommentar.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
"wrote a comment.\nYou can find your poll at the link": "hat einen Kommentar.<br/>Sie können Ihre Umfrage unter dem Link zu finden",
|
||||||
|
"Someone just change your poll available at the following link %s.": "Jemand ändern Sie einfach Ihre Umfrage finden Sie unter dem folgenden Link <a href=\"%1$s\">%1$s</a>.",
|
||||||
|
"Someone just delete your poll %s.": "Jemand hat gerade Ihre Umfrage löschen \"%s\".",
|
||||||
"Thanks for your trust.": "Danke für Ihr Vertrauen.",
|
"Thanks for your trust.": "Danke für Ihr Vertrauen.",
|
||||||
"FOOTER": "",
|
"FOOTER": "",
|
||||||
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATOR] Neue Einstellungen für Ihre Umfrage ",
|
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATOR] Neue Einstellungen für Ihre Umfrage ",
|
||||||
|
@ -189,7 +189,6 @@
|
|||||||
"All comments deleted": "All comments deleted",
|
"All comments deleted": "All comments deleted",
|
||||||
"Keep the comments": "Keep the comments",
|
"Keep the comments": "Keep the comments",
|
||||||
"Remove the comments": "Remove the comments",
|
"Remove the comments": "Remove the comments",
|
||||||
"The poll has been deleted": "The poll has been deleted",
|
|
||||||
"Keep votes": "Keep votes",
|
"Keep votes": "Keep votes",
|
||||||
"Keep comments": "Keep comments",
|
"Keep comments": "Keep comments",
|
||||||
"Keep this poll": "Keep this poll"
|
"Keep this poll": "Keep this poll"
|
||||||
@ -289,9 +288,12 @@
|
|||||||
},
|
},
|
||||||
"Mail" : {
|
"Mail" : {
|
||||||
"Poll's participation": "Poll's participation",
|
"Poll's participation": "Poll's participation",
|
||||||
|
"Notification of poll": "Notification of poll",
|
||||||
"filled a vote.\nYou can find your poll at the link": "filled a vote.<br/>You can find your poll at the link",
|
"filled a vote.\nYou can find your poll at the link": "filled a vote.<br/>You can find your poll at the link",
|
||||||
"updated a vote.\nYou can find your poll at the link": "updated a vote.<br/>You can find your poll at the link",
|
"updated a vote.\nYou can find your poll at the link": "updated a vote.<br/>You can find your poll at the link",
|
||||||
"wrote a comment.\nYou can find your poll at the link": "wrote a comment.<br/>You can find your poll at the link",
|
"wrote a comment.\nYou can find your poll at the link": "wrote a comment.<br/>You can find your poll at the link",
|
||||||
|
"Someone just change your poll available at the following link %s.": "Someone just change your poll available at the following link <a href=\"%1$s\">%1$s</a>.",
|
||||||
|
"Someone just delete your poll %s.": "Someone just delete your poll \"%s\".",
|
||||||
"Thanks for your trust.": "Thanks for your trust.",
|
"Thanks for your trust.": "Thanks for your trust.",
|
||||||
"FOOTER": "",
|
"FOOTER": "",
|
||||||
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATOR] New settings for your poll",
|
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATOR] New settings for your poll",
|
||||||
|
@ -189,7 +189,6 @@
|
|||||||
"Remove the comments": "ES_Supprimer les commentaires",
|
"Remove the comments": "ES_Supprimer les commentaires",
|
||||||
"Comment deleted": "ES_Commentaire supprimé",
|
"Comment deleted": "ES_Commentaire supprimé",
|
||||||
"All comments deleted": "ES_Tous les commentaires ont été supprimés",
|
"All comments deleted": "ES_Tous les commentaires ont été supprimés",
|
||||||
"The poll has been deleted": "ES_Le sondage a été supprimé",
|
|
||||||
"Keep votes": "ES_Garder les votes",
|
"Keep votes": "ES_Garder les votes",
|
||||||
"Keep comments": "ES_Garder les commentaires",
|
"Keep comments": "ES_Garder les commentaires",
|
||||||
"Keep this poll": "Dejar este encuesta!"
|
"Keep this poll": "Dejar este encuesta!"
|
||||||
@ -288,10 +287,13 @@
|
|||||||
"Polls sent": "ES_Sondages envoyés"
|
"Polls sent": "ES_Sondages envoyés"
|
||||||
},
|
},
|
||||||
"Mail": {
|
"Mail": {
|
||||||
"Poll's participation": "ES_Participation au sondage",
|
"Poll's participation": "Participación Encuesta",
|
||||||
|
"Notification of poll": "Notificación de la encuesta",
|
||||||
"filled a vote.\nYou can find your poll at the link": "ES_vient de voter.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"filled a vote.\nYou can find your poll at the link": "ES_vient de voter.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"updated a vote.\nYou can find your poll at the link": "ES_vient de mettre à jour un vote.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"updated a vote.\nYou can find your poll at the link": "ES_vient de mettre à jour un vote.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"wrote a comment.\nYou can find your poll at the link": "ES_vient de rédiger un commentaire.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"wrote a comment.\nYou can find your poll at the link": "ES_vient de rédiger un commentaire.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
|
"Someone just change your poll available at the following link %s.": "Alguien acaba de cambiar su encuesta disponible en el siguiente enlace <a href=\"%1$s\">%1$s</a>.",
|
||||||
|
"Someone just delete your poll %s.": "Alguien acaba de borrar tu encuesta \"%s\".",
|
||||||
"Thanks for your trust.": "ES_Merci de votre confiance.",
|
"Thanks for your trust.": "ES_Merci de votre confiance.",
|
||||||
"FOOTER": "",
|
"FOOTER": "",
|
||||||
"[ADMINISTRATOR] New settings for your poll": "ES_[ADMINISTRATEUR] Changement de configuration du sondage",
|
"[ADMINISTRATOR] New settings for your poll": "ES_[ADMINISTRATEUR] Changement de configuration du sondage",
|
||||||
@ -306,8 +308,8 @@
|
|||||||
"Error": {
|
"Error": {
|
||||||
"Error!": "Error!",
|
"Error!": "Error!",
|
||||||
"Enter a title": "Introducza un título",
|
"Enter a title": "Introducza un título",
|
||||||
"Something is going wrong...": "ES_Quelque chose ne va pas...",
|
"Something is going wrong...": "Algo va mal...",
|
||||||
"Something is wrong with the format": "Something is wrong with the format",
|
"Something is wrong with the format": "Algo está mal con el formato",
|
||||||
"Enter an email address": "Introduzca una dirección electrónica",
|
"Enter an email address": "Introduzca una dirección electrónica",
|
||||||
"The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.": "ES_L'adresse saisie n'est pas correcte ! Il faut une adresse électronique valide (par exemple r.stallman@outlock.com) pour recevoir le lien vers le sondage.",
|
"The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.": "ES_L'adresse saisie n'est pas correcte ! Il faut une adresse électronique valide (par exemple r.stallman@outlock.com) pour recevoir le lien vers le sondage.",
|
||||||
"No polls found": "ES_Aucun sondage n'a été trouvé",
|
"No polls found": "ES_Aucun sondage n'a été trouvé",
|
||||||
|
@ -189,7 +189,6 @@
|
|||||||
"Remove the comments": "Supprimer les commentaires",
|
"Remove the comments": "Supprimer les commentaires",
|
||||||
"Comment deleted": "Commentaire supprimé",
|
"Comment deleted": "Commentaire supprimé",
|
||||||
"All comments deleted": "Tous les commentaires ont été supprimés",
|
"All comments deleted": "Tous les commentaires ont été supprimés",
|
||||||
"The poll has been deleted": "Le sondage a été supprimé",
|
|
||||||
"Keep votes": "Garder les votes",
|
"Keep votes": "Garder les votes",
|
||||||
"Keep comments": "Garder les commentaires",
|
"Keep comments": "Garder les commentaires",
|
||||||
"Keep this poll": "Garder ce sondage"
|
"Keep this poll": "Garder ce sondage"
|
||||||
@ -289,9 +288,12 @@
|
|||||||
},
|
},
|
||||||
"Mail": {
|
"Mail": {
|
||||||
"Poll's participation": "Participation au sondage",
|
"Poll's participation": "Participation au sondage",
|
||||||
|
"Notification of poll": "Notification d'un sondage",
|
||||||
"filled a vote.\nYou can find your poll at the link": "vient de voter.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"filled a vote.\nYou can find your poll at the link": "vient de voter.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"updated a vote.\nYou can find your poll at the link": "vient de mettre à jour un vote.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"updated a vote.\nYou can find your poll at the link": "vient de mettre à jour un vote.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"wrote a comment.\nYou can find your poll at the link": "vient de rédiger un commentaire.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
"wrote a comment.\nYou can find your poll at the link": "vient de rédiger un commentaire.<br/>Vous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
|
"Someone just change your poll available at the following link %s.": "Quelqu'un vient de modifier votre sondage accessible au lien suivant <a href=\"%1$s\">%1$s</a>.",
|
||||||
|
"Someone just delete your poll %s.": "Quelqu'un vient de supprimer votre sondage \"%s\".",
|
||||||
"Thanks for your trust.": "Merci de votre confiance.",
|
"Thanks for your trust.": "Merci de votre confiance.",
|
||||||
"FOOTER": "« La route est longue, mais la voie est libre… »<br/>Framasoft ne vit que par vos dons (déductibles des impôts).<br/>Merci d'avance pour votre soutien http://soutenir.framasoft.org.",
|
"FOOTER": "« La route est longue, mais la voie est libre… »<br/>Framasoft ne vit que par vos dons (déductibles des impôts).<br/>Merci d'avance pour votre soutien http://soutenir.framasoft.org.",
|
||||||
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATEUR] Changement de configuration du sondage",
|
"[ADMINISTRATOR] New settings for your poll": "[ADMINISTRATEUR] Changement de configuration du sondage",
|
||||||
|
@ -189,7 +189,6 @@
|
|||||||
"Remove the comments": "Eliminare i commenti",
|
"Remove the comments": "Eliminare i commenti",
|
||||||
"Comment deleted": "Commento rimosso",
|
"Comment deleted": "Commento rimosso",
|
||||||
"All comments deleted": "Tutti i commenti sono stati cancellati",
|
"All comments deleted": "Tutti i commenti sono stati cancellati",
|
||||||
"The poll has been deleted": "Il sondaggio è stato eliminato",
|
|
||||||
"Keep votes": "Tenere voti",
|
"Keep votes": "Tenere voti",
|
||||||
"Keep comments": "Tenere commenti",
|
"Keep comments": "Tenere commenti",
|
||||||
"Keep this poll": "Mantengo questo sondaggio !"
|
"Keep this poll": "Mantengo questo sondaggio !"
|
||||||
@ -289,9 +288,12 @@
|
|||||||
},
|
},
|
||||||
"Mail": {
|
"Mail": {
|
||||||
"Poll's participation": "Partecipazione al sondaggio",
|
"Poll's participation": "Partecipazione al sondaggio",
|
||||||
|
"Notification of poll": "Notifica di sondaggio",
|
||||||
"filled a vote.\nYou can find your poll at the link": "IT_vient de voter.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
"filled a vote.\nYou can find your poll at the link": "IT_vient de voter.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"updated a vote.\nYou can find your poll at the link": "IT_vient de mettre à jour un vote.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
"updated a vote.\nYou can find your poll at the link": "IT_vient de mettre à jour un vote.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
"wrote a comment.\nYou can find your poll at the link": "IT_vient de rédiger un commentaire.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
"wrote a comment.\nYou can find your poll at the link": "IT_vient de rédiger un commentaire.\nVous pouvez retrouver votre sondage avec le lien suivant",
|
||||||
|
"Someone just change your poll available at the following link %s.": "Qualcuno basta cambiare il vostro sondaggio disponibile al seguente link <a href=\"%1$s\">%1$s</a>.",
|
||||||
|
"Someone just delete your poll %s.": "Qualcuno ha appena cancellare il tuo sondaggio \"%s\".",
|
||||||
"Thanks for your trust.": "Grazie per la vostra fiducia.",
|
"Thanks for your trust.": "Grazie per la vostra fiducia.",
|
||||||
"FOOTER": "IT_« La route est longue, mais la voie est libre… »\nFramasoft ne vit que par vos dons (déductibles des impôts).\nMerci d'avance pour votre soutien http://soutenir.framasoft.org.",
|
"FOOTER": "IT_« La route est longue, mais la voie est libre… »\nFramasoft ne vit que par vos dons (déductibles des impôts).\nMerci d'avance pour votre soutien http://soutenir.framasoft.org.",
|
||||||
"[ADMINISTRATOR] New settings for your poll": "[AMMINISTRATORE] Modifica di configurazione del sondaggio",
|
"[ADMINISTRATOR] New settings for your poll": "[AMMINISTRATORE] Modifica di configurazione del sondaggio",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{block name=main}
|
{block name=main}
|
||||||
<div class="alert alert-success text-center">
|
<div class="alert alert-success text-center">
|
||||||
<h2>{__('adminstuds', 'The poll has been deleted')}</h2>
|
<h2>{$message}</h2>
|
||||||
<p>{__('Generic', 'Back to the homepage of')} <a href="{$SERVER_URL|html}">{$APPLICATION_NAME|html}</a></p>
|
<p>{__('Generic', 'Back to the homepage of')} <a href="{$SERVER_URL|html}">{$APPLICATION_NAME|html}</a></p>
|
||||||
</div>
|
</div>
|
||||||
{/block}
|
{/block}
|
Loading…
Reference in New Issue
Block a user