<?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_av.php");
    protegePagina();
    include "../conectar.php";
    include "../log_.php";
    if($_SERVER['REQUEST_METHOD']=='GET'){
        $busca=$pdo_sgt->prepare("SELECT * FROM tb_voip WHERE id=:id");
        $busca->bindValue(":id",$_GET['id']);
        $busca->execute();
        $dados=$busca->fetch(PDO::FETCH_ASSOC);
        $del = $dados['id'];
    }
    elseif($_SERVER['REQUEST_METHOD']=='POST'){
        $id = isset($_POST["id"]) ? $_POST["id"]: '';
        $id = ($id);
        $setor = isset($_POST["setor"]) ? $_POST["setor"]: '';
        $senha = isset($_POST["senha"]) ? $_POST["senha"]: '';
        $func = isset($_POST["func"]) ? $_POST["func"]: '';
        $tel_d = isset($_POST["tel_d"]) ? $_POST["tel_d"]: '';
        $tel_1 = isset($_POST["tel_1"]) ? $_POST["tel_1"]: '';
        $tel_2 = isset($_POST["tel_2"]) ? $_POST["tel_2"]: '';
        $tt = isset($_POST["tt"]) ? $_POST["tt"]: '';
        $eqp = isset($_POST["eqp"]) ? $_POST["eqp"]: '';
        $info = isset($_POST["info"]) ? $_POST["info"]: '';
        $atualizar=$pdo_sgt->prepare("UPDATE tb_voip SET setor=:setor,senha=:senha,func=:func,tel_d=:tel_d,tel_p=:tel_1,tel_u=:tel_2,tt=:tt,eqp=:eqp,info=:info WHERE id=:id");
        $atualizar->bindValue(":id",$id);
        $atualizar->bindValue(":setor",$setor);
        $atualizar->bindValue(":senha",$senha);
        $atualizar->bindValue(":func",$func);
        $atualizar->bindValue(":tel_d",$tel_d);
        $atualizar->bindValue(":tel_1",$tel_1);
        $atualizar->bindValue(":tel_2",$tel_2);
        $atualizar->bindValue(":tt",$tt);
        $atualizar->bindValue(":eqp",$eqp);
        $atualizar->bindValue(":info",$info);
        $atualizar->execute();
        $mensagem = "Dados alterados na tabela: tb_voip - Para os campos: setor, senha, func, tel_d, tel_p, tel_u, tt, eqp, info - Com os seguintes valores: $func.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_tel.php';
        </script>";
    }
?>