Permalink
Browse files

FIX: Fixed errors when saving viewport as new map

  • Loading branch information...
LarsMichelsen committed Nov 10, 2017
1 parent 7bc589e commit 8149419bd4a9a9015f6e7af22d1ab88e9c00e7fe
View
@@ -2,6 +2,9 @@
Frontend:
* FIX: Fixed wrong hostname label in service hover menus
Worldmap:
* FIX: Fixed errors when saving viewport as new map
1.9.4
Core:
* List of hover menu childs (e.g. services in host object hover) can now be
@@ -414,8 +414,8 @@ private function getStaticMacros() {
'langToStaticMap' => l('Export to static map'),
'langModifyParams' => l('Modify view'),
'langMapViewport' => l('Viewport'),
'langSaveView' => l('Save View'),
'langSaveViewAsNewMap' => l('Save as new Map'),
'langSaveView' => l('Save view'),
'langSaveViewAsNewMap' => l('Save as new map'),
'langScaleToAll' => l('Show all objects'),
// Supported by backend and not using trusted auth
'supportedChangePassword' => $AUTH->checkFeature('changePassword') && !$AUTH->authedTrusted(),
@@ -29,6 +29,17 @@ public function parse($orig_name) {
global $CORE;
ob_start();
$view_params = array();
$params = ltrim(req('view_params'), '&');
if ($params) {
$parts = explode('&', $params);
foreach ($parts as $part) {
list($key, $val) = explode('=', $part);
$view_params[$key] = $val;
}
}
if (is_action()) {
try {
$name = post('name');
@@ -42,6 +53,18 @@ public function parse($orig_name) {
if (count($CORE->getAvailableMaps('/^'.$name.'$/')) > 0)
throw new FieldInputError('name', l('A map with this name already exists.'));
if (!isset($view_params["worldmap_center"]))
throw new FieldInputError('view_params', l('Please change your viewport before saving as new map.'));
if (!preg_match(MATCH_COORDS_MULTI, $view_params["worldmap_center"]))
throw new FieldInputError('view_params', l('This is not a valid worldmap center'));
if (!isset($view_params["worldmap_zoom"]))
throw new FieldInputError('view_params', l('Worldmap zoom parameter missing.'));
if (!preg_match(MATCH_INTEGER, $view_params["worldmap_zoom"]))
throw new FieldInputError('view_params', l('This is not a valid worldmap zoom'));
// Read the old config
$MAPCFG = new GlobalMapCfg($orig_name);
$MAPCFG->readMapConfig();
@@ -53,6 +76,10 @@ public function parse($orig_name) {
$NEW->addElement($cfg['type'], $cfg, $perm = true, $object_id);
}
$NEW->setValue(0, "worldmap_center", $view_params["worldmap_center"]);
$NEW->setValue(0, "worldmap_zoom", $view_params["worldmap_zoom"]);
$NEW->storeUpdateElement(0);
success(l('The map has been created.'));
reload(cfg('paths','htmlbase').'/frontend/nagvis-js/index.php?mod=Map&show='.$name, 1);
} catch (FieldInputError $e) {
@@ -75,13 +102,8 @@ public function parse($orig_name) {
focus('name');
// Keep the view parameters the users has set
$params = ltrim(req('view_params'), '&');
if ($params) {
$parts = explode('&', $params);
foreach ($parts as $part) {
list($key, $val) = explode('=', $part);
hidden($key, $val);
}
foreach ($view_params AS $key => $val) {
hidden($key, $val);
}
form_end();
@@ -243,6 +243,10 @@ function worldmap_update_object($MAPCFG, $map_name, &$map_config, $obj_id, $inse
if ($obj['type'] == 'global')
return false; // adding global section (during map creation)
// disable creating new objects during "view to new map" action
if (val($_GET, 'act', null) == 'viewToNewMap')
return true;
$lat = $obj['x'];
$lng = $obj['y'];
$lat2 = null;

0 comments on commit 8149419

Please sign in to comment.