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

11
avionJournalier.php Normal file
View File

@ -0,0 +1,11 @@
<?php
require_once 'session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'log.php';
$db = new db();
$nAvion = $db->avionJournalier();
$db->close();
print '{"nAvion":"' . $nAvion . '"}';
?>

View File

@ -8,7 +8,7 @@
$table=array("message", "expeMail", "expeKnown", "expeLang", "destLang", "startLat", "startLon", "startName", "startTime", "startTZ", "destMail", "destLat", "destLon", "destName", "public", "color", "deliveryTime", "deliveryTZ", "deliveryTimeServer", "deliveryMethod");
$db = new db();
$db->open();
//$db->open();
foreach ($table as $var)
{

217
cron.php Normal file
View File

@ -0,0 +1,217 @@
<?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();
?>

View File

@ -1,7 +1,10 @@
<?php
require_once '../session_init.php';
require_once 'config.inc.php';
if ( isset($_GET["ok"] ))
{
$fisrt_line = false;
$fh = fopen("../lang/9mfo-traduction.csv", "r") or die("Can't open csv");
$fhIndex = fopen("../lang/lang.json", "w") or die("Can't open lang/lang.json");
@ -32,7 +35,6 @@
$index = explode("/",$column);
echo "opening ../lang/" . $index[0] . EOLH;
$fhl[++$i] = fopen("../lang/" . $index[0], "wb") or die("can't open lang/" . $index[0]);
fwrite($fhl[$i], '{');
if ( $first_column == true )
@ -89,5 +91,15 @@
fwrite($fhx, '}');
fclose($fhx);
}
$fh = fopen("lang/lang.json","r");
$str = fgets($fh);
fclose($fh);
$lang = json_decode( $str, true);
foreach ($lang as $key => $value)
{
getLang( $key );
print $key;
print json_last_error_msg() .EOL;
}
}
?>

View File

@ -28,3 +28,4 @@
<body>
<a href="lang.php">Générer les fichiers de langue</a>
<a href="logs.php">Lire les logs</a>

View File

@ -33,4 +33,4 @@
echo nl2br($text);
?>
<a href="genere_lang.php">Générer les fichiers de langue</a>
<a href="genere_lang.php?ok=true">Générer les fichiers de langue</a>

8
gestion/logs.php Normal file
View File

@ -0,0 +1,8 @@
<?php
require_once '../session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'log.php';
affich_log(200);
?>

View File

@ -1,7 +1,7 @@
<?php
define( 'EOL', "\n" );
define( 'EOLH', "</br>" );
define( 'EOLH', "<br>\n" );
define( 'LF', "\r\n" );
define( 'TAB', "\t" );
@ -20,14 +20,9 @@ $site = "Avion Poème";
$dossier = "/www";
$basedir = dirname( $_SERVER['DOCUMENT_ROOT'] ) . $dossier;
$base_url = "https://avion-poe.me";
$base_url = "http://avion-poe.me";
$base_path = "/flex/storage/avion-poe.me/site/www/";
//$url_admin = $base_url . "/admin";
$url_admin = $base_url . "/gestion";
$accueil = $base_url . "/index.html";
if ( !isset( $_SESSION['base_url']) )
{
$_SESSION['base_url'] = $base_url;
}
?>

View File

@ -7,6 +7,7 @@ if ( !isset($site) )
require_once "config.inc.php";
require_once "log.php";
require_once "fonctions.inc.php";
require_once "envoi_courriel.inc.php";
$table_prefix = "";
@ -30,6 +31,7 @@ class db
public $startLon;
public $startName;
public $startTime;
public $startTimeRFC822;
public $startTZ;
public $destMail;
public $destLat;
@ -38,9 +40,13 @@ class db
public $public;
public $color;
public $deliveryTime;
public $deliveryTimeRFC822;
public $deliveryTZ;
public $deliveryTimeServer;
public $deliveryMethod;
public $avionJournalier;
public $urlAvion;
// peripeties
public $idPeripetie;
public $datePeripetie;
@ -58,7 +64,7 @@ class db
$this->connect = new mysqli( $this->server, $this->user, $this->passwd, $this->database );
if ( $this->connect->connect_errno )
{
log_error( "Échec de la connexion : => " . $this->connect->connect_error . "<br />" . __file__ . ' ligne ' . __line__);
log_error( "Échec de la connexion : => " . $this->connect->connect_error . "<br />" . __file__ . ' ligne ' . __line__, false,false);
return false;
}
}
@ -91,6 +97,7 @@ class db
function newPlane() //return 0 on error
{
global $base_url;
$query = "INSERT INTO avionpoeme VALUES ('0','";
$query .= $this->protect($this->message) . "', '";
$query .= $this->protect($this->expeMail) . "', ";
@ -117,10 +124,45 @@ class db
$this->query($query);
$this->uid = $this->connect->insert_id;
echo "{'uid':'" . $this->uid . "'}";
$this->startTimeRFC822 = formatteDate( $this->expeLang, $this->startTime, $this->startTZ);
$this->deliveryTimeRFC822 = formatteDate( $this->destLang, $this->deliveryTime, $this->deliveryTZ );
$this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid;
courrielEnvoi($this);
$this->newPeripetie();
}
function getPlane($uid)
{
global $base_url;
$query = "SELECT idAvion, message, expeMail, expeKnown, expeLang, destLang, startLat, startLon, startName, UNIX_TIMESTAMP(startTime) as startTime, startTZ, destMail, destLat, destLon, destName, color, UNIX_TIMESTAMP(deliveryTime) as deliveryTime, deliveryTZ, UNIX_TIMESTAMP(deliveryTimeServer) as deliveryTimeServer, deliveryMethod, public FROM avionpoeme WHERE idAvion='" . $uid ."'";
$this->query($query);
$plane = $this->result->fetch_array(MYSQLI_ASSOC);
$this->message = $plane["message"];
$this->expeMail = $plane["expeMail"];
$this->expeKnown = $plane["expeKnown"];
$this->expeLang = $plane["expeLang"];
$this->destLang = $plane["destLang"];
$this->startLat = $plane["startLat"];
$this->startLon = $plane["startLon"];
$this->startName = $plane["startName"];
$this->startTime = $plane["startTime"];
$this->startTZ = $plane["startTZ"];
$this->startTimeRFC822 = formatteDate( $this->expeLang, $this->startTime, $this->startTZ);
$this->destMail = $plane["destMail"];
$this->destLat = $plane["destLat"];
$this->destLon = $plane["destLon"];
$this->destName = $plane["destName"];
$this->color = $plane["color"];
$this->deliveryTime = $plane["deliveryTime"];
$this->deliveryTZ = $plane["deliveryTZ"];
$this->deliveryTimeRFC822 = formatteDate( $this->destLang, $this->deliveryTime, $this->deliveryTZ );
$this->deliveryTimeServer = $plane["deliveryTimeServer"];
$this->deliveryMethod = $plane["deliveryMethod"];
$this->public = $plane["public"];
$this->uid = $plane["idAvion"];
$this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid;
}
function getCurrentPlanes()
{
$query = "SELECT idAvion as uid, UNIX_TIMESTAMP(deliveryTime) as deliveryTime, deliveryTZ, destLat, destLon, destName, UNIX_TIMESTAMP(startTime) as startTime, startTZ, startLon, startLat, startName, color FROM avionpoeme WHERE deliveryTimeServer>NOW()";
@ -143,7 +185,7 @@ class db
}else //renvoie les lignes d'anthologie
{
if ($page > $n_pages) $page=$n_pages;
$query = "SELECT UNIX_TIMESTAMP(startTime) as startTime, startTZ, startName, message, UNIX_TIMESTAMP(deliveryTime) as deliveryTime , deliveryTZ, destName FROM avionpoeme WHERE deliveryTimeServer<NOW() AND public='1' ORDER BY startTime DESC LIMIT " . ($page-1)*RESULTS_BY_PAGE . "," . RESULTS_BY_PAGE;
$query = "SELECT UNIX_TIMESTAMP(startTime) as startTime, startTZ, startName, message, UNIX_TIMESTAMP(deliveryTime) as deliveryTime , deliveryTZ, destName FROM avionpoeme WHERE deliveryTimeServer<NOW() AND public='1' ORDER BY deliveryTime DESC LIMIT " . ($page-1)*RESULTS_BY_PAGE . "," . RESULTS_BY_PAGE;
$this->query($query);
$planes = $this->result->fetch_all(MYSQLI_ASSOC);
print json_encode($planes, JSON_FORCE_OBJECT);
@ -153,11 +195,12 @@ class db
function savePeripetie()
{
global $db;
$query = "INSERT INTO avionPeripetie VALUES ('0','";
$query .= $this->protect($this->uid) . "','";
$query .= $this->protect($this->idPeripetie) . "', ";
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "))";
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "), '0')";
log_write("savePeripetie " . $query);
//$query .= $this->protect($this->effetPeripetie) . "', '";
//$query .= $this->protect($this->expeMail) . "', '";
//$query .= $this->protect($this->destMail) . "')"; echo $query . EOL;
@ -166,27 +209,29 @@ class db
function newPeripetie()
{
global $db;
$query = "SELECT *, DATEDIFF(quand,CURDATE()) as datePeripetie FROM peripeties WHERE quand IS NULL";
echo $query .EOL;
$this->query($query);
$this->startTime = 1616584838;
$this->deliveryTime = 1617469941;
while ( ($result = $this->result->fetch_assoc()) )
{
print_r($result["idPeripetie"]);
$this->idPeripetie = $result["idPeripetie"];
if ((mt_rand(0,100) <= $result["probabilite"])) //calcul de la probabilité de la péripétie
{
print $this->startTime . "=>" . $this->deliveryTime . "===>";
log_write("newPeripetie");
$this->datePeripetie = mt_rand($this->startTime, $this->deliveryTime); //ajustement de l'effet
print $this->datePeripetie . "EOL";
$this->savePeripetie();
break; //une seule péripétie par avionpoème. Enlever le break si pas de limites sur le nombre de péripéties
}
}
}
function avionJournalier()
{
$query = "SELECT COUNT(*) as count FROM avionpoeme WHERE DATEDIFF(startTime, NOW())=0";
$this->query($query);
$result = $this->result->fetch_assoc();
$this->avionJournalier = $result["count"];
return $this->avionJournalier;
}
}

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;
}
}
?>

View File

@ -1,4 +1,5 @@
<?php
require_once 'log.php';
if ( !isset($site) )
{
require_once( "config.inc.php" );
@ -36,3 +37,69 @@ function mb_ucfirst($str) {
return $char . $str;
}
function getLang( $lang )
{
$dico = array();
if ( empty($lang) )
{
$lang="en";
}
if (($fh = fopen('lang/'.$lang, 'r') ))
{
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}
}
function formatteDate($locale, $date, $tz)
{
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $tz, IntlDateFormatter::GREGORIAN );
if ($formatter == null)
{
log_write(InvalidConfigException(intl_get_error_message()));
}
return $formatter->format($date);
}
function replaceVariables($db, $text, $dico)
{
$variables = array( 'expediteur' => 'expeMail', 'destinataire' => 'destMail', 'date_depart' => 'startTimeRFC822', 'date_arrivee' => 'deliveryTimeRFC822', 'new_date_arrivee' => 'datePeripetie', 'message' => 'message', 'url_avion' => 'url_avion', 'onglet_apropos' => 'onglet_apropos', 'NB_avion_poeme' => 'avionJournalier', "url_avion" => "urlAvion");
$posVar = 0 ;
$x =0;
while( 1 )
{
$posVar = strpos( $text, "$", $posVar);
if ($posVar !== false)
{
if ($x++ >10 ) break;
$posEsp = strpos( $text, " ", $posVar);
if ($posEsp === false)
{
$var = substr($text, $posVar+1, strlen($text)-$posVar);
}else
{
$var = substr($text, $posVar+1, $posEsp-$posVar-1);
}
$var = trim($var, " .\n\r");
$posVar = $posEsp+1;
$varReplace = "$" . $var;
if ( isset ($variables[$var]) )
{
$dbVar = $variables[$var];
$text = str_replace($varReplace, $db->$dbVar, $text);
}elseif ( isset ($dico[$var]) )
{
$text = str_replace($varReplace, $dico[$var], $text);
}else
{
log_error( "La variable => " . $var . "n'est pas reconnue<br />" . __file__ . ' ligne ' . __line__ . "\n" , true, false);
}
}else {
break;
}
}
return $text;
}

View File

@ -10,8 +10,8 @@ require_once 'envoi_courriel.inc.php';
// $level => INFO, ALERT, ERROR
function log_write($log, $level=INFO)
{
require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster;
//require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster, $db;
$user = ( !empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'' );
$log_mail = str_replace ( "<br />", "\n", $log ) . "\n";
$log_mail .= ( !empty( $_SERVER["REQUEST_METHOD"])?'$_SERVER["REQUEST_METHOD"]' . $_SERVER["REQUEST_METHOD"] . "\n":'' );
@ -25,29 +25,30 @@ function log_write($log, $level=INFO)
$log_mail .= "Utilisateur: $user \n";
$log_mail .= ( !empty( $_SERVER["ORIG_PATH_INFO"])?'$_SERVER["ORIG_PATH_INFO"]' . $_SERVER["ORIG_PATH_INFO"] . "\n":'' );
$log_mail .= ( !empty( $_SERVER["PATH_INFO"])?'$_SERVER["PATH_INFO"]' . $_SERVER["PATH_INFO"] . "\n":'' );
$db1 = new db();
$db1->open();
if( !empty( $db1->connect ) )
//$db = new db();
//$db->open();
if( !empty( $db->connect ) )
{
$query = 'INSERT INTO ' . $db1->protect($table_prefix) . 'logs SET date=NOW(), auteur="' . $db1->protect( $user ) . '", log="' . $db1->protect($log) . '", niveau="' . $db1->protect($level) . '"';
$db1->query( $query );
if ( !$db1->result )
$query = 'INSERT INTO ' . $db->protect($table_prefix) . 'logs SET date=NOW(), auteur="' . $db->protect( $user ) . '", log="' . $db->protect($log) . '", niveau="' . $db->protect($level) . '"';
$db->query( $query );
if ( !$db->result )
{
$text = $db1->error() . "\n\n" . $log_mail;
envoiMail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
$text = $db->error() . "\n\n" . $log_mail;
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
}
$db1->close();
}else
{
echo $db1->error();
envoiMail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__ , $log_mail);
echo $db->error();
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__ , $log_mail);
}
//$db->close();
if ( $level == ALERT )
{
envoiMail( $webmaster, "Alerte Site Web", $log_mail );
mail( $webmaster, "Alerte Site Web", $log_mail );
}elseif ( $level == ERROR )
{
envoiMail( $webmaster, "Erreur Site Web", $log_mail );
mail( $webmaster, "Erreur Site Web", $log_mail );
}
}
@ -57,12 +58,12 @@ function log_error($log, $w_db=true, $die=false)
{
global $webmaster, $headers, $accueil, $db;
if ( $w_db ) log_write($log, ERROR);
echo "$log<br />\n";
//echo "$log<br />\n";
$log_err = 'erreur dans la requête<br/>un rapport détaillé a été envoyé au webmaster';
if ( $die )
{
echo "\n";
die( $log_err );
//echo "\n";
//die( $log_err );
}else
{
$_SESSION['error'] = $log_err;
@ -70,19 +71,20 @@ function log_error($log, $w_db=true, $die=false)
}
}
function affich_log( $nl, $np = 1, $level=INFO )
function affich_log( $nl, $np = 1, $level=0)
{
global $table_prefix, $base_url, $path, $page;
if( !empty( $db->open() ) )
$db = new db();
if( !empty( $db->connect ) )
{
$level_s = array( "aucun" , "info" , "alerte" , "erreur" );
$query = 'SELECT * FROM ' . $table_prefix . 'logs';
$query = 'SELECT * FROM ' . $table_prefix . 'logs ORDER BY id_log DESC';
if ( $level != 0 )
{
$query .= " WHERE niveau='" . $db->protect($level) . "'";
}
$db->query($query) OR log_error($db->error() . "<br />" . __file__ . " ligne " . __line__ );
$total_lignes = $db->result->num_rows();
$db->query($query);
$total_lignes = $db->result->num_rows;
if ($total_lignes != 0 )
{
@ -139,9 +141,9 @@ function affich_log( $nl, $np = 1, $level=INFO )
}
$query .= ' ORDER BY date DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl;
$db->query( $query ) OR log_error( $db->error( ) . "<br />" . __file__ . " ligne " . __line__ );
$db->query( $query );
echo "<table border='1' width='90%'><tr><td><b>date</b></td><td><b>auteur</b></td><td><b>log</b></td><td><b>niveau</b></td></tr>\n";
while ( $db->connect->mysqli_fetch_array( $db->result ) )
while ( ($donnees =$db->result->fetch_array()) )
{
$niveau = $donnees["niveau"];
echo "<tr><td>" . $donnees["date"] . "</td><td>" . $donnees["auteur"] . "</td><td>" . $donnees["log"] . "</td><td>" . $level_s[ $niveau ] . "</td></tr>\n";

View File

@ -1,88 +0,0 @@
<?php
require_once './session_init.php';
require_once 'config.inc.php';
require_once 'db.class.php';
require_once 'log.php';
$db = new db();
$db->open();
test();
//peripetieDatee();
peripeties();
function peripetieDatee()
{
global $db;
require_once 'envoi_courriel.inc.php';
$flag = false;
//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( "dtux@free.fr", $objetMail, $mailText, true);//$result['destMail']
sleep(2);
envoiMail( "dtux@free.fr", $objetMail, $mailText, true);//$result['expeMail']
sleep(2);
}
}
}
function peripeties()
{
global $db;
//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'] );
$query = "SELECT * FROM avionPeripetie LEFT JOIN peripeties USING (idPeripetie) WHERE idAvion='" . $result['idAvion'] . "'";
$dbPeripetie->query($query);
while (($peripetie =$dbPeripetie->result->fetch_assoc()))
{
print $result["destMail"] . EOL;
$indexObjet = "Objet_" . $peripetie['indexText'];
$objetMail = $dicoExpe["Objet_" . $peripetie['indexText']];
$mailText = $dicoExpe[$peripetie['indexText']] .EOL .EOL ;
print $indexObjet . EOL;
print $mailText .EOL;
//envoiMail( "dtux@free.fr", $objetMail, $mailText, true);//$result['destMail']
//sleep(2);
//envoiMail( "dtux@free.fr", $objetMail, $mailText, true);//$result['expeMail']
//sleep(2);
}
}
$dbPeripetie->close();
}
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() .EOL;
}
}
$db->close();
?>

View File

@ -17,5 +17,4 @@ error_reporting(E_ALL);
date_default_timezone_set("Europe/Paris");
set_include_path(get_include_path() . ':./include');
?>