Files
2023-11-07 19:51:49 +06:00

81 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}