protected function doModifyObject($a) { $MAPCFG = new GlobalMapCfg($a['map']); try { $MAPCFG->readMapConfig(); } catch (MapCfgInvalid $e) { } // Give the sources the chance to load the object $MAPCFG->handleSources('load_obj', $a['id']); if (!$MAPCFG->objExists($a['id'])) { throw new NagVisException(l('The object does not exist.')); } // set options in the array foreach ($a['opts'] as $key => $val) { $MAPCFG->setValue($a['id'], $key, $val); } // write element to file $MAPCFG->storeUpdateElement($a['id']); // delete map lock if (!$MAPCFG->deleteMapLock()) { throw new NagVisException(l('mapLockNotDeleted')); } return json_encode(array('status' => 'OK', 'message' => '')); }
private function createForm() { global $CORE; echo '<h2>' . l('Create Map') . '</h2>'; $map_types = array('map' => l('Regular map'), 'worldmap' => l('Geographical map (interactive)'), 'geomap' => l('Geographical map (non interactive)'), 'automap' => l('Automap based on parent/child relations'), 'dynmap' => l('Dynamic map')); if (is_action() && post('mode') == 'create') { try { $name = post('name'); if (!$name) { throw new FieldInputError('name', l('You need to provide a unique map name (ID) for the map')); } if (count($CORE->getAvailableMaps('/^' . preg_quote($name) . '$/')) > 0) { throw new FieldInputError('name', l('A map with this name already exists')); } if (!preg_match(MATCH_MAP_NAME, $name)) { throw new FieldInputError('name', l('This is not a valid map name (need to match [M])', array('M' => MATCH_MAP_NAME))); } $type = post('type'); if (!isset($map_types[$type])) { throw new FieldInputError('type', l('You provided an invalid type')); } $alias = post('alias'); if ($alias && !preg_match(MATCH_STRING, $alias)) { throw new FieldInputError('alias', l('This is not a valid map alias (need to match [M])', array('M' => MATCH_STRING))); } $MAPCFG = new GlobalMapCfg($name); if (!$MAPCFG->createMapConfig()) { throw new NagVisException(l('Failed to create the map')); } $global = array(); if ($alias) { $global['alias'] = $alias; } if ($type != 'map') { $global['sources'] = array($type); } $MAPCFG->addElement('global', $global, false, 0); $MAPCFG->handleSources('init_map'); $MAPCFG->storeUpdateElement(0); success(l('The map has been created. Changing to the new map...')); reload('index.php?mod=Map&act=view&show=' . $name, 1); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('create_map'); hidden('mode', 'create'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('ID (Internal Name)') . '</td>'; echo '<td class="tdfield">'; input('name'); echo '</td></tr>'; echo '<tr><td class="tdlabel">' . l('Alias') . '</td>'; echo '<td class="tdfield">'; input('alias'); echo '</td></tr>'; echo '<tr><td class="tdlabel">' . l('Map Type') . '</td>'; echo '<td class="tdfield">'; select('type', $map_types); echo '</td></tr>'; echo '</table>'; submit(l('Create')); form_end(); }