1
0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__avion-poeme/cron.php

218 lines
7.7 KiB
PHP
Raw Normal View History

2021-04-29 10:32:58 +02:00
<?php
chdir('/var/www/html/avion-poeme/');
require_once '/var/www/html/avion-poeme/session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'log.php';
require_once 'envoi_courriel.inc.php';
$db = new db();
test();
//peripetieDatee();
envoiCourrielEnattente();
peripeties();
arrivee();
function peripetieDatee()
{
global $db;
$flag = false;
$db->urlAvion = $base_url . "/?avionpoeme=" . $db->idAvion;
//recherche des péripéties datées
$query = "SELECT * FROM peripeties WHERE quand!='' AND DATEDIFF(quand,CURDATE())=0";
$db->query($query);
$peripetieTable = $result = $db->result->fetch_all(MYSQLI_ASSOC);
$query = "SELECT * FROM avionpoeme WHERE atteri=0";
$db->query($query);
while ( ($result = $db->result->fetch_assoc()) )
{
$dicoExpe = getLang( $result['expeLang'] );
$dicoDest = getLang( $result['destLang'] );
foreach( $peripetieTable as $p )
{
$indexObjet = "Objet_" . $p['indexText'];
$objetMail = $dicoExpe["Objet_" . $p['indexText']];
$mailText = $dicoExpe[$p['indexText']] .EOL .EOL ;
print $objetMail .EOLH;
print $mailText .EOLH;
envoiMail( $result['destMail'], $objetMail, $mailText, false);
sleep(1);
envoiMail( $result['expeMail'], $objetMail, $mailText, true);
sleep(1);
}
}
}
/* function peripeties()
{
global $db, $base_url;
//recherche des péripéties non datées
$query = "SELECT * FROM avionpoeme WHERE atteri = 0";
$db->query($query);
$dbPeripetie = new db();
$dbPeripetie->open();
while ( ($result = $db->result->fetch_assoc()) )
{
$dicoExpe = getLang( $result['expeLang'] );
$dicoDest = getLang( $result['destLang'] );
$db->urlAvion = $base_url . "/?avionpoeme=" . $result['idAvion'];
$query = "SELECT *, UNIX_TIMESTAMP(date) as dateArrivee FROM avionPeripetie LEFT JOIN peripeties USING (idPeripetie) WHERE idAvion='" . $result['idAvion'] . "' AND mailSent=false AND TIMEDIFF(CONCAT_WS(' ',CURDATE(),CURTIME()), date) > '00:00'";
$dbPeripetie->query($query);
while (($peripetie = $dbPeripetie->result->fetch_assoc()))
{
$db->datePeripetie = formatteDate($result['expeLang'],$peripetie['dateArrivee'], $result['startTZ']);
$indexObjet = "Objet_" . $peripetie['indexText'];
$objetMail = replaceVariables($db, $dicoExpe["Objet_" . $peripetie['indexText']], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$peripetie['indexText']], $dicoExpe) .EOLH .EOLH ;
print $mailText .EOLH;
print "envoi courriel au destinataire" .EOLH;
$r = true; //envoiMail( $result['destMail'], $objetMail, $mailText, true);
//sleep(2);
$db->datePeripetie = formatteDate($result['destLang'],$peripetie['dateArrivee'], $result['deliveryTZ']);
$objetMail = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest) .EOLH .EOLH ;
print $mailText .EOLH;
print "envoi courriel à l'expéditeur" .EOLH;
$s = true; //envoiMail( $result['expeMail'], $objetMail, $mailText, true);
//sleep(2);
if ($r AND $s)
{
$query = "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'";
$db->query($query);
}
}
}
$dbPeripetie->close();
}
*/
function peripeties() //recherche des péripéties non datées
{
global $db, $base_url;
// ouverture DB peripéties
$dbPeripetie = new db();
// requête Mysql
$query = "SELECT *, UNIX_TIMESTAMP(date) as datePeripetie FROM avionPeripetie LEFT JOIN peripeties USING (idPeripetie) WHERE mailSent=false AND TIMEDIFF(CONCAT_WS(' ',CURDATE(),CURTIME()), date) > '00:00'";
$dbPeripetie->query($query);
$peripeties = $dbPeripetie->result->fetch_all(MYSQLI_ASSOC);
$dbPeripetie->close();
foreach ( $peripeties as $peripetie)
{
$db->getPlane($peripetie['idAvion']);
$dicoExpe = getLang( $db->expeLang );
if ( $db->expeLang == $db->destLang )
{
$dicoDest ='';
}else
{
$dicoDest = getLang( $db->destLang );
}
// TODO calcul de la nouvelle date d'arrivée
$dateExpe = new DateTime("@$db->startTime");
$dateDest = new DateTime("@$db->deliveryTime");
$interval = $dateExpe->diff($dateDest);
$numericInterval = (($interval->days*24 + $interval->h)*60 + $interval->i)*60 + $interval->s;
$addDate = $numericInterval * 15/100;
$db->deliveryTime += $addDate;
$query = "UPDATE avionpoeme SET deliveryTime=FROM_UNIXTIME(" . $this->deliveryTime . ")";
$db->query($query);
$db->urlAvion = $base_url . "/?avionpoeme=" . $db->uid;
$db->datePeripetie = formatteDate($db->expeLang, $db->deliveryTime, $db->startTZ);
$indexObjet = "Objet_" . $peripetie['indexText'];
$objetMail = replaceVariables($db, $dicoExpe["Objet_" . $peripetie['indexText']], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$peripetie['indexText']], $dicoExpe) .EOLH .EOLH ;
print $mailText .EOLH;
sleep(1);
if (empty($dicoDest))
{
print "envoi courriel à l'expéditeur et au destinataire en BCC" .EOLH;
$r = envoiMail( $db->expeMail, $objetMail, $mailText, false, '', $db->destMail );
$s = $r; //pour l'update de la BD
}else
{
print "envoi courriel à l'expéditeur" .EOLH;
$r = envoiMail( $db->expeMail, $objetMail, $mailText, false);
$db->datePeripetie = formatteDate($db->destLang, $db->deliveryTime, $db->deliveryTZ);
$objetMail = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest) .EOLH .EOLH ;
print "envoi courriel au destinataire" .EOLH;
$s = envoiMail( $db->destMail, $objetMail, $mailText, false);
sleep(1);
//print "r=" . $r ." => s=" .$s .EOLH;
}
if ($r AND $s)
{
$query = "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'";
$db->query($query);
}
}
}
function arrivee()
{
global $db;
//recherche des avions atteris
$query = "SELECT * FROM avionpoeme WHERE atteri = 0 AND TIMEDIFF(CONCAT_WS(' ',CURDATE(),CURTIME()),deliveryTime) > '00:00'";
$db->query($query);
$avionArrive = $db->result->fetch_all(MYSQLI_ASSOC);
foreach ($avionArrive as $avion)
{
$dicoExpe = getLang( $avion['expeLang'] );
$dicoDest = getLang( $avion['destLang'] );
$index = "Notification_Arrivee_Expediteur";
$indexObjet = "Objet_";
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet . $index], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$index], $dicoExpe) . EOL . EOL ;
print $mailText . EOLH;
print "envoi courriel à l'expéditeur" . EOLH;
$r = envoiMail( $avion['destMail'], $objetMail, $mailText);//
sleep(1);
$index = "Notification_Arrivee_Destinataire";
$objetMail = replaceVariables($db, $dicoDest[$indexObjet . $index], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$index], $dicoDest) .EOLH .EOLH ;
print "envoi courriel au destinataire" . EOLH;
$s = envoiMail( $avion['expeMail'], $objetMail, $mailText);
if ($r AND $s)
{
$query = "UPDATE avionpoeme SET atteri=true WHERE idAvion='" . $avion['idAvion'] ."'";
$db->query($query);
}
sleep(1);
}
}
function envoiCourrielEnattente()
{
global $db;
$query = "SELECT * FROM courriels";
$db->query($query);
$courriels = $db->result->fetch_all(MYSQLI_ASSOC);
foreach( $courriels as $courriel)
{
$r = envoiMail( $courriel['destinataire'], $courriel['objet'], $courriel['message'], $courriel['html']);
if ($r)
{
$query = "DELETE FROM courriels WHERE id='" . $courriel['id'] . "'";
$db->query($query);
}
sleep(1);
}
}
function test()
{
$lang = array( 'fr', 'en', 'es', 'de', 'ar', 'bg', 'zh', 'ja', 'pt');
foreach ($lang as $value)
{
getLang( $value );
print $value;
print json_last_error_msg() .EOLH;
}
}
$db->close();
?>