コード例 #1
0
ファイル: ViewMapManageTmpl.php プロジェクト: rlugojr/nagvis
 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();
 }