1
0

Merge branch 'fix-bug-button-header' of DTux/avion-poeme into master

This commit is contained in:
mathieu_berard 2021-12-14 21:40:01 +00:00 committed by Gogs
commit 8429233511
8 changed files with 54919 additions and 620 deletions

54004
dist/html2pdf/html2pdf.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,7 @@
<?php <?php
if ( !isset($site) ) if (!isset($site)) {
{ require_once("config.inc.php");
require_once( "config.inc.php" ); header('Location: ' . $accueil);
header( 'Location: ' . $accueil );
} }
require_once "config.inc.php"; require_once "config.inc.php";
@ -13,13 +12,13 @@ require_once "envoi_courriel.inc.php";
$table_prefix = ""; $table_prefix = "";
class db class db
{ {
private $server = "db351634-avionpoeme.sql-pro.online.net"; private $server = "db351634-avionpoeme.sql-pro.online.net";
private $port = 3306; private $port = 3306;
private $user = "db120904"; private $user = "db120904";
private $passwd = "AvionPoème*DB"; private $passwd = "AvionPoème*DB";
private $database = "db351634_avionpoeme"; private $database = "db351634_avionpoeme";
public $connect; public $connect;
public $result; public $result;
// avion // avion
public $uid; public $uid;
public $message; public $message;
@ -52,56 +51,53 @@ class db
public $datePeripetie; public $datePeripetie;
public $effetPeripetie; public $effetPeripetie;
function __construct() function __construct()
{ {
$this->open(); $this->open();
} }
function open() function open()
{ {
if ( !$this->connect ) if (!$this->connect) {
{ $this->connect = new mysqli($this->server, $this->user, $this->passwd, $this->database);
$this->connect = new mysqli( $this->server, $this->user, $this->passwd, $this->database ); if ($this->connect->connect_errno) {
if ( $this->connect->connect_errno ) log_error("Échec de la connexion : => " . $this->connect->connect_error . "<br />" . __file__ . ' ligne ' . __line__, false, false);
{
log_error( "Échec de la connexion : => " . $this->connect->connect_error . "<br />" . __file__ . ' ligne ' . __line__, false,false);
return false; return false;
} }
} }
$this->connect->set_charset("utf8"); $this->connect->set_charset("utf8");
return true; return true;
} }
function close() function close()
{ {
$this->connect->close(); $this->connect->close();
$this->connect = 0; $this->connect = 0;
} }
function protect( $string ) function protect($string)
{ {
return $this->connect->real_escape_string( $string ); return $this->connect->real_escape_string($string);
} }
function query( $string ) function query($string)
{ {
//log_write( $string ); //log_write( $string );
if ( empty( $this->connect ) ) $this->open(); if (empty($this->connect)) $this->open();
$this->result = $this->connect->query( $string ) ; $this->result = $this->connect->query($string);
if ( $this->connect->errno > 0 ) log_error( "Échec de la commande query => " . $this->connect->error . "<br />" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false); if ($this->connect->errno > 0) log_error("Échec de la commande query => " . $this->connect->error . "<br />" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false);
//print_r( $this ); //print_r( $this );
} }
function newPlane() //return 0 on error function newPlane() //return 0 on error
{ {
global $base_url; global $base_url;
if (round($this->startLat,3,PHP_ROUND_HALF_DOWN)==round($this->destLat,3,PHP_ROUND_HALF_DOWN) && round($this->startLon,3,PHP_ROUND_HALF_DOWN)==round($this->destLon,3,PHP_ROUND_HALF_DOWN)) if (round($this->startLat, 3, PHP_ROUND_HALF_DOWN) == round($this->destLat, 3, PHP_ROUND_HALF_DOWN) && round($this->startLon, 3, PHP_ROUND_HALF_DOWN) == round($this->destLon, 3, PHP_ROUND_HALF_DOWN)) {
{ $this->destLon += 0.001;
$this->destLon+=0.001; $this->destLat += 0.001;
$this->destLat+=0.001;
} }
$query = "INSERT INTO avionpoeme VALUES ('0','"; $query = "INSERT INTO avionpoeme VALUES ('0','";
$query .= $this->protect($this->message) . "', '"; $query .= $this->protect($this->message) . "', '";
@ -128,18 +124,17 @@ class db
$this->query($query); $this->query($query);
$this->uid = $this->connect->insert_id; $this->uid = $this->connect->insert_id;
echo "{'uid':'" . $this->uid . "'}"; echo "{'uid':'" . $this->uid . "'}";
$this->startTimeRFC822 = formatteDate( $this->expeLang, $this->startTime, $this->startTZ); $this->startTimeRFC822 = formatteDate($this->expeLang, $this->startTime, $this->startTZ);
$this->deliveryTimeRFC822 = formatteDate( $this->destLang, $this->deliveryTime, $this->deliveryTZ ); $this->deliveryTimeRFC822 = formatteDate($this->destLang, $this->deliveryTime, $this->deliveryTZ);
$this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid; $this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid;
$this->newPeripetie(); $this->newPeripetie();
courrielEnvoi($this); courrielEnvoi($this);
}
}
function getPlane($uid) function getPlane($uid)
{ {
global $base_url; 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 ."'"; $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); $this->query($query);
$plane = $this->result->fetch_array(MYSQLI_ASSOC); $plane = $this->result->fetch_array(MYSQLI_ASSOC);
$this->message = $plane["message"]; $this->message = $plane["message"];
@ -152,7 +147,7 @@ class db
$this->startName = $plane["startName"]; $this->startName = $plane["startName"];
$this->startTime = $plane["startTime"]; $this->startTime = $plane["startTime"];
$this->startTZ = $plane["startTZ"]; $this->startTZ = $plane["startTZ"];
$this->startTimeRFC822 = formatteDate( $this->expeLang, $this->startTime, $this->startTZ); $this->startTimeRFC822 = formatteDate($this->expeLang, $this->startTime, $this->startTZ);
$this->destMail = $plane["destMail"]; $this->destMail = $plane["destMail"];
$this->destLat = $plane["destLat"]; $this->destLat = $plane["destLat"];
$this->destLon = $plane["destLon"]; $this->destLon = $plane["destLon"];
@ -160,7 +155,7 @@ class db
$this->color = $plane["color"]; $this->color = $plane["color"];
$this->deliveryTime = $plane["deliveryTime"]; $this->deliveryTime = $plane["deliveryTime"];
$this->deliveryTZ = $plane["deliveryTZ"]; $this->deliveryTZ = $plane["deliveryTZ"];
$this->deliveryTimeRFC822 = formatteDate( $this->destLang, $this->deliveryTime, $this->deliveryTZ ); $this->deliveryTimeRFC822 = formatteDate($this->destLang, $this->deliveryTime, $this->deliveryTZ);
$this->deliveryTimeServer = $plane["deliveryTimeServer"]; $this->deliveryTimeServer = $plane["deliveryTimeServer"];
$this->deliveryMethod = $plane["deliveryMethod"]; $this->deliveryMethod = $plane["deliveryMethod"];
$this->public = $plane["public"]; $this->public = $plane["public"];
@ -168,9 +163,9 @@ class db
$this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid; $this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid;
} }
function getCurrentPlanes() function getCurrentPlanes()
{ {
$query = "SELECT idAvion as uid, UNIX_TIMESTAMP(deliveryTime) as deliveryTime, deliveryTZ, destLat, destLon, destName, message, UNIX_TIMESTAMP(startTime) as startTime, startTZ, startLon, startLat, startName, color, message FROM avionpoeme WHERE deliveryTimeServer>NOW()"; $query = "SELECT idAvion as uid, UNIX_TIMESTAMP(deliveryTime) as deliveryTime, deliveryTZ, destLat, destLon, destName, destMail, message, expeMail, deliveryTimeServer, deliveryMethod, UNIX_TIMESTAMP(startTime) as startTime, startTZ, startLon, startLat, startName, color, message FROM avionpoeme WHERE deliveryTimeServer>NOW()";
$this->query($query); $this->query($query);
$planes = $this->result->fetch_all(MYSQLI_ASSOC); $planes = $this->result->fetch_all(MYSQLI_ASSOC);
print json_encode($planes); print json_encode($planes);
@ -178,20 +173,20 @@ class db
return $planes; return $planes;
} }
function getAnthology($page=0) function getAnthology($page = 0)
{ {
$query = "SELECT COUNT(*) as count FROM avionpoeme WHERE deliveryTimeServer<NOW() AND public='1'"; $query = "SELECT COUNT(*) as count FROM avionpoeme WHERE deliveryTimeServer<NOW() AND public='1'";
$this->query($query); $this->query($query);
$result = $this->result->fetch_assoc(); $result = $this->result->fetch_assoc();
$n_pages = floor(($result["count"] / RESULTS_BY_PAGE))+1; $n_pages = floor(($result["count"] / RESULTS_BY_PAGE)) + 1;
if ($page <= 0) //renvoie le nombre de ligne d'anthologie if ($page <= 0) //renvoie le nombre de ligne d'anthologie
{ {
print '{"nAnthology":"' . $result["count"] . '","nPages":"' . $n_pages .'"}'; print '{"nAnthology":"' . $result["count"] . '","nPages":"' . $n_pages . '"}';
return $n_pages; return $n_pages;
}else //renvoie les lignes d'anthologie } else //renvoie les lignes d'anthologie
{ {
if ($page > $n_pages) $page=$n_pages; 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 deliveryTime 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); $this->query($query);
$planes = $this->result->fetch_all(MYSQLI_ASSOC); $planes = $this->result->fetch_all(MYSQLI_ASSOC);
print json_encode($planes, JSON_FORCE_OBJECT); print json_encode($planes, JSON_FORCE_OBJECT);
@ -217,10 +212,9 @@ class db
{ {
$query = "SELECT *, DATEDIFF(quand,CURDATE()) as datePeripetie FROM peripeties WHERE quand IS NULL"; $query = "SELECT *, DATEDIFF(quand,CURDATE()) as datePeripetie FROM peripeties WHERE quand IS NULL";
$this->query($query); $this->query($query);
while ( ($result = $this->result->fetch_assoc()) ) while (($result = $this->result->fetch_assoc())) {
{
$this->idPeripetie = $result["idPeripetie"]; $this->idPeripetie = $result["idPeripetie"];
if ((mt_rand(0,100) <= $result["probabilite"])) //calcul de la probabilité de la péripétie if ((mt_rand(0, 100) <= $result["probabilite"])) //calcul de la probabilité de la péripétie
{ {
log_write("newPeripetie"); log_write("newPeripetie");
$this->datePeripetie = mt_rand($this->startTime, $this->deliveryTime); //ajustement de l'effet $this->datePeripetie = mt_rand($this->startTime, $this->deliveryTime); //ajustement de l'effet

View File

@ -133,13 +133,14 @@
</div> </div>
</div> </div>
</div> </div>
<div id="closePlane"></div>
<div id="downloadPlaneMessage" class="btn btn-outline-primary">Télécharger l'avion-poème</div>
<script src="src/map.js"></script> <script src="src/map.js"></script>
<script src="src/geocoder.js"></script> <script src="src/geocoder.js"></script>
<script src="src/paperPlaneAnimation.js"></script> <script src="src/paperPlaneAnimation.js"></script>
<script src="src/formValidation.js"></script> <script src="src/formValidation.js"></script>
<script src="src/newPlane.js"></script> <script src="src/newPlane.js"></script>
<script src="src/translation.js"></script> <script src="src/translation.js"></script>
<script src="src/anthology.js"></script>
</body> </body>
</html> </html>

View File

@ -33,4 +33,5 @@
<script src="dist/rasterizeHTML/rasterizeHTML.allinone.js"></script> <script src="dist/rasterizeHTML/rasterizeHTML.allinone.js"></script>
<script src="dist/leaflet-locatecontrol/L.Control.Locate.min.js"></script> <script src="dist/leaflet-locatecontrol/L.Control.Locate.min.js"></script>
<script src='dist/leaflet-fullscreen/Leaflet.fullscreen.min.js'></script> <script src='dist/leaflet-fullscreen/Leaflet.fullscreen.min.js'></script>
<script src='dist/html2pdf/html2pdf.bundle.min.js'></script>
</head> </head>

View File

@ -1,79 +1,136 @@
function flightTime(a,b){ function flightTime(a, b) {
var days = Math.round((b-a)/86400 * 100) / 100 var days = Math.round(((b - a) / 86400) * 100) / 100;
var months = Math.round(days/30) var months = Math.round(days / 30);
var years = Math.round(months/12) var years = Math.round(months / 12);
if (days < 30){ if (days < 30) {
return ""+days+" "+dictionnary.jours return "" + days + " " + dictionnary.jours;
} } else if (days >= 30 && days < 365) {
else if (days >= 30 && days < 365){ if (months > 1) {
if(months>1){ return "" + months + " " + dictionnary.mois_pluriel;
return ""+months+" "+dictionnary.mois_pluriel } else {
} return "" + months + " " + dictionnary.mois;
else{ }
return ""+months+" "+dictionnary.mois } else if (days >= 365) {
} if (years > 1) {
} return "" + years + " " + dictionnary.ans;
else if (days >= 365){ } else {
if(years>1){ return "" + years + " " + dictionnary.an;
return ""+years+" "+dictionnary.ans }
} }
else{
return ""+years+" "+dictionnary.an
}
}
} }
//load //load
var nPages; var nPages;
var nPagesLoaded = 1 var nPagesLoaded = 1;
$.post( "getAnthology.php", function(pages) { $.post("getAnthology.php", function (pages) {
pages = $.parseJSON(pages) pages = $.parseJSON(pages);
nPages = Number(pages.nPages) nPages = Number(pages.nPages);
})
function displayAnthology(){ // clean and display first page
$("#anthologyItems").html('')
nPagesLoaded = 1
$.post( "getAnthology.php?page=1", function(result) {
results = $.parseJSON(result)
var momentLocale = lang;
if (momentLocale == 'zh'){momentLocale = 'zh-cn'} //troubleshot for chinese
moment.locale(momentLocale)
for (var i in results){
addAnthologyLine(results[i])
}
})
}
$( "#anthology" ).scroll(function() {
if($("#anthology").scrollTop() + 700 > $("#anthologyItems").height()){
if (nPagesLoaded < nPages){
nPagesLoaded++
console.log('Loading anthology page '+nPagesLoaded+'/'+nPages)
$.post( "getAnthology.php?page="+nPagesLoaded+"", function(result) {
results = $.parseJSON(result)
var momentLocale = lang;
if (momentLocale == 'zh'){momentLocale = 'zh-cn'} //troubleshot for chinese
moment.locale(momentLocale)
for (var i in results){
addAnthologyLine(results[i])
}
})
}
}
}); });
function addAnthologyLine(results){ function displayAnthology() {
if (lang == 'ar'){ // arabic : rtl + add <br> // clean and display first page
$("#anthologyItems").append( $("#anthologyItems").html("");
'<small style="float:right">'+dictionnary.origine+': <b>'+results.startName+'</b> &bull; '+dictionnary.destination+': <b>'+results.destName+'</b> &bull; '+dictionnary.date_arrivee+': <b>'+moment(Number(results.deliveryTime)*1000).format('LL')+'</b> &bull; '+dictionnary.temps_de_vol+': <b>'+flightTime(Number(results.startTime),Number(results.deliveryTime))+'</b></small><br><br>'+results.message+'<br><hr><br>' nPagesLoaded = 1;
) $.post("getAnthology.php?page=1", function (result) {
} results = $.parseJSON(result);
else{ var momentLocale = lang;
$("#anthologyItems").append( if (momentLocale == "zh") {
'<small>'+dictionnary.origine+': <b>'+results.startName+'</b> &bull; '+dictionnary.destination+': <b>'+results.destName+'</b> &bull; '+dictionnary.date_arrivee+': <b>'+moment(Number(results.deliveryTime)*1000).format('LL')+'</b> &bull; '+dictionnary.temps_de_vol+': <b>'+flightTime(Number(results.startTime),Number(results.deliveryTime))+'</b></small><br><br>'+results.message+'<br><hr><br>' momentLocale = "zh-cn";
) } //troubleshot for chinese
} moment.locale(momentLocale);
for (var i in results) {
addAnthologyLine(results[i]);
}
});
} }
$("#anthology").scroll(function () {
if ($("#anthology").scrollTop() + 700 > $("#anthologyItems").height()) {
if (nPagesLoaded < nPages) {
nPagesLoaded++;
console.log("Loading anthology page " + nPagesLoaded + "/" + nPages);
$.post("getAnthology.php?page=" + nPagesLoaded + "", function (result) {
results = $.parseJSON(result);
var momentLocale = lang;
if (momentLocale == "zh") {
momentLocale = "zh-cn";
} //troubleshot for chinese
moment.locale(momentLocale);
for (var i in results) {
addAnthologyLine(results[i]);
}
});
}
}
});
function addAnthologyLine(results) {
if (lang == "ar") {
// arabic : rtl + add <br>
$("#anthologyItems").append(
'<small style="float:right">' +
dictionnary.origine +
": <b>" +
results.startName +
"</b> &bull; " +
dictionnary.destination +
": <b>" +
results.destName +
"</b> &bull; " +
dictionnary.date_arrivee +
": <b>" +
moment(Number(results.deliveryTime) * 1000).format("LL") +
"</b> &bull; " +
dictionnary.temps_de_vol +
": <b>" +
flightTime(Number(results.startTime), Number(results.deliveryTime)) +
"</b></small><br><br>" +
results.message +
"<br><hr><br>"
);
} else {
$("#anthologyItems").append(
"<small>" +
dictionnary.origine +
": <b>" +
results.startName +
"</b> &bull; " +
dictionnary.destination +
": <b>" +
results.destName +
"</b> &bull; " +
dictionnary.date_arrivee +
": <b>" +
moment(Number(results.deliveryTime) * 1000).format("LL") +
"</b> &bull; " +
dictionnary.temps_de_vol +
": <b>" +
flightTime(Number(results.startTime), Number(results.deliveryTime)) +
"</b></small><br><br>" +
results.message +
"<br><hr><br>"
);
}
}
$.post("avionJournalier.php", function (result) {
result = result.replace(/'/g, '"');
result = $.parseJSON(result);
nbPlane = Number(result.nAvion);
console.log(result);
$("#buttonNewPlane").val(
"Lancer un avion-poème " + Number(result.nAvion) + "/100"
);
$("#buttonNewPlane").on("click", () => {
window.location.replace("/");
});
});
$(document).ready(function () {
$.getJSON("lang/" + lang + "", function (s) {
displayAnthology();
$("#anthologyTitle").html(s.anthologie);
$("#anthologyDisclaimer").html(s.suppr_message_public);
$("#closeAnthologyAbout").html(s.retour_carte);
});
});

View File

@ -337,6 +337,49 @@ a#navbarDropdownLang.nav-link.dropdown-toggle::after {
} }
} }
.custom-file-label {
text-overflow: ellipsis;
overflow: hidden;
width: 100%;
padding-right: 9em;
white-space: nowrap;
}
.custom-file-label::after { .custom-file-label::after {
content: attr(data-after); content: attr(data-after);
} }
#closePlane {
position: fixed;
top: 70px;
right: 40px;
visibility: hidden;
opacity: 0;
cursor: pointer;
z-index: 10000;
}
#closePlane:before {
content: "\f00d";
font-family: "Font Awesome 5 Pro";
color: white;
font-size: 3em;
}
#downloadPlaneMessage {
position: fixed;
z-index: 10000;
bottom: 5%;
left: 50%;
transform: translateX(-50%);
color: var(--primary);
background-color: white;
opacity: 0;
visibility: hidden;
}
#downloadPlaneMessage:before {
content: "\f019";
font-family: "Font Awesome 5 Pro";
color: var(--primary);
margin-right: 10px;
}

1158
src/map.js

File diff suppressed because it is too large Load Diff

View File

@ -104,13 +104,7 @@ function translateUI(l) {
$("#navTitle").html(s.avionpoeme); $("#navTitle").html(s.avionpoeme);
$("#buttonAnthology").html(s.anthologie); $("#buttonAnthology").html(s.anthologie);
$("#buttonAbout").html(s.apropos); $("#buttonAbout").html(s.apropos);
if (typeof nbPlane !== "undefined") { $("#buttonNewPlane").val(s.lancer_avion + " " + nbPlane + "/100");
$("#buttonNewPlane").val(s.lancer_avion + " " + nbPlane + "/100");
} else {
$("#buttonNewPlane").on("click", () => {
window.location.replace("/");
});
}
//new plane form //new plane form
$("#newPlaneModalTitle").html(s.lancer_avion); $("#newPlaneModalTitle").html(s.lancer_avion);
$("#newPlaneModalMessage").html(s.message); $("#newPlaneModalMessage").html(s.message);
@ -139,11 +133,6 @@ function translateUI(l) {
$("#publicTooltip").attr("title", s.public_tooltip).tooltip("_fixTitle"); $("#publicTooltip").attr("title", s.public_tooltip).tooltip("_fixTitle");
$('#selectDestLang option[value="' + lang + '"]').prop("selected", true); //selecting by default recipient language same as interface $('#selectDestLang option[value="' + lang + '"]').prop("selected", true); //selecting by default recipient language same as interface
//Anthology
displayAnthology();
$("#anthologyTitle").html(s.anthologie);
$("#anthologyDisclaimer").html(s.suppr_message_public);
$("#closeAnthologyAbout").html(s.retour_carte);
//About //About
$("#aboutTitle").html(s.apropos); $("#aboutTitle").html(s.apropos);