<?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_adm.php");
    protegePagina();
    include "../conectar.php";
    include "../log_.php";
    $marca = $_POST['marca'];
    $comp = (isset($_POST['comp'])) ? 1 : 0;
    $mon = (isset($_POST['mon'])) ? 1 : 0;
    $eqp = (isset($_POST['eqp'])) ? 1 : 0;
    $proc = (isset($_POST['proc'])) ? 1 : 0;
    $vid = (isset($_POST['vid'])) ? 1 : 0;
    $select=$pdo_sgt->prepare("SELECT * FROM tb_marcas WHERE marca=:marca");
    $select->bindValue(":marca",$marca);
    $select->execute();
    $array = $select->fetch(PDO::FETCH_ASSOC);
    if($array['marca'] == $marca){
        echo"<script language='javascript' type='text/javascript'>
            alert('Esta Marca "; echo $marca; echo" já existe!');
            window.history.go(-1)>Volta;
        </script>";
        die();
    }else{
        $query_ = "INSERT INTO tb_marcas (marca,comp,mon,eqp,proc,vid) VALUES (:marca,:comp,:mon,:eqp,:proc,:vid)";
        $query=$pdo_sgt->prepare("$query_");
        $query->bindValue(":marca",$marca);
        $query->bindValue(":comp",$comp);
        $query->bindValue(":mon",$mon);
        $query->bindValue(":eqp",$eqp);
        $query->bindValue(":proc",$proc);
        $query->bindValue(":vid",$vid);
        $query->execute();
        $mensagem = "Dados inseridos na tabela: tb_marcas - Para os campos: marca, comp, mon, eqp, proc, vid - Com os seguintes valores: $marca, $comp, $mon, $eqp, $proc, $vid.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_marc.php';
        </script>";
    }	
?>