Form : envoi de mails

This commit is contained in:
fredtempez 2019-02-12 14:39:36 +01:00
parent b08238a664
commit 7aaf446893
3 changed files with 72 additions and 16 deletions

View File

@ -48,10 +48,20 @@ class form extends common {
self::TYPE_CHECKBOX => 'Case à cocher'
];
public static $listUsers = [
];
/**
* Configuration
*/
public function config() {
// Liste des utilisateurs
$userIdsFirstnames = helper::arrayCollumn($this->getData(['user']), 'firstname');
ksort($userIdsFirstnames);
self::$listUsers [] = '';
foreach($userIdsFirstnames as $userId => $userFirstname) {
self::$listUsers [] = $this->getData(['user', $userId, 'mail']);
}
// Soumission du formulaire
if($this->isPost()) {
// Configuration
@ -63,6 +73,8 @@ class form extends common {
'button' => $this->getInput('formConfigButton'),
'capcha' => $this->getInput('formConfigCapcha', helper::FILTER_BOOLEAN),
'group' => $this->getInput('formConfigGroup', helper::FILTER_INT),
'user' => self::$listUsers [$this->getInput('formConfigUser', helper::FILTER_INT)],
'mail' => $this->getInput('formConfigMail', helper::FILTER_MAIL),
'pageId' => $this->getInput('formConfigPageId', helper::FILTER_ID),
'subject' => $this->getInput('formConfigSubject')
]
@ -296,9 +308,13 @@ class form extends common {
$this->setData(['module', $this->getUrl(0), 'data', helper::increment(1, $this->getData(['module', $this->getUrl(0), 'data'])), $data]);
// Envoi du mail
$sent = true;
$singleuser = $this->getData(['module', $this->getUrl(0), 'config', 'user']);
$singlemail = $this->getData(['module', $this->getUrl(0), 'config', 'mail']);
if(
self::$inputNotices === []
AND $group = $this->getData(['module', $this->getUrl(0), 'config', 'group'])
OR $singleuser !== ''
OR $singlemail !== ''
) {
// Utilisateurs dans le groupe
$to = [];
@ -307,6 +323,15 @@ class form extends common {
$to[] = $user['mail'];
}
}
// Utilisateur désigné
if (!empty($singleuser)) {
$to[] = $singleuser;
}
// Mail désigné
if (!empty($singlemail)) {
$to[] = $singlemail;
}
if($to) {
// Sujet du mail
$subject = $this->getData(['module', $this->getUrl(0), 'config', 'subject']);

View File

@ -142,6 +142,8 @@ $("#formConfigMailOptionsToggle").on("change", function() {
$("#formConfigMailOptions").slideUp(function() {
$("#formConfigGroup").val("");
$("#formConfigSubject").val("");
$("#formConfigMail").val("");
$("#formConfigUser").val("");
});
}
}).trigger("change");

View File

@ -72,34 +72,63 @@
'label' => 'Texte du bouton de soumission',
'value' => $this->getData(['module', $this->getUrl(0), 'config', 'button'])
]); ?>
<?php echo template::checkbox('formConfigMailOptionsToggle', true, 'Envoyer par mail les données saisies aux utilisateurs d\'un groupe', [
'checked' => (bool) $this->getData(['module', $this->getUrl(0), 'config', 'group'])
]); ?>
<?php echo template::checkbox('formConfigMailOptionsToggle', true, 'Envoyer par mail les données saisies :', [
'checked' => (bool) $this->getData(['module', $this->getUrl(0), 'config', 'group']) ||
!empty($this->getData(['module', $this->getUrl(0), 'config', 'user'])) ||
!empty($this->getData(['module', $this->getUrl(0), 'config', 'mail'])),
'help' => 'Sélectionnez au moins un groupe, un utilisateur ou saississez un email'
]); ?>
<div id="formConfigMailOptions" class="displayNone">
<div class="row">
<div class="col6">
<?php echo template::select('formConfigGroup', self::$groupNews, [
'label' => 'Groupe',
'selected' => $this->getData(['module', $this->getUrl(0), 'config', 'group'])
]); ?>
</div>
<div class="col6">
<div class="col11 offset1">
<?php echo template::text('formConfigSubject', [
'help' => 'Laissez vide afin de conserver le texte par défaut.',
'label' => 'Sujet du mail',
'value' => $this->getData(['module', $this->getUrl(0), 'config', 'subject'])
]); ?>
</div>
</div>
<?php
// Element 0 quand aucun membre a été sélectionné
$groupMembers = [''] + $module::$groupNews;
?>
Destinataires :
<div class="row">
<div class="col6 offset1">
<?php echo template::select('formConfigGroup', $groupMembers, [
'label' => 'Un groupe de membres :',
'selected' => $this->getData(['module', $this->getUrl(0), 'config', 'group'])
]); ?>
</div>
</div>
<div class="row">
<div class="col6 offset1">
<?php echo template::select('formConfigUser', $module::$listUsers, [
'label' => 'Un membre :',
'selected' => array_search($this->getData(['module', $this->getUrl(0), 'config', 'user']),$module::$listUsers)
]); ?>
</div>
</div>
<div class="row">
<div class="col6 offset1">
<?php echo template::text('formConfigMail', [
'label' => 'Un eMail :',
'value' => $this->getData(['module', $this->getUrl(0), 'config', 'mail']),
'help' => 'Saisissez une adresse mail individuelle ou de liste'
]); ?>
</div>
</div>
</div>
<?php echo template::checkbox('formConfigPageIdToggle', true, 'Rediriger vers une page du site après soumission du formulaire', [
<?php echo template::checkbox('formConfigPageIdToggle', true, 'Redirection après soumission du formulaire', [
'checked' => (bool) $this->getData(['module', $this->getUrl(0), 'config', 'pageId'])
]); ?>
<?php echo template::select('formConfigPageId', $module::$pages, [
'classWrapper' => 'displayNone',
'label' => 'Page',
'selected' => $this->getData(['module', $this->getUrl(0), 'config', 'pageId'])
]); ?>
<div class="col6 offset1">
<?php echo template::select('formConfigPageId', $module::$pages, [
'classWrapper' => 'displayNone',
'label' => 'Sélectionner une page du site :',
'selected' => $this->getData(['module', $this->getUrl(0), 'config', 'pageId'])
]); ?>
</div>
<?php echo template::checkbox('formConfigCapcha', true, 'Capcha à remplir pour soumettre le formulaire', [
'checked' => $this->getData(['module', $this->getUrl(0), 'config', 'capcha'])
]); ?>