exec('SET NAMES utf8'); //$db->exec("SET time_zone = '+00:00'"); $fn=0; if(isset($_GET['fn'])) { $fn=$_GET['fn']; } if($fn=='0') //Вернуть список маршрутов { $sql = ' SELECT id ,name ,ST_NPoints(geom) as count FROM main.routes ORDER BY name; '; try { $res = $db->query($sql); }catch (Exception $e) { echo $e->getMessage(); $res = null; } //Массив объектов $json ='['; //Перебираю и последовательно отправляю не отправленные пломбы while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $json .="\n"; $json .='{'; $json .='"id":"'.$row['id']."\",\n"; $json .='"name":"'.$row['name']."\",\n"; $json .='"count":"'.$row['count']."\"\n"; $json .='},'; } if($json[strlen($json) - 1]==','){ $json=substr ( $json , 0, strlen($json)-1 ); } $json .=']'; header('Content-Type: application/json'); echo $json; }else if($fn=='1') //Вернуть GEOJSON по ID записи { if(!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("php://input"); } $object = json_decode($HTTP_RAW_POST_DATA); if($object->id=='') $object->id='null'; /*if($object->cnumber=='') $object->cnumber='null'; else $object->cnumber='"%'.$object->cnumber.'%"'; //Гос. номер if($object->tnumber=='') $object->tnumber='null'; else $object->tnumber='"%'.$object->tnumber.'%"'; //Номер ТД if($object->country_seal_begin=='') $object->country_seal_begin='null'; //Страна пломб. if($object->country_seal_end=='') $object->country_seal_end='null'; //Страна распломб.*/ //Выбираю геометрию $sql="select ST_AsGeoJSON(geom,3,0) as geom from main.routes where id=".$object->id.";"; try { $res = $db->query($sql); }catch (Exception $e) { echo $e->getMessage(); $res = null; } $json="{}"; if($res!=NULL && $res->rowCount()>0) { while ($row = $res->fetch(PDO::FETCH_NUM)) { $json=$row[0]; } } header('Content-Type: application/json'); echo $json; exit; }else { echo 'fn is null'; }