diff --git a/inc/Feed.php b/inc/Feed.php index 22561e7..086f124 100644 --- a/inc/Feed.php +++ b/inc/Feed.php @@ -168,6 +168,31 @@ class Feed extends PhpObject { return $bNewMsg; } + public function addManualPosition($sLat, $sLng, $iTimestamp) { + $sTimeZone = date_default_timezone_get(); + $oDateTime = new \DateTime('@'.$iTimestamp); + $oDateTime->setTimezone(new \DateTimeZone($sTimeZone)); + $asWeather = $this->getWeather(array($sLat, $sLng), $iTimestamp); + + $asMsg = [ + 'ref_msg_id' => $iTimestamp.'/man', + 'id_feed' => $this->getFeedId(), + 'type' => 'OK', + 'latitude' => $sLat, + 'longitude' => $sLng, + 'iso_time' => $oDateTime->format("Y-m-d\TH:i:sO"), //Incorrect ISO 8601 format, but compliant with Spot data + 'site_time' => $oDateTime->format(Db::TIMESTAMP_FORMAT), + 'timezone' => $sTimeZone, + 'unix_time' => $iTimestamp, + 'content' => '', + 'battery_state' => '', + 'posted_on' => date(Db::TIMESTAMP_FORMAT), + ]; + + $iMessageId = $this->oDb->insertRow(self::MSG_TABLE, array_merge($asMsg, $asWeather)); + return $iMessageId; + } + private function updateFeed() { $bNewMsg = false; $asData = $this->retrieveFeed(); diff --git a/inc/Spot.php b/inc/Spot.php index 540340d..4eec823 100755 --- a/inc/Spot.php +++ b/inc/Spot.php @@ -630,6 +630,13 @@ class Spot extends Main return self::getJsonResult($asResult['result'], $asResult['desc'], $asResult['data']); } + public function addPosition($sLat, $sLng, $iTimestamp) { + $oFeed = new Feed($this->oDb, $this->oProject->getFeedIds()[0]); + $bResult = ($oFeed->addManualPosition($sLat, $sLng, $iTimestamp) > 0); + + return self::getJsonResult($bResult, $bResult?'':$this->oDb->getLastError()); + } + public function getAdminSettings($sType='') { $oFeed = new Feed($this->oDb); $asData = array( diff --git a/index.php b/index.php index f714139..ef4494b 100755 --- a/index.php +++ b/index.php @@ -25,6 +25,9 @@ $oValue = $_REQUEST['value'] ?? ''; $iId = $_REQUEST['id'] ?? 0 ; $sType = $_REQUEST['type'] ?? ''; $sEmail = $_REQUEST['email'] ?? ''; +$sLat = $_REQUEST['latitude'] ?? ''; +$sLng = $_REQUEST['longitude'] ?? ''; +$iTimestamp = $_REQUEST['timestamp'] ?? 0; //Initiate class $oSpot = new Spot(__FILE__, $sTimezone); @@ -70,6 +73,9 @@ if($sAction!='') case 'add_comment': $sResult = $oSpot->addComment($iId, $sContent); break; + case 'add_position': + $sResult = $oSpot->addPosition($sLat, $sLng, $iTimestamp); + break; case 'admin_new': $sResult = $oSpot->createProject(); break; diff --git a/masks/upload.html b/masks/upload.html index 2b4778f..5615634 100644 --- a/masks/upload.html +++ b/masks/upload.html @@ -6,6 +6,9 @@
+