<?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";
    $unidade = $_POST['unidade'];
    $nivel = $_POST['nivel'];
    $tt = $_POST['tt'];
    $desc = $_POST['desc'];
    $pp = $_POST['pp'];
    $busca_pp=$pdo_sgt->prepare("SELECT * FROM tb_pp WHERE unidade=:unidade AND tt=:tt AND descricao=:desc");
    $busca_pp->bindValue(":unidade",$unidade);
    $busca_pp->bindValue(":tt",$tt);
    $busca_pp->bindValue(":desc",$desc);
    $busca_pp->execute();
    if($busca_pp->rowCount() > 0){
        echo"<script language='javascript' type='text/javascript'>
            alert('Este Passo a Passo já existe');
            window.history.go(-1)>Volta;
        </script>";
    }else{
        $query=$pdo_sgt->prepare("INSERT INTO tb_pp (unidade,nivel,tt,descricao,pp) VALUES (:unidade,:nivel,:tt,:desc,:pp)");
        $query->bindValue(":unidade",$unidade);
        $query->bindValue(":nivel",$nivel);
        $query->bindValue(":tt",$tt);
        $query->bindValue(":desc",$desc);
        $query->bindValue(":pp",$pp);
        $query->execute();
        $mensagem = "Dados inseridos na tabela: tb_pp - "
            . "Para os campos: unidade, nivel, tt, descricao, pp - "
            . "Com os seguintes valores: $unidade, $nivel, $tt, $desc, $pp.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_pp.php';
        </script>";
    }
?>