diff --git a/gestionsite/envoiMailing.php b/gestionsite/envoiMailing.php index b9b4bc0..d7a1ec9 100644 --- a/gestionsite/envoiMailing.php +++ b/gestionsite/envoiMailing.php @@ -25,7 +25,7 @@ if (empty($idVotation)) }else { //chargement des données de la votation - $db->query("SELECT *, UNIX_TIMESTAMP( DATE_ADD(dateFin, INTERVAL 1 DAY)) as tf FROM liste_votations WHERE id=" . $idVotation); + $db->query("SELECT *, UNIX_TIMESTAMP( DATE_ADD(dateFin, INTERVAL 1 DAY)) as tf, UNIX_TIMESTAMP(dateFin) as df, UNIX_TIMESTAMP(dateDebut) as dd FROM liste_votations WHERE id=" . $idVotation); $votation = $db->result->fetch_array(); if(empty($_GET['status'])) @@ -51,7 +51,7 @@ if (empty($idVotation)) $dolibarr->close(); $sujet = "[LALIS] Convocation à un vote"; - $textDebut = "Bonjour,\nL'association Lalis vous invite à un vote.\nMotif du vote : " . $votation['libelle'] . "\n\nPour voter, cliquez sur le lien suivant :\nhttps://lalis69.ddns.net:10443/vote.form.php?v=" . $idVotation . "&id="; + $textDebut = "Bonjour,\nL'association Lalis vous invite à un vote du " . formatteDate('fr', $votation['dd'], 'Europe/Paris') . " 0h00 au " . formatteDate('fr', $votation['df'], 'Europe/Paris') . " minuit.\nMotif du vote : " . $votation['libelle'] . "\n\nPour voter, cliquez sur le lien suivant :\nhttps://lalis69.ddns.net:10443/vote.form.php?v=" . $idVotation . "&id="; $textFin = "\n\nNous vous rappelons que pour pouvoir voter, vous devez être à jour de cotisation à la date du vote.\nLes résultats seront visibles dès le " . formatteDate('fr', $votation['tf'], 'Europe/Paris') . " par le lien suivant : https://lalis69.ddns.net:10443/vote.resultat.php?id=" . $idVotation . "\n\nPour Lalis, Le Président, David Larochette."; foreach($adherents as $adherent) { @@ -59,9 +59,8 @@ if (empty($idVotation)) print '
' . $adherent['email'] . ' ' . $adherent['firstname'] . ' ' . $adherent['lastname'] . EOLH . nl2br($text) . ''; if ( $_GET['status'] == 'Oui') { - //envoiMail($adherent['email'], $sujet, $text, $html=false, $cc='', $bcc=''); - envoiMail('david@larochette.me', $sujet, $text, $html=false, $cc='', $bcc=''); - envoiMail('ric.libr4d@protonmail.com', $sujet, $text, $html=false, $cc='', $bcc=''); + envoiMail($adherent['email'], $sujet, $text, $html=false, $cc='', $bcc=''); + //envoiMail('dtux@free.fr', $sujet, $text, $html=false, $cc='', $bcc=''); } } }else diff --git a/include/fonctions.inc.php b/include/fonctions.inc.php index 8ae41f2..e328eba 100644 --- a/include/fonctions.inc.php +++ b/include/fonctions.inc.php @@ -1,5 +1,12 @@ '; } -function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='') +/* +function envoiMailold($destinataire, $sujet, $text, $html=false, $cc='', $bcc='') { require_once 'swiftmailer/autoload.php'; //require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php'; @@ -133,6 +141,64 @@ function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='') return false; } return true; +}*/ + +function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='') +{ + + //require 'vendor/autoload.php'; + $mail = new PHPMailer(true); + try { + if ($html) + { + // setParameters() takes an associative array + $str = nl2br($text); + $text = "\n" . $str . ""; + log_write(__FILE__ . EOL . __LINE__ . EOL . wordwrap($text, 1000, "\r\n"), INFO); + $mail->isHTML(true); + $mail->AltBody = 'Ceci est un messssage HTML'; + }else + { + //$mail->isHTML(false); + + $text = str_replace("\n","\r\n", $text); + } + + + //Server settings + //$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output + $mail->isSMTP(); //Send using SMTP + $mail->Host = 'mail.gandi.net'; //Set the SMTP server to send through + $mail->SMTPAuth = true; //Enable SMTP authentication + $mail->Username = 'contact@lalis.fr'; //SMTP username + $mail->Password = 'Gu>V$fiM{bQ^!x+FAHF+R.}bl'; //SMTP password + $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit ssl encryption + $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` + $mail->MessageDate= ''; + $mail->SMTPKeepAlive = true; + //Recipients + $mail->setFrom('contact@lalis.fr'); + $mail->addAddress($destinataire); //Add a recipient + //$mail->addReplyTo('info@example.com', 'Information'); + $mail->CharSet = PHPMailer::CHARSET_UTF8; + $mail->Body = $text; + //Attachments + //$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments + //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name + + //Content + //Set email format to HTML + $mail->Subject = $sujet; + $mail->send(); + echo 'Message has been sent'; + log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti:" . $destinataire . EOL . $sujet . EOL, INFO); + } catch (Exception $e) { + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; + log_error(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" . $destinataire . EOL . $sujet . EOL . print_r($mail->ErrorInfo, true) . EOL . wordwrap($text, 1000 , "\r\n")); + $mail->getSMTPInstance()->reset(); + return false; + } + return true; } function formatteDate($locale, $date, $tz) @@ -146,4 +212,32 @@ function formatteDate($locale, $date, $tz) } return $formatter->format($datetime ); } + +function listeAdherents() +{ + $dolibarr = new dbDolibarr(); + $query = 'SELECT login, firstname, lastname FROM llx_adherent'; + $dolibarr->query($query); + while ($adherent = $dolibarr->result->fetch_array()) + { + $listeAdherents[$adherent['login']] = $adherent['firstname'] . ' ' . $adherent['lastname']; + } + $dolibarr->close(); + return $listeAdherents; +} + +function listeVotants($idVotation, $idVote, $listeAdherents) +{ + global $db; + $query = "SELECT DISTINCT idVotant FROM votes WHERE idVotation=" . $idVotation . ' AND idVote=' . $idVote; + $result = $db->query($query); + print (EOLH . ' ' . EOLH); +} + ?> diff --git a/vote.form.php b/vote.form.php index 09cee20..5a990a7 100644 --- a/vote.form.php +++ b/vote.form.php @@ -35,7 +35,7 @@ if ($dolibarr->result->num_rows == 0) { $dolibarr->close(); $db = new db(); - $query = 'SELECT *, UNIX_TIMESTAMP(dateDebut) as td, UNIX_TIMESTAMP(dateFin) as tf FROM liste_votations WHERE id=' . $db->protect($idVotation); + $query = 'SELECT *, UNIX_TIMESTAMP(dateDebut) as td, UNIX_TIMESTAMP( DATE_ADD(dateFin, INTERVAL 1 DAY)) as tf FROM liste_votations WHERE id=' . $db->protect($idVotation); $resultVotation = $db->query($query); $votation = $db->result->fetch_array(); $now = date('Y-m-d'); diff --git a/vote.resultat.php b/vote.resultat.php index 1282e72..7bdaadb 100644 --- a/vote.resultat.php +++ b/vote.resultat.php @@ -4,7 +4,22 @@ require_once 'session_init.php'; require_once 'config.inc.php'; require_once 'db.class.php'; require_once 'entete.html'; +require_once 'fonctions.inc.php'; +print ''; $idVotation = $_GET["id"]; $db = new db(); @@ -34,6 +49,7 @@ if ( empty($idVotation)) if ( time() < $votation['tf'] ) { echo $votation["libelle"] . ""; + $listeAdherents = listeAdherents(); print ('