<?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";
    $unidade = $_POST['unidade'];
    $setor = $_POST['setor'];
    $voip = $_POST['voip'];
    $senha = $_POST['senha'];
    $func = $_POST['func'];
    $tel_d = $_POST['tel_d'];
    $tel_1 = $_POST['tel_1'];
    $tel_2 = $_POST['tel_2'];
    $tt = $_POST['tt'];
    $eqp = $_POST['eqp'];
    $info = $_POST['info'];
    $select=$pdo_sgt->prepare("SELECT * FROM tb_voip WHERE unidade=:unidade AND voip=:voip");
    $select->bindValue(":unidade",$unidade);
    $select->bindValue(":voip",$voip);
    $select->execute();
    $array = $select->fetch(PDO::FETCH_ASSOC);
    if($array['voip'] == $voip){
        echo"<script language='javascript' type='text/javascript'>
            alert('Este VoIP "; echo $voip; echo" já existe!');
            window.history.go(-1)>Volta;
        </script>";
    } else {
        $query=$pdo_sgt->prepare("INSERT INTO tb_voip (unidade,setor,voip,senha,func,tel_d,tel_p,tel_u,tt,eqp,info) "
                . "VALUES (:unidade,:setor,:voip,:senha,:func,:tel_d,:tel_1,:tel_2,:tt,:eqp,:info)");
        $query->bindValue(":unidade",$unidade);
        $query->bindValue(":setor",$setor);
        $query->bindValue(":voip",$voip);
        $query->bindValue(":senha",$senha);
        $query->bindValue(":func",$func);
        $query->bindValue(":tel_d",$tel_d);
        $query->bindValue(":tel_1",$tel_1);
        $query->bindValue(":tel_2",$tel_2);
        $query->bindValue(":tt",$tt);
        $query->bindValue(":eqp",$eqp);
        $query->bindValue(":info",$info);
        $query->execute();
        $mensagem = "Dados inseridos na tabela: tb_voip - Para os campos: unidade, setor, voip, senha, func, tel_d, tel_p, tel_u, tt, eqp, info - "
                . "Com o seguinte valor: $unidade, $setor, $voip, $senha, $func, $tel_d, $tel_1, $tel_2, $tt, $eqp, $info.";
        salvaLog($mensagem);
        echo"<script language='javascript' type='text/javascript'>
            window.location.href='list_tel.php';
        </script>";
    }
?>