2021-04-07
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
define( 'EOL', "\n" );
|
||||
define( 'EOLH', "</br>" );
|
||||
define( 'LF', "\r\n" );
|
||||
define( 'TAB', "\t" );
|
||||
|
||||
|
@@ -7,6 +7,7 @@ if ( !isset($site) )
|
||||
|
||||
require_once "config.inc.php";
|
||||
require_once "log.php";
|
||||
require_once "envoi_courriel.inc.php";
|
||||
|
||||
$table_prefix = "";
|
||||
class db
|
||||
@@ -110,14 +111,14 @@ class db
|
||||
$query .= "FROM_UNIXTIME(" . $this->protect($this->deliveryTime) . "), '";
|
||||
$query .= $this->protect($this->deliveryTZ) . "', ";
|
||||
$query .= "FROM_UNIXTIME(" . $this->protect($this->deliveryTimeServer) . "), '";
|
||||
$query .= $this->protect($this->deliveryMethod) . "'";
|
||||
$query .= ")";
|
||||
$query .= $this->protect($this->deliveryMethod) . "','";
|
||||
$query .= "0')";
|
||||
//print_r($this);
|
||||
$this->query($query);
|
||||
$this->uid = $this->connect->insert_id;
|
||||
echo "{'uid':'" . $this->uid . "'}";
|
||||
|
||||
//newPeripetie($uid);
|
||||
courrielEnvoi($this);
|
||||
$this->newPeripetie();
|
||||
}
|
||||
|
||||
function getCurrentPlanes()
|
||||
@@ -142,7 +143,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 ASC 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 startTime 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);
|
||||
@@ -154,39 +155,37 @@ class db
|
||||
{
|
||||
global $db;
|
||||
$query = "INSERT INTO avionPeripetie VALUES ('0','";
|
||||
$query .= $this->protect($this->uid) . ",'";
|
||||
$query .= $this->protect($this->idPeripetie) . "', '";
|
||||
$query .= $this->protect($this->datePeripetie) . "', '";
|
||||
$query .= $this->protect($this->effetPeripetie) . "', '";
|
||||
$query .= $this->protect($this->expeMail) . "', '";
|
||||
$query .= $this->protect($this->destMail) . "')";
|
||||
echo $query;
|
||||
//$this->query($query);
|
||||
$query .= $this->protect($this->uid) . "','";
|
||||
$query .= $this->protect($this->idPeripetie) . "', ";
|
||||
$query .= "FROM_UNIXTIME(" . $this->protect($this->datePeripetie) . "))";
|
||||
//$query .= $this->protect($this->effetPeripetie) . "', '";
|
||||
//$query .= $this->protect($this->expeMail) . "', '";
|
||||
//$query .= $this->protect($this->destMail) . "')"; echo $query . EOL;
|
||||
$this->query($query);
|
||||
}
|
||||
|
||||
function newPeripetie()
|
||||
{
|
||||
global $db;
|
||||
mt_getrandmax ( );
|
||||
$query = "SELECT COUNT(*) as count FROM peripeties";
|
||||
|
||||
$query = "SELECT *, DATEDIFF(quand,CURDATE()) as datePeripetie FROM peripeties WHERE quand IS NULL";
|
||||
echo $query .EOL;
|
||||
$this->query($query);
|
||||
$result = $this->result->fetch_assoc();
|
||||
$db->idPeripetie = round(mt_rand(1,$result["count"]));
|
||||
$query = "SELECT * FROM peripeties WHERE idPeripetie='" . $db->idPeripetie . "'";
|
||||
$query = "SELECT COUNT(*) as count FROM peripeties";
|
||||
$this->query($query);
|
||||
$result = $this->result->fetch_assoc();
|
||||
//calcul de la probabilité de la péripétie
|
||||
|
||||
|
||||
//ajustement de l'effet
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$this->savePeripetie();
|
||||
$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 . "===>";
|
||||
$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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,46 @@
|
||||
<?php
|
||||
require_once 'log.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 )
|
||||
{
|
||||
$dicoExpe = getLang( $db->expeLang );
|
||||
$dicoDest = getLang( $db->destLang );
|
||||
$expediteurIndex = "Notification_denvoi_Expediteur";
|
||||
//print "envoi du courriel" . EOL;
|
||||
if ( $db->expeKnown == false )
|
||||
{
|
||||
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
|
||||
}else
|
||||
{
|
||||
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
|
||||
}
|
||||
$indexObjet = "Objet_" . $expediteurIndex;
|
||||
$objetMail = $dicoExpe[$indexObjet];
|
||||
$mailText = $dicoExpe[$expediteurIndex] .EOL .EOL ;
|
||||
|
||||
envoiMail( $db->expeMail, $objetMail, $mailText, true);
|
||||
|
||||
$indexObjet = "Objet_" . $destinataireIndex;
|
||||
$objetMail = $dicoExpe[$indexObjet];
|
||||
$mailText = $dicoExpe[$destinataireIndex] .EOL .EOL ;
|
||||
//sleep (1);
|
||||
envoiMail( $db->destMail, $objetMail, $mailText, true);
|
||||
}
|
||||
|
||||
function courrielArrivee($uid)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
function envoiMail($destinataire, $sujet, $text, $html=false)
|
||||
{
|
||||
@@ -16,16 +56,17 @@ function envoiMail($destinataire, $sujet, $text, $html=false)
|
||||
$headers .= "DATE: " . date( 'r' ) . LF . LF;
|
||||
|
||||
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $text . "sujet:" . $sujet, INFO);
|
||||
if( !mail($destinataire, $sujet, $text, $headers) ) //Sending mail
|
||||
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;
|
||||
}else
|
||||
{
|
||||
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel avec les pièces jointes est parti:" .$text . EOL, INFO);
|
||||
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel est parti:" .$text . EOL, INFO);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -8,7 +8,7 @@ if ( !isset($site) )
|
||||
// $default valeur retournée si aucune valeur n'est trouvée
|
||||
// $session: si true, rechercher aussi dans $_SESSION
|
||||
|
||||
function getpost( $var, $default="", $session=false )
|
||||
function getpost( $var )
|
||||
{
|
||||
//echo '$var =>' . $var . "<br />";
|
||||
if ( isset($_GET[$var]) )
|
||||
@@ -22,14 +22,7 @@ function getpost( $var, $default="", $session=false )
|
||||
return $_POST[$var];
|
||||
}else
|
||||
{
|
||||
if ( isset($_SESSION[$var]) AND $session==true )
|
||||
{
|
||||
return $_SESSION[$var];
|
||||
}else
|
||||
{
|
||||
//echo 'default -> $var =>' . $var . "<br />";
|
||||
return $default;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user