<?php
#   SGT - The SGT for Internet - http://sgt.eti.br
#   Copyright (c) 2016-2018, Jean Azevedo. All rights reserved.

#   This file is part of SGT.

#   SGT is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   any later version.

#   SGT is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

    include("../seguranca_aux_unid.php");
    protegePagina();
    include "../conectar.php";
    include "../log_.php";
    $local = $_POST['local'];
    $desc = $_POST['desc'];
    $select=$pdo_sgt->prepare("SELECT * FROM tb_local WHERE local=:local");
    $select->bindValue(":local",$local);
    $select->execute();
    $array = $select->fetch(PDO::FETCH_ASSOC);
    if($array['local'] == $local){
        echo"<script language='javascript' type='text/javascript'>
            alert('Este local: ".$local." já existe!');
            window.history.go(-1)>Volta;
        </script>";
    }
    else{
        $query=$pdo_sgt->prepare("INSERT INTO tb_local (local,descricao) VALUES (:local,:desc)");
        $query->bindValue(":local",$local);
        $query->bindValue(":desc",$desc);
        $query->execute();
        $mensagem = "Dados inseridos na tabela: tb_local - Para os campos: local, descricao - Com os seguintes valores: $local, $desc.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_local.php';
        </script>";
    }
?>