From 6dbf315f9fa7d457bfa91ff5cda71b25323c2b99 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Thu, 25 Mar 2021 10:26:40 +0100 Subject: [PATCH] getCurrentPlane.php, getAnthology.php, avionpoeme.php fonctionnels --- avionpoeme.php | 2 +- include/db.class.php | 29 ++++++++++++----------------- session_init.php | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 session_init.php diff --git a/avionpoeme.php b/avionpoeme.php index 25fb60c..e693e5a 100644 --- a/avionpoeme.php +++ b/avionpoeme.php @@ -5,7 +5,7 @@ require_once 'log.php'; require_once 'fonctions.inc.php'; - $table=array("message", "expeMail", "expeKnown", "expeLang", "destLang", "startLat", "startLon", "startName", "startTime", "StartTZ", "destMail", "destLat", "destLon", "destName", "public", "color", "actual_lat", "actual_lon", "bearing", "deliveryTime", "deliveryTZ", "deliveryTimeServer"); + $table=array("message", "expeMail", "expeKnown", "expeLang", "destLang", "startLat", "startLon", "startName", "startTime", "startTZ", "destMail", "destLat", "destLon", "destName", "public", "color", "deliveryTime", "deliveryTZ", "deliveryTimeServer"); $db = new db(); $db->open(); diff --git a/include/db.class.php b/include/db.class.php index ee056e6..568c0ce 100644 --- a/include/db.class.php +++ b/include/db.class.php @@ -29,16 +29,13 @@ class db public $startLon; public $startName; public $startTime; - public $StartTZ; + public $startTZ; public $destMail; public $destLat; public $destLon; public $destName; public $public; public $color; - public $actual_lat; - public $actual_lon; - public $bearing; public $deliveryTime; public $deliveryTZ; public $deliveryTimeServer; @@ -96,21 +93,18 @@ class db $query .= $this->protect($this->destLang) . "', '"; $query .= $this->protect($this->startLat) . "', '"; $query .= $this->protect($this->startLon) . "', '"; - $query .= $this->protect($this->startName) . "', '"; - $query .= $this->protect($this->startTime) . "', '"; - $query .= $this->protect($this->StartTZ) . "', '"; + $query .= $this->protect($this->startName) . "', "; + $query .= "FROM_UNIXTIME(" . $this->protect($this->startTime) . "), '"; + $query .= $this->protect($this->startTZ) . "', '"; $query .= $this->protect($this->destMail) . "', '"; $query .= $this->protect($this->destLat) . "', '"; $query .= $this->protect($this->destLon) . "', '"; $query .= $this->protect($this->destName) . "', "; $query .= $this->protect($this->public) . ", '"; - $query .= $this->protect($this->color) . "', '"; - $query .= $this->protect($this->actual_lat) . "', '"; - $query .= $this->protect($this->actual_lon) . "', '"; - $query .= $this->protect($this->bearing) . "', '"; - $query .= $this->protect($this->deliveryTime) . "', '"; - $query .= $this->protect($this->deliveryTZ) . "', '"; - $query .= $this->protect($this->deliveryTimeServer) . "'"; + $query .= $this->protect($this->color) . "', "; + $query .= "FROM_UNIXTIME(" . $this->protect($this->deliveryTime) . "), '"; + $query .= $this->protect($this->deliveryTZ) . "', "; + $query .= "FROM_UNIXTIME(" . $this->protect($this->deliveryTimeServer) . ")"; $query .= ")"; print_r($this); $this->query($query); @@ -119,9 +113,10 @@ class db function getCurrentPlanes() { - $query = "SELECT deliveryTime, deliveryTZ, destLat, destLon, destName, startTime, startTZ, startLon, startLat, startName, color FROM avionpoeme WHERE deliveryTimeServer>NOW() AND public='1'"; + $query = "SELECT UNIX_TIMESTAMP(deliveryTime) as deliveryTime, deliveryTZ, destLat, destLon, destName, UNIX_TIMESTAMP(startTime) as startTime, startTZ, startLon, startLat, startName, color FROM avionpoeme WHERE deliveryTimeServer>NOW() AND public='1'"; $this->query($query); $planes = $this->result->fetch_all(MYSQLI_ASSOC); + print json_encode($planes); } @@ -130,14 +125,14 @@ class db $query = "SELECT COUNT(*) as count FROM avionpoeme WHERE public='1'"; $this->query($query); $result = $this->result->fetch_assoc(); - $n_pages = $result["count"] / RESULTS_BY_PAGE + 1; + $n_pages = round($result["count"] / RESULTS_BY_PAGE + 1, 0, PHP_ROUND_HALF_DOWN); if ($page <= 0) //renvoie le nombre de ligne d'anthologie { print '{"nAnthology":"' . $result["count"] . '","nPages":"' . $n_pages .'"}'; }else //renvoie les lignes d'anthologie { if ($page > $n_pages) $page=$n_pages; - $query = "SELECT deliveryTime, deliveryTZ, destName, startTime, startTZ, startName, message FROM avionpoeme WHERE public='1' LIMIT " . ($page-1)*RESULTS_BY_PAGE+1 . "," . RESULTS_BY_PAGE; + $query = "SELECT deliveryTime, deliveryTZ, destName, startTime, startTZ, startName, message FROM avionpoeme WHERE public='1' 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); diff --git a/session_init.php b/session_init.php new file mode 100644 index 0000000..df3cff5 --- /dev/null +++ b/session_init.php @@ -0,0 +1,21 @@ +