distancefinder/save-locations.php
2016-05-24 00:51:25 +02:00

36 lines
839 B
PHP

<?php
require_once 'bootstrap.php';
$locationId = $_GET['locationId'];
$distances = array();
foreach($_POST['locations'] as $location) {
$distances[] = $location['dst'];
if(!$location['id']){
dbInsert('df_locations', array(
'address' => formatAddress($location['adr']),
'latitude' => $location['lat'],
'longitude' => $location['lng'],
));
$location['id'] = dbGetInsertId();
}
$dst = (string) getDbDistance($locationId, $location['id']);
if ($location['id'] and !$dst){
dbInsert('df_distances', array(
'id1' => $locationId,
'id2' => $location['id'],
'distance' => $location['dst'],
));
}
}
if(sizeof($distances)){
$text = implode($distances, NEWLINE) . NEWLINE;
file_put_contents(DISTANCES_FILE, $text, FILE_APPEND);
}