示例#1
0
 private function deleteForm()
 {
     global $CORE;
     echo '<h2>' . l('Delete Map') . '</h2>';
     if (is_action() && post('mode') == 'delete') {
         try {
             $name = post('name');
             if (!$name) {
                 throw new FieldInputError('name', l('Please choose a map'));
             }
             if (count($CORE->getAvailableMaps('/^' . preg_quote($name) . '$/')) == 0) {
                 throw new FieldInputError('name', l('The given map name is invalid'));
             }
             $MAPCFG = new GlobalMapCfg($name);
             try {
                 $MAPCFG->readMapConfig();
             } catch (MapCfgInvalid $e) {
             }
             $MAPCFG->deleteMapConfig();
             success(l('The map has been deleted.'));
             $cur_map = post('current_map');
             if ($cur_map && $cur_map == $name) {
                 reload('index.php', 1);
             }
             // change to overview page when current map has been deleted
         } 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('delete_map');
     hidden('mode', 'delete');
     // eventual currently open map, needed for redirecting the user if the
     // renamed map is currently open
     hidden('current_map', '');
     js('document.getElementById(\'current_map\').value = oPageProperties.map_name;');
     echo '<table class="mytable">';
     echo '<tr><td class="tdlabel">' . l('Map') . '</td>';
     echo '<td class="tdfield">';
     $maps = array('' => l('Choose a map'));
     foreach ($CORE->getAvailableMaps() as $map) {
         $maps[$map] = $map;
     }
     select('name', $maps);
     echo '</td></tr>';
     echo '</table>';
     submit(l('Delete'));
     form_end();
 }