Add manual message upload
This commit is contained in:
25
inc/Feed.php
25
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();
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
<div class="bar" style="width: 0%;"></div>
|
||||
</div>
|
||||
<div id="comments"></div>
|
||||
<div id="location">
|
||||
<button id="add_loc"><i class="fa fa-message push"></i>New Position</button>
|
||||
</div>
|
||||
<div id="status"></div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
@@ -35,6 +38,27 @@ oSpot.pageInit = function(asHash) {
|
||||
$('#progress .bar').css('width', progress+'%');
|
||||
}
|
||||
});
|
||||
|
||||
$('#add_loc').click(() => {
|
||||
if(navigator.geolocation) {
|
||||
addStatus('Determining position...');
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
addStatus('Sending position...');
|
||||
oSpot.get(
|
||||
'add_position',
|
||||
function(asData){addStatus('Position sent');},
|
||||
{'latitude':position.coords.latitude, 'longitude':position.coords.longitude, 'timestamp':Math.round(position.timestamp / 1000)},
|
||||
function(sMsgId){addStatus(self.lang(sMsgId));},
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
addStatus(error.message);
|
||||
}
|
||||
);
|
||||
}
|
||||
else addStatus('This browser does not support geolocation');
|
||||
});
|
||||
}
|
||||
else addStatus(self.lang('upload_mode_archived', [asProject.name]), true);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user