require 'common.php';
if (array_key_exists('copiar', $_GET)) {
    $id_mapa = intval($_GET['copiar']);
    Mapa::carregarEstrutura($id_mapa);
    $id_mapa = Mapa::copiarMapa($id_mapa, true);
    header('location: mapa-config.php?map=' . $id_mapa);
    exit;
}
if (!Mapa::carregarEstrutura()) {
    throw new Exception('Mapa não encontrado!');
}
$msgerro = null;
$msgsuccess = null;
if (count($_POST) > 0) {
    try {
        Mapa::carregarDoPost();
    } catch (Exception $e) {
        $msgerro = $e->getMessage();
    }
    if ($_POST['acao'] == 'Gravar') {
        Mapa::alterarEstrutura();
        $msgsuccess = "Dados do mapa gravados com sucesso.";
    }
}
require 'header.php';
if (!is_null($msgerro)) {
    ?>
<div class="row">
    <div class="twelve columns">
        <div class="alert-box alert"><?php 
    echo $msgerro;