Revert "Revert "Added location_map_regex""

This commit is contained in:
Neil Lathwood
2016-02-09 19:02:38 +00:00
parent 4cc523aeb0
commit f074f25be2
4 changed files with 17 additions and 2 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']);
$poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\');
// Rewrite sysLocation if there is a mapping array (database too?)
if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) {
if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) {
$poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']);
}
+9
View File
@@ -5,6 +5,15 @@ function rewrite_location($location) {
// FIXME -- also check the database for rewrites?
global $config, $debug;
if (is_array($config['location_map_regex'])) {
foreach ($config['location_map_regex'] as $reg => $val) {
if (preg_match($reg, $location)) {
$location = $val;
continue;
}
}
}
if (isset($config['location_map'][$location])) {
$location = $config['location_map'][$location];
}