Untitled diff

Created Diff never expires
9 removals
270 lines
19 additions
278 lines
<?php
<?php


$page= new Template();
$page= new Template();
$page->LoadFile($_SERVER['DOCUMENT_ROOT'].'/templates/'.'check-cities.html');
$page->LoadFile($_SERVER['DOCUMENT_ROOT'].'/templates/'.'check-cities.html');


preg_match('/city_start_id=([0-9]+)/ui', $_SERVER['REQUEST_URI'] ,$start);
preg_match('/city_start_id=([0-9]+)/ui', $_SERVER['REQUEST_URI'] ,$start);
preg_match('/city_end_id=([0-9]+)/ui', $_SERVER['REQUEST_URI'] ,$end);
preg_match('/city_end_id=([0-9]+)/ui', $_SERVER['REQUEST_URI'] ,$end);


$SQL="SELECT * FROM `cities` WHERE `id` IN (".$start[1].",".$end[1].") LIMIT 2";
$SQL="SELECT * FROM `cities` WHERE `id` IN (".$start[1].",".$end[1].") LIMIT 2";
$temp=get_city_data_by_sql($SQL);
$temp=get_city_data_by_sql($SQL);


$city_start=$temp[$start[1]];
$city_start=$temp[$start[1]];
$city_end=$temp[$end[1]];
$city_end=$temp[$end[1]];




unset ($temp);
unset ($temp);




$SQL="SELECT id, start_city_id, end_city_id FROM `routes` WHERE `start_city_id`=".$city_start['locality']['id']." AND `end_city_id`=".$city_end['locality']['id']." LIMIT 1";
$SQL="SELECT id, start_city_id, end_city_id FROM `routes` WHERE `start_city_id`=".$city_start['locality']['id']." AND `end_city_id`=".$city_end['locality']['id']." LIMIT 1";
$res=DB_query($SQL);
$res=DB_query($SQL);


if (mysql_num_rows($res)==0)
if (mysql_num_rows($res)==0)
{
{
$load_url='https://api-maps.yandex.ru/2.1-dev/?lang=ru-RU&load=package.full';
$load_url='https://api-maps.yandex.ru/2.1-dev/?lang=ru-RU&load=package.full';
$route_string=get_url_from_yandex($load_url, 100);
$route_string=get_url_from_yandex($load_url, 100);
preg_match_all('/project_data\[\"token\"\]\=\"([a-z0-9]*)\"/ui', $route_string,$match);
preg_match_all('/project_data\[\"token\"\]\=\"([a-z0-9]*)\"/ui', $route_string,$match);
$load_url='https://api-maps.yandex.ru/services/route/2.0/?lang=ru_RU&rll='.$city_start['locality']['x'].','.$city_start['locality']['y'].'~'.$city_end['locality']['x'].','.$city_end['locality']['y'].'&token='.$match[1][0];
$load_url='https://api-maps.yandex.ru/services/route/2.0/?lang=ru_RU&rll='.$city_start['locality']['x'].','.$city_start['locality']['y'].'~'.$city_end['locality']['x'].','.$city_end['locality']['y'].'&token='.$match[1][0];
$route_string=get_url_from_yandex($load_url, 100);
$route_string=get_url_from_yandex($load_url, 100);
if ($route_string!='')
if ($route_string!='')
{
{
$json_route=json_decode($route_string);
$json_route=json_decode($route_string);
if (isset($json_route->error->status))
if (isset($json_route->error->status))
{
{
$page->ReplaceBlock('normal_content', '');
$page->ReplaceBlock('normal_content', '');
$page->Replace('<alert_content>', '');
$page->Replace('<alert_content>', '');
$page->Replace('</alert_content>', '');
$page->Replace('</alert_content>', '');
$page->Replace('{:ALERT_MESSAGE:}', 'Code '.$json_route->error->status.':<BR>"'.$json_route->error->message.'"');
$page->Replace('{:ALERT_MESSAGE:}', 'Code '.$json_route->error->status.':<BR>"'.$json_route->error->message.'"');
} else {
} else {
$coords = $json_route->data->features[0]->features[0]->properties->encodedCoordinates;
$key = 'jNr34oE0';
$curl_decoder = curl_init();
curl_setopt($curl_decoder, CURLOPT_URL, 'http://wotgame.ninja/api/$key/decode');
curl_setopt($curl_decoder, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_decoder, CURLOPT_POST, true);
curl_setopt($curl_decoder, CURLOPT_POSTFIELDS, "coord_string=$coords");
$decoded_coords = json_decode(curl_exec($curl_decoder));
curl_close($curl_decoder);
$route_lengh=round($json_route->data->features[0]->properties->RouteMetaData->Distance->value);
$route_lengh=round($json_route->data->features[0]->properties->RouteMetaData->Distance->value);
$route_time=round($json_route->data->features[0]->properties->RouteMetaData->Duration->value);
$route_time=round($json_route->data->features[0]->properties->RouteMetaData->Duration->value);
$route_bound[0][0]=$json_route->data->features[0]->properties->boundedBy[0][0];
$route_bound[0][0]=$json_route->data->features[0]->properties->boundedBy[0][0];
$route_bound[0][1]=$json_route->data->features[0]->properties->boundedBy[0][1];
$route_bound[0][1]=$json_route->data->features[0]->properties->boundedBy[0][1];
$route_bound[1][0]=$json_route->data->features[0]->properties->boundedBy[1][0];
$route_bound[1][0]=$json_route->data->features[0]->properties->boundedBy[1][0];
$route_bound[1][1]=$json_route->data->features[0]->properties->boundedBy[1][1];
$route_bound[1][1]=$json_route->data->features[0]->properties->boundedBy[1][1];


$full_route=Array();
$full_route=Array();
foreach ($json_route->data->features[0]->features[0]->features as $feature)
foreach ($json_route->data->features[0]->features[0]->features as $feature)
{
{
$value = $feature->properties;
$value = $feature->properties;
$value_array=Array();
$value_array=Array();


$value_array['street']=str_replace("'",' ',$value->SegmentMetaData->street);
$value_array['street']=str_replace("'",' ',$value->SegmentMetaData->street);
$value_array['action']=$value->SegmentMetaData->action;
$value_array['action']=$value->SegmentMetaData->action;
$value_array['angle']=$value->SegmentMetaData->angle;
$value_array['angle']=$value->SegmentMetaData->angle;
$value_array['length']=round($value->SegmentMetaData->Distance->value);
$value_array['length']=round($value->SegmentMetaData->Distance->value);
$value_array['time']=round($value->SegmentMetaData->Duration->value);
$value_array['time']=round($value->SegmentMetaData->Duration->value);
// geometry seems to be passed in a separate encoded string, providing only link to it
// empty data for now
$lodIndex = $feature->geometry->geometries[0]->lodIndex;
$value_array['start_x_y']=$value->boundedBy[0][0].','.$feature->geometry->boundedBy[0][1];
$value_array['start_x_y']=$value->boundedBy[0][0].','.$feature->geometry->boundedBy[0][1]; $value_array['start_x_y'] = implode(',', $decoded_coords[$lodIndex]);
$value_array['end_x_y']=$value->boundedBy[1][0].','.$value->properties->boundedBy[1][1];
$value_array['end_x_y']=$value->boundedBy[1][0].','.$value->properties->boundedBy[1][1]; $value_array['end_x_y'] = implode(',', $decoded_coords[$lodIndex+1]);
$full_route[]=$value_array;
}
}
$point_array=Array();
$point_array=Array();
foreach ($full_route AS $key=>$value)
foreach ($full_route AS $key=>$value)
{
{
$temp_start=explode(',',$value['start_x_y']);
$temp_start=explode(',',$value['start_x_y']);
$temp_array[0]=$temp_start[0];
$temp_array[0]=$temp_start[0];
$temp_array[1]=$temp_start[1];
$temp_array[1]=$temp_start[1];
$temp_array[2]=$value['length'];
$temp_array[2]=$value['length'];
$temp_array[3]=$value['time'];
$temp_array[3]=$value['time'];
$point_array[]=$temp_array;
$point_array[]=$temp_array;
$temp_end=explode(',',$value['end_x_y']);
$temp_end=explode(',',$value['end_x_y']);
$end_array[0]=$temp_end[0];
$end_array[0]=$temp_end[0];
$end_array[1]=$temp_end[1];
$end_array[1]=$temp_end[1];
$end_array[2]=0;
$end_array[2]=0;
$end_array[3]=0;
$end_array[3]=0;
}
}
$point_array[]=$end_array;
$point_array[]=$end_array;
$prev_x=$point_array[0][0];
$prev_x=$point_array[0][0];
$prev_y=$point_array[0][1];
$prev_y=$point_array[0][1];
$tmp_this_len=0;
$tmp_this_len=0;
$tmp_this_time=0;
$tmp_this_time=0;
$array_new_points=array();
$array_new_points=array();
foreach ($point_array as $value)
foreach ($point_array as $value)
{
{