Merge pull request #1501 from laf/issue-1334-new

New overview page and new map
This commit is contained in:
Paul Gear
2015-07-26 14:33:34 +10:00
220 changed files with 92463 additions and 57 deletions

View File

@@ -416,3 +416,60 @@ function get_main_serial($device) {
}
}//end get_main_serial()
function location_to_latlng($device) {
global $config;
if (function_check('curl_version') !== true) {
d_echo("Curl support for PHP not enabled\n");
return false;
}
$bad_loc = false;
$device_location = $device['location'];
if (!empty($device_location)) {
$new_device_location = preg_replace("/ /","+",$device_location);
// We have a location string for the device.
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
if (is_array($loc) === false) {
// Grab data from which ever Geocode service we use.
switch ($config['geoloc']['engine']) {
case "google":
default:
d_echo("Google geocode engine being used\n");
$api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location";
break;
}
$curl_init = curl_init($api_url);
set_curl_proxy($curl_init);
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
$data = json_decode(curl_exec($curl_init),true);
// Parse the data from the specific Geocode services.
switch ($config['geoloc']['engine']) {
case "google":
default:
if ($data['status'] == 'OK') {
$loc = $data['results'][0]['geometry']['location'];
} else {
$bad_loc = true;
}
break;
}
if ($bad_loc === true) {
d_echo("Bad lat / lng received\n");
}
else {
$loc['timestamp'] = array('NOW()');
$loc['location'] = $device_location;
if (dbInsert($loc, 'locations')) {
d_echo("Device lat/lng created\n");
}
else {
d_echo("Device lat/lng could not be created\n");
}
}
}
else {
d_echo("Using cached lat/lng from other device\n");
}
}
}// end location_to_latlng()

View File

@@ -114,9 +114,11 @@ foreach (array('sysContact', 'sysObjectID', 'sysName', 'sysDescr') as $elem) {
}
}
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation']) {
if (!get_dev_attrib($device, 'override_sysLocation_bool')) {
$update_array['location'] = $poll_device['sysLocation'];
log_event('Location -> '.$poll_device['sysLocation'], $device, 'system');
}
if ($poll_device['sysLocation'] && $device['location'] != $poll_device['sysLocation'] && $device['override_sysLocation'] == 0) {
$update_array['location'] = $poll_device['sysLocation'];
log_event('Location -> '.$poll_device['sysLocation'], $device, 'system');
}
if ($config['geoloc']['latlng'] === true) {
location_to_latlng($device);
}