1
0

- added mail return address to expeditor of ap\n- debug of error on peripetie datetime

This commit is contained in:
Daniel Tartavel 2022-02-10 19:57:35 +01:00
parent ecf570ee87
commit 4dd37cda7b
3 changed files with 72 additions and 54 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
//chdir('/var/www/html/avion-poeme/'); //chdir('/var/www/html/avion-poeme/');
require_once 'session_init.php'; require_once 'session_init.php';
require_once 'config.inc.php'; require_once 'config.inc.php';
require_once 'db.class.php'; require_once 'db.class.php';
@ -9,11 +10,10 @@
$db = new db(); $db = new db();
//test(); //test();
$_SERVER["PHP_AUTH_USER"] = "cron"; $_SERVER["PHP_AUTH_USER"] = "cron";
//peripetieDatee(); //peripetieDatee(); // désactivée pour l'instant
print "envoi des courriers en attente" . EOLH;
envoiCourrielEnattente(); envoiCourrielEnattente();
print "envoi des péripéties" . EOLH; print "envoi des péripéties" . EOLH;
peripeties(); //peripeties();
print "Envoi des arrivées" . EOLH; print "Envoi des arrivées" . EOLH;
arrivee(); arrivee();
anonymisation(); anonymisation();
@ -62,6 +62,7 @@
$dbPeripetie->query($query); $dbPeripetie->query($query);
$peripeties = $dbPeripetie->result->fetch_all(MYSQLI_ASSOC); $peripeties = $dbPeripetie->result->fetch_all(MYSQLI_ASSOC);
$dbPeripetie->close(); $dbPeripetie->close();
//print_r($peripeties);
foreach ( $peripeties as $peripetie) foreach ( $peripeties as $peripetie)
{ {
print "péripétie " . $peripetie["idAP"] . " - avion poème n° " . $peripetie['idAvion'] .EOLH; print "péripétie " . $peripetie["idAP"] . " - avion poème n° " . $peripetie['idAvion'] .EOLH;
@ -77,11 +78,15 @@
$dicoExpe = getLang( $db->expeLang ); $dicoExpe = getLang( $db->expeLang );
$dicoDest = getLang( $db->destLang ); $dicoDest = getLang( $db->destLang );
// TODO calcul de la nouvelle date d'arrivée // TODO calcul de la nouvelle date d'arrivée
$dateExpe = new DateTime("@$db->startTime"); $startTime = date("c", $db->startTime);
$dateDest = new DateTime("@$db->deliveryTime"); $deliveryTime = date("c", $db->deliveryTime);
$dateExpe = new DateTime($startTime);
print_r($dateExpe);
$dateDest = new DateTime($deliveryTime);
print_r($dateDest);
$interval = $dateExpe->diff($dateDest); $interval = $dateExpe->diff($dateDest);
$numericInterval = (($interval->days*24 + $interval->h)*60 + $interval->i)*60 + $interval->s; $numericInterval = (($interval->days*24 + $interval->h)*60 + $interval->i)*60 + $interval->s;
$addDate = $numericInterval * 15/100; $addDate = $numericInterval * 15/100; //TODO calculer d'après les données de la péripétie(voir table péripétie de la base de données)
$db->deliveryTime += $addDate; $db->deliveryTime += $addDate;
$db->deliveryTimeServer += $addDate; $db->deliveryTimeServer += $addDate;
$query = "UPDATE avionpoeme SET deliveryTime=FROM_UNIXTIME(" . $db->deliveryTime . "), deliveryTimeServer=FROM_UNIXTIME(" . $db->deliveryTimeServer . ") WHERE idAvion='" . $peripetie['idAvion'] . "'" ; $query = "UPDATE avionpoeme SET deliveryTime=FROM_UNIXTIME(" . $db->deliveryTime . "), deliveryTimeServer=FROM_UNIXTIME(" . $db->deliveryTimeServer . ") WHERE idAvion='" . $peripetie['idAvion'] . "'" ;
@ -96,24 +101,23 @@
//$html = $result['html']; //$html = $result['html'];
sleep(1); sleep(1);
print "envoi courriel à l'expéditeur : " . $db->expeMail . EOLH . $mailText .EOLH; print "envoi courriel à l'expéditeur : " . $db->expeMail . EOLH . $mailText .EOLH;
$r = envoiMail( $db->expeMail, $objetMail, $mailText); $r = envoiMail("contact@avion-poe.me", $db->expeMail, $objetMail, $mailText);
$db->datePeripetie = formatteDate($db->destLang, $db->deliveryTime, $db->deliveryTZ); $db->datePeripetie = formatteDate($db->destLang, $db->deliveryTime, $db->deliveryTZ);
$result = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest); $result = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest);
$objetMail = $result["text"]; $objetMail = $result["text"];
$result = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest); $result = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest);
$mailText = $result["text"]; $mailText = $result["text"];
print "envoi courriel au destinataire : " . $db->destMail . EOLH . $mailText .EOLH; print "envoi courriel au destinataire : " . $db->destMail . EOLH . $mailText .EOLH;
$s = envoiMail( $db->destMail, $objetMail, $mailText); $s = envoiMail($db->expeMail, $db->destMail, $objetMail, $mailText);
sleep(1); sleep(1);
//print "r=" . $r ." => s=" .$s .EOLH; //print "r=" . $r ." => s=" .$s .EOLH;
if ($r AND $s) if ($r AND $s)
{ {
$query = "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'"; $query = "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'";
$db->query($query); $db->query($query);
}else }else
{ {
print "table avion péripétie non mise à jour" .EOL; print "table avion péripétie non mise à jour" . EOL;
print "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'" .EOLH; print "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'" .EOLH;
} }
@ -135,7 +139,7 @@
//var_dump($avionArrive); //var_dump($avionArrive);
foreach ($avionArrive as $avion) foreach ($avionArrive as $avion)
{ {
print "avion poème n° " . $avion['idAvion'] . "a atterri" . EOLH; print "avion poème n° " . $avion['idAvion'] . " a atterri" . EOLH;
$dicoExpe = getLang( $avion['expeLang'] ); $dicoExpe = getLang( $avion['expeLang'] );
$dicoDest = getLang( $avion['destLang'] ); $dicoDest = getLang( $avion['destLang'] );
@ -146,7 +150,7 @@
$result = replaceVariables((object)$avion, $dicoExpe[$index], $dicoExpe); $result = replaceVariables((object)$avion, $dicoExpe[$index], $dicoExpe);
$mailText= $result["text"]; $mailText= $result["text"];
print "envoi courriel à l'expéditeur : " . $avion['expeMail'] . EOLH . $mailText .EOLH; print "envoi courriel à l'expéditeur : " . $avion['expeMail'] . EOLH . $mailText .EOLH;
$r = envoiMail( $avion['expeMail'], $objetMail["text"], $mailText); $r = envoiMail("contact@avion-poe.me", $avion['expeMail'], $objetMail["text"], $mailText);
//envoi notification arrivée destinataire //envoi notification arrivée destinataire
$index = "Notification_Arrivee_Destinataire"; $index = "Notification_Arrivee_Destinataire";
@ -159,14 +163,14 @@
$mailText = "<html><head></head>\n<body>" . $mailText . "</body></html>"; $mailText = "<html><head></head>\n<body>" . $mailText . "</body></html>";
} }
print "envoi courriel au destinataire : " . $avion['destMail'] . EOLH . $mailText .EOLH; print "envoi courriel au destinataire : " . $avion['destMail'] . EOLH . $mailText .EOLH;
sleep(1); sleep(3);
$s = envoiMail( $avion['destMail'], $objetMail["text"], $mailText, $html); $s = envoiMail($avion['expeMail'], $avion['destMail'], $objetMail["text"], $mailText, $html);
if ($r AND $s) if ($r AND $s)
{ {
$query = "UPDATE avionpoeme SET atteri=true WHERE idAvion='" . $avion['idAvion'] ."'"; $query = "UPDATE avionpoeme SET atteri=true WHERE idAvion='" . $avion['idAvion'] ."'";
$db->query($query); $db->query($query);
} }
sleep(1); sleep(3);
} }
} }
@ -178,13 +182,14 @@
$courriels = $db->result->fetch_all(MYSQLI_ASSOC); $courriels = $db->result->fetch_all(MYSQLI_ASSOC);
foreach( $courriels as $courriel) foreach( $courriels as $courriel)
{ {
$r = envoiMail( $courriel['destinataire'], $courriel['objet'], $courriel['message'], $courriel['html']); //TODO changer l'expéditeur, doit être l'expéditeur de l'avion-poême.
$r = envoiMail("contact@avion-poe.me", $courriel['destinataire'], $courriel['objet'], $courriel['message'], $courriel['html']);
if ($r) if ($r)
{ {
$query = "DELETE FROM courriels WHERE id='" . $courriel['id'] . "'"; $query = "DELETE FROM courriels WHERE id='" . $courriel['id'] . "'";
$db->query($query); $db->query($query);
} }
sleep(1); sleep(3);
} }
} }
@ -213,3 +218,4 @@
} }
} }
$db->close(); $db->close();
?>

View File

@ -7,7 +7,6 @@ if (!isset($site)) {
require_once "config.inc.php"; require_once "config.inc.php";
require_once "log.php"; require_once "log.php";
require_once "fonctions.inc.php"; require_once "fonctions.inc.php";
require_once "envoi_courriel.inc.php";
$table_prefix = ""; $table_prefix = "";
class db class db
@ -197,10 +196,17 @@ class db
function savePeripetie() function savePeripetie()
{ {
$query = "INSERT INTO avionPeripetie VALUES ('0','"; $query = "INSERT INTO avionPeripetie ('expeMail', 'idAvion', 'idPeripetie', 'date'), VALUES (";
$query .= $this->protect($this->uid) . "','"; if ($this->expeKnown)
$query .= $this->protect($this->idPeripetie) . "', "; {
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "), '0')"; $query .= "'" . $this->protect($this->expeMail) . "',";
}else
{
$query .= "'contact@avion-poe.me',";
}
$query .= "'" . $this->protect($this->uid) . "',";
$query .= "'" . $this->protect($this->idPeripetie) . "', ";
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "))";
log_write("savePeripetie " . $query); log_write("savePeripetie " . $query);
//$query .= $this->protect($this->effetPeripetie) . "', '"; //$query .= $this->protect($this->effetPeripetie) . "', '";
//$query .= $this->protect($this->expeMail) . "', '"; //$query .= $this->protect($this->expeMail) . "', '";

View File

@ -2,7 +2,6 @@
require_once 'log.php'; require_once 'log.php';
require_once 'fonctions.inc.php'; require_once 'fonctions.inc.php';
function courrielEnvoi( $db ) function courrielEnvoi( $db )
{ {
$dicoExpe = getLang( $db->expeLang ); $dicoExpe = getLang( $db->expeLang );
@ -56,43 +55,50 @@ function saveMail( $db, $expediteur, $destinataire, $objet, $text, $html=false)
$db->query($query); $db->query($query);
} }
function envoiMail($expediteur,$destinataire, $sujet, $text, $html=false, $cc='', $bcc='') function envoiMail($expediteur, $destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
{ {
require_once 'include/swiftmailer/autoload.php'; require_once 'include/swiftmailer/autoload.php';
//require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php'; //require_once 'include/swiftmailer/swiftmailer/lib/swift_init.php';
$transport = (new Swift_SmtpTransport('smtpauth.online.net', 465, 'ssl')) try
->setUsername('contact@avion-poe.me')
->setPassword('AvionPoème*27juillet');
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message($sujet))
->setFrom(["contact@avion-poe.me"])
->setTo([$destinataire])
->setCharset('utf-8');
$type = $message->getHeaders()->get('Content-Type');
if ($html)
{ {
// setParameters() takes an associative array $transport = (new Swift_SmtpTransport('smtpauth.online.net', 465, 'ssl'))
$type->setValue('text/html'); ->setUsername('contact@avion-poe.me')
$type->setParameter('charset', 'utf-8'); ->setPassword('AvionPoème*27juillet');
$str = nl2br($text); $mailer = new Swift_Mailer($transport);
$text = "<html><head></head>\n<body>" . $str . "</body></html>"; $message = (new Swift_Message($sujet))
log_write(__FILE__ . EOL . __LINE__ . EOL . wordwrap($text, 1000, "\r\n"), INFO); ->setFrom(["contact@avion-poe.me"])
}else ->setTo([$destinataire])
{ ->setCharset('utf-8');
$type->setValue('text/plain'); $type = $message->getHeaders()->get('Content-Type');
$type->setParameter('charset', 'utf-8'); if ($html)
$text = str_replace("\n","\r\n", $text); {
// setParameters() takes an associative array
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');
$str = nl2br($text);
$text = "<html><head></head>\n<body>" . $str . "</body></html>";
log_write(__FILE__ . EOL . __LINE__ . EOL . wordwrap($text, 1000, "\r\n"), INFO);
}else
{
$type->setValue('text/plain');
$type->setParameter('charset', 'utf-8');
$text = str_replace("\n","\r\n", $text);
}
$message->setBody($text);
//add date header
$headers = $message->getHeaders();
//$headers->addDateHeader('Date', new DateTimeImmutable('3 days ago'));
$headers->addPathHeader('Return-Path', $expediteur);
if (!$mailer->send($message, $failures))
{
echo "Failures:";
print_r($failures);
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" . $destinataire . EOL . $sujet . EOL . print_r($failure, true) . EOL . wordwrap($text, 1000 , "\r\n"), ERROR);
return false;
}
} }
$message->setBody($text); catch (\Swift_TransportException $ex)
//add date header
$headers = $message->getHeaders();
//$headers->addDateHeader('Date', new DateTimeImmutable('3 days ago'));
$headers->addPathHeader('Return-Path', $expediteur);
if (!$mailer->send($message, $failures))
{ {
echo "Failures:";
print_r($failures);
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" . $destinataire . EOL . $sujet . EOL . print_r($failure, true) . EOL . wordwrap($text, 1000 , "\r\n"), ERROR);
return false; return false;
} }
return true; return true;