1
0
This commit is contained in:
Daniel Tartavel
2021-04-29 10:32:58 +02:00
parent 37d8c8b64f
commit 7e015a3d1b
14 changed files with 504 additions and 238 deletions

View File

@ -1,15 +1,7 @@
<?php
require_once 'log.php';
require_once 'fonctions.inc.php';
function getLang( $lang )
{
$dico = array();
$fh = fopen('lang/'.$lang, 'r');
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}
function courrielEnvoi( $db )
{
@ -17,6 +9,11 @@ function courrielEnvoi( $db )
$dicoDest = getLang( $db->destLang );
$expediteurIndex = "Notification_denvoi_Expediteur";
//print "envoi du courriel" . EOL;
// Message à l'expéditeur
$indexObjet = "Objet_" . $expediteurIndex;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) .EOL .EOL ;
if ( $db->expeKnown == false )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
@ -24,49 +21,49 @@ function courrielEnvoi( $db )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
}
$indexObjet = "Objet_" . $expediteurIndex;
$objetMail = $dicoExpe[$indexObjet];
$mailText = $dicoExpe[$expediteurIndex] .EOL .EOL ;
envoiMail( $db->expeMail, $objetMail, $mailText, true);
saveMail( $db, $db->expeMail, $objetMail, $mailText);
// message au destinataire
$indexObjet = "Objet_" . $destinataireIndex;
$objetMail = $dicoExpe[$indexObjet];
$mailText = $dicoExpe[$destinataireIndex] .EOL .EOL ;
//sleep (1);
envoiMail( $db->destMail, $objetMail, $mailText, true);
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest) .EOL .EOL ;
saveMail( $db, $db->destMail, $objetMail, $mailText);
}
function courrielArrivee($uid)
function saveMail( $db, $destinataire, $objet, $text, $html=FALSE)
{
//TODO
$query = "INSERT INTO courriels VALUES ('0', '" . $db->protect($destinataire) . "', '" . $db->protect($objet) . "', '" . $db->protect($text) . "', '" . (int)$html . "')";
$db->query($query);
}
function envoiMail($destinataire, $sujet, $text, $html=false)
function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
{
$headers = "From: contact@avion-poe.me" . LF;
if ($html)
{
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
}else
if ( !empty($cc)) $headers .= "Cc: " . $cc . LF;
if ( !empty($bcc)) $headers .= "Bcc: " . $bcc . LF;
if (empty($html))
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
}else
{
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
nl2br($text);
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $text . "sujet:" . $sujet, INFO);
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
if( !mail($destinataire, $sujet, wordwrap($text, 70 , "\r\n"), $headers) ) //Sending mail
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$text . EOL . $sujet . EOL, ERROR);
return 0;
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet, ERROR);
return false;
}else
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti:" .$text . EOL, INFO);
return 1;
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti: " . $destinataire . EOL . "text:" . $text, INFO);
return true;
}
}
?>