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() //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) { print "avion poème n° " . $peripetie['idAvion'] .EOL; $db->getPlane($peripetie['idAvion']); $dicoExpe = getLang( $db->expeLang ); $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; $db->deliveryTimeServer += $addDate; $query = "UPDATE avionpoeme SET deliveryTime=FROM_UNIXTIME(" . $db->deliveryTime . "), deliveryTimeServer=FROM_UNIXTIME(" . $db->deliveryTimeServer . ") WHERE idAvion='" . $peripetie['idAvion'] . "'" ; $db->query($query); $db->urlAvion = $base_url . "/?avionpoeme=" . $db->uid; $db->datePeripetie = formatteDate($db->expeLang, $db->deliveryTime, $db->startTZ); $indexObjet = "Objet_" . $peripetie['indexText']; $result = replaceVariables($db, $dicoExpe["Objet_" . $peripetie['indexText']], $dicoExpe); $objetMail = $result["text"]; $result = replaceVariables($db, $dicoExpe[$peripetie['indexText']], $dicoExpe); $mailText = $result["text"]; //$html = $result['html']; sleep(1); print "envoi courriel à l'expéditeur" .EOL; $r = envoiMail( $db->expeMail, $objetMail, $mailText); $db->datePeripetie = formatteDate($db->destLang, $db->deliveryTime, $db->deliveryTZ); $result = replaceVariables($db, $dicoDest["Objet_" . $peripetie['indexText']], $dicoDest); $objetMail = $result["text"]; $result = replaceVariables($db, $dicoDest[$peripetie['indexText']], $dicoDest); $mailText = $result["text"] .EOLH .EOLH; print "envoi courriel au destinataire" .EOL; $s = envoiMail( $db->destMail, $objetMail, $mailText); 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); }else { print "table avion péripétie non mise à jour" .EOL; print "UPDATE avionPeripetie SET mailSent=true WHERE idAP='" . $peripetie['idAP'] ."'" .EOL; } sleep(1); } } function arrivee() { global $db; //recherche des avions atteris $query = "SELECT * FROM avionpoeme WHERE atteri = 0 AND TIMEDIFF(CONCAT_WS(' ',CURDATE(),CURTIME()),deliveryTimeServer) > '00:00'"; $db->query($query); $avionArrive = $db->result->fetch_all(MYSQLI_ASSOC); foreach ($avionArrive as $avion) { print "avion poème n° " . $avion['idAvion'] . EOLH; $dicoExpe = getLang( $avion['expeLang'] ); $dicoDest = getLang( $avion['destLang'] ); $index = "Notification_Arrivee_Expediteur"; $indexObjet = "Objet_"; $objetMail = replaceVariables($db, $dicoExpe[$indexObjet . $index], $dicoExpe); $result = replaceVariables($db, $dicoExpe[$index], $dicoExpe); $mailText= $result["text"]; print "envoi courriel à l'expéditeur". EOLH; $r = envoiMail( $avion['expeMail'], $objetMail["text"], $mailText); sleep(1); $index = "Notification_Arrivee_Destinataire"; $objetMail = replaceVariables($db, $dicoDest[$indexObjet . $index], $dicoDest); $result = replaceVariables($db, $dicoDest[$index], $dicoDest); log_write(__FILE__ . EOL . __LINE__ . EOL . "#" .print_r($result, true) . "#", INFO); $mailText = $result["text"]; $html = $result['html']; if ( $html ) { $mailText = "\n" . $mailText . ""; } print "envoi courriel au destinataire" . EOLH; $s = envoiMail( $avion['destMail'], $objetMail["text"], $mailText, $html); 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(); ?>