示例#1
0
 private function deleteForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Template') . '</h2>';
     $map_name = req('show');
     if (!$map_name) {
         throw new NagVisException(l('Map name missing'));
     }
     if (count($CORE->getAvailableMaps('/^' . preg_quote($map_name) . '$/')) == 0) {
         throw new NagVisException(l('A map with this name does not exists'));
     }
     $MAPCFG = new GlobalMapCfg($map_name);
     $MAPCFG->readMapConfig(!ONLY_GLOBAL, false, false);
     if (is_action() && post('mode') == 'delete') {
         try {
             $name = post('name');
             if (count($MAPCFG->getTemplateNames('/^' . $name . '$/')) == 0) {
                 throw new FieldInputError('name', l('A template with this name does not exist.'));
             }
             $obj_id = $MAPCFG->getTemplateIdByName($name);
             $MAPCFG->deleteElement($obj_id, true);
             success(l('The template has been deleted.'));
         } 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;
     js_form_start('delete');
     hidden('mode', 'delete');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Name') . '</td>';
     echo '<td class="tdfield">';
     $choices = array('' => l('Please choose'));
     foreach (array_keys($MAPCFG->getTemplateNames()) as $tmpl_name) {
         $choices[$tmpl_name] = $tmpl_name;
     }
     select('name', $choices, '', 'updateForm(this.form)');
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }
示例#2
0
 protected function doDeleteObject($a)
 {
     // initialize map and read map config
     $MAPCFG = new GlobalMapCfg($a['map']);
     // Ignore map configurations with errors in it.
     // the problems may get resolved by deleting the object
     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.'));
     }
     // first delete element from array
     $MAPCFG->deleteElement($a['id'], true);
     // delete map lock
     if (!$MAPCFG->deleteMapLock()) {
         throw new NagVisException(l('mapLockNotDeleted'));
     }
     return true;
 }