distancefinder/save-locations.php

37 lines
839 B
PHP
Raw Permalink Normal View History

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