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