<?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";
    $id_vlan = $_POST['id_vlan'];
    $vlan = $_POST['vlan'];
    $desc = $_POST['desc'];
    $cor = $_POST['cor'];
    $select=$pdo_sgt->prepare("SELECT * FROM tb_vlan WHERE vlan=:vlan");
    $select->bindValue(":vlan",$vlan);
    $select->execute();
    $array = $select->fetch(PDO::FETCH_ASSOC);
    if($array['vlan'] == $vlan){
        echo"<script language='javascript' type='text/javascript'>
            alert('Este ID: ".$id_vlan." com a VALN: ".$vlan." já existe!');
            window.location.href='list_local.php';
        </script>";
    }
    else{
        $query_ = "INSERT INTO tb_vlan (id_vlan,vlan,descricao,cor) VALUES (:id_vlan,:vlan,:desc,:cor)";
        $query=$pdo_sgt->prepare("$query_");
        $query->bindValue(":id_vlan",$id_vlan);
        $query->bindValue(":vlan",$vlan);
        $query->bindValue(":desc",$desc);
        $query->bindValue(":cor",$cor);
        $query->execute();
        $mensagem = "Dados inseridos na tabela: tb_vlan - Para o campos: id_vlan, vlan, descricao, cor - Com o seguinte valor: $id_vlan, $vlan, $desc, $cor.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_vlan.php';
        </script>";
    }
?>