Beispiel #1
0
 public function parse($orig_name)
 {
     global $CORE;
     ob_start();
     if (is_action()) {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please provide a map name.'));
             }
             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)));
             }
             if (count($CORE->getAvailableMaps('/^' . $name . '$/')) > 0) {
                 throw new FieldInputError('name', l('A map with this name already exists.'));
             }
             // Read the old config
             $MAPCFG = new GlobalMapCfg($orig_name);
             $MAPCFG->readMapConfig();
             // Create a new map config
             $NEW = new GlobalMapCfg($name);
             $NEW->createMapConfig();
             foreach ($MAPCFG->getMapObjects() as $object_id => $cfg) {
                 $NEW->addElement($cfg['type'], $cfg, $perm = true, $object_id);
             }
             success(l('The map has been created.'));
             reload(cfg('paths', 'htmlbase') . '/frontend/nagvis-js/index.php?mod=Map&show=' . $name, 1);
         } catch (FieldInputError $e) {
             form_error($e->field, $e->msg);
         } catch (NagVisException $e) {
             form_error(null, $e->message());
         } catch (Exception $e) {
             if (isset($e->msg)) {
                 form_error(null, $e->msg);
             } else {
                 throw $e;
             }
         }
     }
     echo $this->error;
     echo '<div class="simple_form">' . N;
     js_form_start('to_new_map');
     input('name');
     submit(l('Save'));
     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);
         }
     }
     form_end();
     echo '</div>' . N;
     return ob_get_clean();
 }
Beispiel #2
0
 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();
 }