diff --git a/avionJournalier.php b/avionJournalier.php
new file mode 100644
index 0000000..0245031
--- /dev/null
+++ b/avionJournalier.php
@@ -0,0 +1,11 @@
+avionJournalier();
+ $db->close();
+ print '{"nAvion":"' . $nAvion . '"}';
+?>
diff --git a/avionpoeme.php b/avionpoeme.php
index a218f2f..44520cd 100644
--- a/avionpoeme.php
+++ b/avionpoeme.php
@@ -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)
{
diff --git a/cron.php b/cron.php
new file mode 100644
index 0000000..3ee15a9
--- /dev/null
+++ b/cron.php
@@ -0,0 +1,217 @@
+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();
+?>
diff --git a/gestion/genere_lang.php b/gestion/genere_lang.php
index 7f68527..fc1cc70 100644
--- a/gestion/genere_lang.php
+++ b/gestion/genere_lang.php
@@ -1,93 +1,105 @@
";
- if ( $first_column_line == true )
+
+ $column = trim($column, " \n\r\t\0\"" );
+
+ if ($first_line == true)
{
- //echo "first_column";
- $first_column_line = false;
+ //echo "first_line =>";
+ if ( $first_column_line == true )
+ {
+ //echo "first_column";
+ $first_column_line = false;
+ }else
+ {
+
+ $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 )
+ {
+ $first_column = false;
+ }else
+ {
+ fwrite($fhIndex, ",");
+ }
+ fwrite($fhIndex, '"' . $index[0] . '":"' . $index[1] . '"');
+ }
+ echo EOLH;
}else
{
-
- $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 (!empty($fhIndex))
+ {
+ fwrite($fhIndex, '}');
+ fclose($fhIndex);
+ unset($fhIndex);
+ }
+ //echo "not first_line =>";
if ( $first_column == true )
{
$first_column = false;
+ $index = $column;
+ //echo "first_column = ". $index . "=>";
}else
{
- fwrite($fhIndex, ",");
- }
- fwrite($fhIndex, '"' . $index[0] . '":"' . $index[1] . '"');
- }
- echo EOLH;
- }else
- {
- if (!empty($fhIndex))
- {
- fwrite($fhIndex, '}');
- fclose($fhIndex);
- unset($fhIndex);
- }
- //echo "not first_line =>";
- if ( $first_column == true )
- {
- $first_column = false;
- $index = $column;
- //echo "first_column = ". $index . "=>";
- }else
- {
- $i++;
- if ($first_object == false) // insère la virgule
- {
- //echo "not first_object =>";
- fwrite($fhl[$i], ", ");
- }
- $text = '"' . $index . '":"' . $column .'"';
- fwrite($fhl[$i], $text ); //écrit l'objet json
- echo "writing ***" . $text .'***' . EOLH;
- fflush($fhl[$i]);
+ $i++;
+ if ($first_object == false) // insère la virgule
+ {
+ //echo "not first_object =>";
+ fwrite($fhl[$i], ", ");
+ }
+ $text = '"' . $index . '":"' . $column .'"';
+ fwrite($fhl[$i], $text ); //écrit l'objet json
+ echo "writing ***" . $text .'***' . EOLH;
+ fflush($fhl[$i]);
+ }
+ echo EOLH;
}
- echo EOLH;
+ //echo EOLH;
}
- //echo EOLH;
+ if ($first_line == false)
+ {
+ $first_object = false;
+ }
+ $first_line = false;
}
- if ($first_line == false)
+ fclose($fh);
+ foreach( $fhl as $fhx)
{
- $first_object = false;
+ 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;
}
- $first_line = false;
}
- fclose($fh);
- foreach( $fhl as $fhx)
- {
- fwrite($fhx, '}');
- fclose($fhx);
- }
-
?>
diff --git a/gestion/index.php b/gestion/index.php
index 871eff2..d194559 100644
--- a/gestion/index.php
+++ b/gestion/index.php
@@ -28,3 +28,4 @@
Générer les fichiers de langue
+Lire les logs
diff --git a/gestion/lang.php b/gestion/lang.php
index 2652c35..b2d3357 100644
--- a/gestion/lang.php
+++ b/gestion/lang.php
@@ -33,4 +33,4 @@
echo nl2br($text);
?>
-Générer les fichiers de langue
+Générer les fichiers de langue
diff --git a/gestion/logs.php b/gestion/logs.php
new file mode 100644
index 0000000..91744f5
--- /dev/null
+++ b/gestion/logs.php
@@ -0,0 +1,8 @@
+
diff --git a/include/config.inc.php b/include/config.inc.php
index fff7499..ff010f7 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -1,7 +1,7 @@
" );
+define( 'EOLH', "
\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;
-}
-
?>
diff --git a/include/db.class.php b/include/db.class.php
index 929b8af..eee0b60 100644
--- a/include/db.class.php
+++ b/include/db.class.php
@@ -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 . "
" . __file__ . ' ligne ' . __line__);
+ log_error( "Échec de la connexion : => " . $this->connect->connect_error . "
" . __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 deliveryTimeServerquery($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;
+ }
}
diff --git a/include/envoi_courriel.inc.php b/include/envoi_courriel.inc.php
index 9869eed..59350c7 100644
--- a/include/envoi_courriel.inc.php
+++ b/include/envoi_courriel.inc.php
@@ -1,15 +1,7 @@
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;
}
-
-
}
?>
diff --git a/include/fonctions.inc.php b/include/fonctions.inc.php
index 8eba094..ef3f93e 100644
--- a/include/fonctions.inc.php
+++ b/include/fonctions.inc.php
@@ -1,4 +1,5 @@
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
" . __file__ . ' ligne ' . __line__ . "\n" , true, false);
+ }
+ }else {
+ break;
+ }
+ }
+ return $text;
+}
diff --git a/include/log.php b/include/log.php
index 83d9d19..1f4f85a 100644
--- a/include/log.php
+++ b/include/log.php
@@ -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 ( "
", "\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
\n";
+ //echo "$log
\n";
$log_err = 'erreur dans la requête
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() . "
" . __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( ) . "
" . __file__ . " ligne " . __line__ );
+ $db->query( $query );
echo "date | auteur | log | niveau |
\n";
- while ( $db->connect->mysqli_fetch_array( $db->result ) )
+ while ( ($donnees =$db->result->fetch_array()) )
{
$niveau = $donnees["niveau"];
echo "" . $donnees["date"] . " | " . $donnees["auteur"] . " | " . $donnees["log"] . " | " . $level_s[ $niveau ] . " |
\n";
diff --git a/peripetie.cron.php b/peripetie.cron.php
deleted file mode 100644
index cd3c6bd..0000000
--- a/peripetie.cron.php
+++ /dev/null
@@ -1,88 +0,0 @@
-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();
-?>
diff --git a/session_init.php b/session_init.php
index df3cff5..462ee2f 100644
--- a/session_init.php
+++ b/session_init.php
@@ -17,5 +17,4 @@ error_reporting(E_ALL);
date_default_timezone_set("Europe/Paris");
set_include_path(get_include_path() . ':./include');
-
?>