81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
||
//Скрипт по обновлению геометрии а именно точек
|
||
|
||
require_once("../../monitoring/config.php");
|
||
|
||
function sendError($msg)
|
||
{
|
||
$json='{"errorCode":1,"errorMessage":'.json_encode($msg,JSON_UNESCAPED_UNICODE).'}';
|
||
header('Content-Type: application/json');
|
||
echo $json;
|
||
exit;
|
||
}
|
||
|
||
$db = connectToDB();
|
||
//$db->exec('SET NAMES utf8');
|
||
//$db->exec("SET time_zone = '+00:00'");
|
||
|
||
$fn=0;
|
||
if(isset($_GET['fn'])) { $fn=$_GET['fn']; }
|
||
|
||
if($fn=='1') //Перезаписать все координаты для геометрии
|
||
{
|
||
if(!isset($HTTP_RAW_POST_DATA))
|
||
{ $HTTP_RAW_POST_DATA = file_get_contents("php://input");
|
||
}
|
||
$object = json_decode($HTTP_RAW_POST_DATA);
|
||
|
||
if($object->name=="TCheckPoint")
|
||
{
|
||
$sql="update main.routes_checkpoints set geom=ST_GeomFromText('POLYGON((".$object->points."))', 4326) where id=".$object->id;
|
||
try
|
||
{
|
||
$db->query($sql);
|
||
}catch (Exception $e)
|
||
{
|
||
sendError($e->getMessage());
|
||
}
|
||
}else if($object->name=="TDetour")
|
||
{
|
||
$sql="update main.detours set geom=ST_GeomFromText('POLYGON((".$object->points."))', 4326) where id=".$object->id;
|
||
try
|
||
{
|
||
$db->query($sql);
|
||
}catch (Exception $e)
|
||
{
|
||
sendError($e->getMessage());
|
||
}
|
||
}else if($object->name=="TRoute")
|
||
{
|
||
$sql="update main.routes set geom=ST_GeomFromText('LINESTRING(".$object->points.")', 4326) where id=".$object->id;
|
||
try
|
||
{
|
||
$db->query($sql);
|
||
}catch (Exception $e)
|
||
{
|
||
sendError($e->getMessage());
|
||
}
|
||
}else if($object->name=="TGeofence")
|
||
{
|
||
$sql="update main.geofences set geom=ST_GeomFromText('POLYGON((".$object->points."))', 4326) where id=".$object->id;
|
||
try
|
||
{
|
||
$db->query($sql);
|
||
}catch (Exception $e)
|
||
{
|
||
sendError($e->getMessage());
|
||
}
|
||
}
|
||
|
||
/*json+='"id":'+feature.userFeature.userData.id+',\n';
|
||
json+='"name":"'+feature.userFeature.userData.constructor.name+'",\n';
|
||
json+='"points":"';*/
|
||
|
||
$json='{"errorCode":0}';
|
||
|
||
header('Content-Type: application/json');
|
||
echo $json;
|
||
exit;
|
||
}
|
||
|