commit version 22.12.12447
This commit is contained in:
@ -6,36 +6,26 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
*
|
||||
*/
|
||||
|
||||
if ($vars['editing'])
|
||||
{
|
||||
if ($readonly)
|
||||
{
|
||||
if ($vars['editing']) {
|
||||
if ($readonly) {
|
||||
print_error_permission('You have insufficient permissions to edit settings.');
|
||||
}
|
||||
else if (get_db_version() < 169)
|
||||
{
|
||||
// FIXME. Remove this block in r7000
|
||||
print_warning("DB scheme is old, must update first. Device Geolocation not changed.");
|
||||
} else {
|
||||
$updated = 0;
|
||||
|
||||
if ($vars['submit'] === 'save')
|
||||
{
|
||||
if ($vars['submit'] === 'save') {
|
||||
if (get_var_true($vars['reset_geolocation'])) {
|
||||
$updated = dbDelete('devices_locations', '`device_id` = ?', array($device['device_id']));
|
||||
$updated = dbDelete('devices_locations', '`device_id` = ?', [ $device['device_id'] ]);
|
||||
} elseif ((bool)$vars['location_manual']) {
|
||||
// Set manual coordinates if present
|
||||
$pattern = '/(?:^|[\[(])\s*(?<lat>[+-]?\d+(?:\.\d+)*)\s*[,; ]\s*(?<lon>[+-]?\d+(?:\.\d+)*)\s*(?:[\])]|$)/';
|
||||
if (preg_match($pattern, $vars['coordinates'], $matches))
|
||||
{
|
||||
if (preg_match($pattern, $vars['coordinates'], $matches)) {
|
||||
//r($matches);
|
||||
if ($matches['lat'] >= -90 && $matches['lat'] <= 90 &&
|
||||
$matches['lon'] >= -180 && $matches['lon'] <= 180)
|
||||
{
|
||||
$matches['lon'] >= -180 && $matches['lon'] <= 180) {
|
||||
$update_geo['location_lat'] = $matches['lat'];
|
||||
$update_geo['location_lon'] = $matches['lon'];
|
||||
$update_geo['location_country'] = '';
|
||||
@ -47,29 +37,28 @@ if ($vars['editing'])
|
||||
//r($vars);
|
||||
}
|
||||
|
||||
if ((bool)$device['location_manual'] && !(bool)$vars['location_manual'])
|
||||
{
|
||||
if ((bool)$device['location_manual'] && !(bool)$vars['location_manual']) {
|
||||
// Reset manual flag, rediscover geo info
|
||||
$update_geo['location_lat'] = array('NULL');
|
||||
$update_geo['location_lon'] = array('NULL');
|
||||
$update_geo['location_lat'] = [ 'NULL' ];
|
||||
$update_geo['location_lon'] = [ 'NULL' ];
|
||||
$update_geo['location_manual'] = 0;
|
||||
$updated++;
|
||||
}
|
||||
|
||||
if ($updated)
|
||||
{
|
||||
if ($updated) {
|
||||
//r($update_geo);
|
||||
dbUpdate($update_geo, 'devices_locations', '`location_id` = ?', array($device['location_id']));
|
||||
$geo_db = dbFetchRow("SELECT * FROM `devices_locations` WHERE `device_id` = ?", array($device['device_id']));
|
||||
if (count($geo_db))
|
||||
{
|
||||
if (!safe_empty($update_geo)) {
|
||||
dbUpdate($update_geo, 'devices_locations', '`location_id` = ?', [ $device['location_id'] ]);
|
||||
}
|
||||
$geo_db = dbFetchRow("SELECT * FROM `devices_locations` WHERE `device_id` = ?", [ $device['device_id'] ]);
|
||||
if (safe_count($geo_db)) {
|
||||
if (get_var_true($vars['reset_geolocation'])) {
|
||||
print_warning("Device Geo location dropped. Country/city will be updated on next poll.");
|
||||
} else {
|
||||
print_success("Device Geolocation updated. Country/city will be updated on next poll.");
|
||||
}
|
||||
}
|
||||
$device = array_merge($device, $geo_db);
|
||||
$device = array_merge($device, (array)$geo_db);
|
||||
unset($updated, $update_geo, $geo_db);
|
||||
} else {
|
||||
print_warning("Some input data wrong. Device Geolocation not changed.");
|
||||
@ -78,37 +67,32 @@ if ($vars['editing'])
|
||||
}
|
||||
}
|
||||
|
||||
$location = array('location_text' => $device['location']);
|
||||
$location = [ 'location_text' => $device['location'] ];
|
||||
|
||||
$override_sysLocation_bool = get_dev_attrib($device,'override_sysLocation_bool');
|
||||
if ($override_sysLocation_bool)
|
||||
{
|
||||
if ($override_sysLocation_bool) {
|
||||
$override_sysLocation_string = get_dev_attrib($device,'override_sysLocation_string');
|
||||
if ($override_sysLocation_string != $device['location'])
|
||||
{
|
||||
// Device not polled since location overrided
|
||||
if ($override_sysLocation_string != $device['location']) {
|
||||
// Device not polled since location override
|
||||
$location['location_help'] = 'NOTE, device not polled since location overridden, Geolocation is old.';
|
||||
$location['location_text'] = $override_sysLocation_string;
|
||||
}
|
||||
}
|
||||
|
||||
if ($location['location_text'] == '') { $location['location_text'] = OBS_VAR_UNSET; }
|
||||
foreach (array('location_lat', 'location_lon', 'location_city', 'location_county', 'location_state', 'location_country',
|
||||
'location_geoapi', 'location_status', 'location_manual', 'location_updated') as $param)
|
||||
{
|
||||
if (safe_empty($location['location_text'])) { $location['location_text'] = OBS_VAR_UNSET; }
|
||||
foreach ([ 'location_lat', 'location_lon', 'location_city', 'location_county', 'location_state', 'location_country',
|
||||
'location_geoapi', 'location_status', 'location_manual', 'location_updated' ] as $param) {
|
||||
$location[$param] = $device[$param];
|
||||
}
|
||||
if (is_numeric($location['location_lat']) && is_numeric($location['location_lon']))
|
||||
{
|
||||
if (is_numeric($location['location_lat']) && is_numeric($location['location_lon'])) {
|
||||
// Generate link to Google maps
|
||||
// http://maps.google.com/maps?q=46.090271,6.657248+description+(name)
|
||||
$location['coordinates'] = $location['location_lat'].','.$location['location_lon'];
|
||||
$location['coordinates_manual'] = $location['coordinates'];
|
||||
$location['location_link'] = '<a target="_blank" href="http://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="'.$config['icon']['map'].'"></i> View this location on a map</a>';
|
||||
$location['location_link'] = '<a target="_blank" href="https://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="'.$config['icon']['map'].'"></i> View this location on a map</a>';
|
||||
$location['location_geo'] = country_from_code($location['location_country']).' (Country), '.$location['location_state'].' (State), ';
|
||||
$location['location_geo'] .= $location['location_county'] .' (County), ' .$location['location_city'] .' (City)';
|
||||
switch ($location['location_geoapi'])
|
||||
{
|
||||
switch ($location['location_geoapi']) {
|
||||
//case 'yandex':
|
||||
// // Generate link to Yandex maps
|
||||
// $location['location_link'] = '<a target="_blank" href="http://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="oicon-map"></i> View this location on a map</a>';
|
||||
@ -122,8 +106,7 @@ if (is_numeric($location['location_lat']) && is_numeric($location['location_lon'
|
||||
$location['coordinates_manual'] = $config['geocoding']['default']['lat'].','.$config['geocoding']['default']['lon'];
|
||||
}
|
||||
|
||||
if ($updated && $update_message)
|
||||
{
|
||||
if ($updated && $update_message) {
|
||||
print_message($update_message);
|
||||
} elseif ($update_message) {
|
||||
print_error($update_message);
|
||||
|
Reference in New Issue
Block a user