<?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 "del_voip_.php";
    include "../var_sub.php";
    $tt_c = 1;
?>
<!doctype html>
<html>
<head>
    <?php
        include '../css.html';
    ?>
    <meta charset="UTF-8">
    <title>Apagar VoIP - SGT</title>
</head>
<body>
    <div class="main_sgt">
        <?php
            include '../menu.html';
        ?>
        <div class="container-fluid content_tb_sgt">
            <div class="row">
                <div class="col-24 col-md-1"></div>
                <div class="col align-self-center">
                    <h4>ATENÇÃO, OS DADOS SERÃO APAGADOS!!!</h4>
                    <form action="del_voip_.php" method="POST">
                        <?php
                            if($_SERVER['REQUEST_METHOD']){
                                $busca_unid=$pdo_sgt->prepare("SELECT * FROM tb_unidades WHERE id=:id");
                                $busca_unid->bindValue(":id",$dados['unidade']);
                                $busca_unid->execute();
                                $dados_unid=$busca_unid->fetch(PDO::FETCH_ASSOC);
                            }
                        ?>
                        <input style="display: none" type="text" readonly name="id" value="<?php echo $dados['id']; ?>">
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Unidade:</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" disabled value="<?php echo $dados_unid['unidade']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Setor:</label>
                            <div class="col-sm-3">
                                <select class="custom-select mb-2 mr-sm-2 mb-sm-0 form-control" disabled>
                                    <option value = \"a\">Sem Seleção</option>
                                    <?php
                                        $busca_set = $pdo_sgt->query("SELECT * FROM tb_setores ORDER BY setor");
                                        while (@$linha = $busca_set->fetch(PDO::FETCH_ASSOC)){
                                            $valor = $linha[@id]; 
                                            echo "<option value = \"$valor\""; if($dados['setor'] == $valor){echo ' selected';} echo ">$valor - $linha[setor]</option>";
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">VoIP:</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="voip" disabled value="<?php echo $dados['voip']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Senha:</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" disabled value="<?php echo $dados['senha']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Funcionário:</label>
                            <div class="col-sm-3">
                                <select class="custom-select mb-2 mr-sm-2 mb-sm-0 form-control" disabled>
                                    <option value = \"a\">Sem Seleção</option>
                                    <?php
                                        $buscaf_u=$pdo_sgt->prepare("SELECT * FROM tb_unidades WHERE id=:id ORDER BY unidade");
                                        $buscaf_u->bindValue(":id",$unid_master);
                                        $buscaf_u->execute();
                                        while ($linhaf_u = $buscaf_u->fetch(PDO::FETCH_ASSOC)){
                                            $valorf_u = $linhaf_u['id'];
                                            $buscaf =$pdo_sgt->prepare("SELECT * FROM tb_funcionarios WHERE unidade=:unidade ORDER BY nome_c");
                                            $buscaf->bindValue(":unidade",$valorf_u);
                                            $buscaf->execute();
                                            while ($linhaf = $buscaf->fetch(PDO::FETCH_ASSOC)){
                                                $valorf = $linhaf['id'];
                                                echo "<option value = \"$valorf\""; if($dados['func'] == $valorf){echo ' selected';} echo ">".$linhaf_u['unidade']." - ".$linhaf['p_nome']." ".$linhaf['u_nome']."</option>";
                                            }

                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">DDR:</label>
                            <div class="col-sm-4">
                                <div class="form-inline">
                                    <input type="text" class="form-control" value="(<?php echo $dados['tel_d']; ?>) <?php echo $dados['tel_p']; ?>-<?php echo $dados['tel_u']; ?>" disabled>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Tempo de Toque:</label>
                            <div class="col-sm-3">
                                <select class="custom-select mb-2 mr-sm-2 mb-sm-0 form-control" disabled>
                                    <option value = \"a\">Sem Seleção</option>
                                    <?php
                                        while ($tt_c < 61){
                                            echo "<option value = \"$tt_c\""; if($dados['tt'] == $tt_c){echo ' selected';} echo "> $tt_c s </option>";
                                            $tt_c ++;
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Cód. Eqp.:</label>
                            <div class="col-sm-3">
                                <select class="custom-select mb-2 mr-sm-2 mb-sm-0 form-control" disabled>
                                    <option value = \"a\">Sem Seleção</option>
                                    <?php
                                        $buscae=$pdo_sgt->prepare("SELECT * FROM tb_equipamentos WHERE tipo=:tipo AND unidade=:unidade ORDER BY cod_e");
                                        $buscae->bindValue(":tipo",8);
                                        $buscae->bindValue(":unidade",$unid_master);
                                        $buscae->execute();
                                        while ($linhae = $buscae->fetch(PDO::FETCH_ASSOC)){
                                            $valore = $linhae['id']; 
                                            echo "<option value = \"$valore\""; if($dados['eqp'] == $valore){echo 'selected';} echo ">$linhae[cod_e]</option>";
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label" >Informações:</label>
                            <div class="col-sm-3">
                                <textarea class="form-control" id="exampleFormControlTextarea1" maxlength="500" rows="8" cols="33" onkeyup="limite_textarea(this.value)" disabled><?php echo $dados['info']; ?></textarea>
                                <label>Caracteres restantes: <span id="cont">500</span></label>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-danger">Apagar</button>
                        <button type="button" class="btn btn-secondary" align="center" onclick="javascript: window.location.href='list_tel.php';">Cancelar</button>
                    </form>
                </div>
            </div>
        </div>
        <?php
            include '../roda_pe.html';
        ?>
    </div>
</body>
</html>