<?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 "busca_func_.php";
    include "../var_sub.php";
?>
<!DOCTYPE HTML>
<html>
<head>
    <?php
        include '../css.html';
    ?>
    <script type="text/javascript">
        function proximoCampo(atual,proximo){
            if(atual.value.length >= atual.maxLength){
                document.getElementById(proximo).focus();
            }
        }
    </script>
    <meta charset="UTF-8">
    <title>Gestão de Funcionários - SGT</title>
</head>
<body>
    <div class="main_sgt">
        <?php
            include '../menu.html';
        ?>
        <div class="container-fluid content_sgt">
            <div class="row">
                <div class="col-24 col-md-1"></div>
                <div class="col align-self-center">
                    <form enctype="multipart/form-data" action="alt_func_.php" method="POST">
                        <?php
                            $del = $dados['id'];
                        ?>
                        <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">
                                <select class="custom-select mb-2 mr-sm-2 mb-sm-0 form-control" name="unidade">
                                    <?php
                                        $busca_uni = $pdo_sgt->prepare("SELECT * FROM tb_unidades WHERE id>1 ORDER BY id");
                                        $busca_uni->execute();
                                        while ($linha = $busca_uni->fetch(PDO::FETCH_ASSOC)){
                                            $valor = $linha['id']; 
                                            echo "<option value = \"$valor\""; if($dados['unidade'] == $valor){echo ' selected';} echo ">$linha[unidade]</option>";
                                        }
                                    ?>
                                </select>
                            </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" name="setor">
                                    <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">Função: </label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="funcao" value="<?php echo $dados['funcao']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Nome: </label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="p_nome" required value="<?php echo $dados['p_nome']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Sobrenome: </label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="u_nome" required value="<?php echo $dados['u_nome']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Nome Completo: </label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" name="nome_c" required value="<?php echo $dados['nome_c']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">e-mail 1: </label>
                            <div class="col-sm-5">
                                <input type="email" class="form-control" name="email_1" value="<?php echo $dados['email_1']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">e-mail 2: </label>
                            <div class="col-sm-5">
                                <input type="email" class="form-control" name="email_2" value="<?php echo $dados['email_2']; ?>" />
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Telefone: </label>
                            <div class="col-sm-4">
                                <div class="form-inline">
                                    <input type="text" class="form-control" maxlength="2" size="1" name="tel_d" id="tel_d" value="<?php echo $dados['tel_d']; ?>" onkeyup="javascript:proximoCampo(this, 'tel_1')">
                                    <input type="text" class="form-control mx-sm-2" maxlength="4" size="2" name="tel_1" id="tel_1" value="<?php echo $dados['tel_p']; ?>" onkeyup="javascript:proximoCampo(this, 'tel_2')">
                                    -<input type="text" class="form-control mx-sm-2" maxlength="4" size="2" name="tel_2" id="tel_2" value="<?php echo $dados['tel_u']; ?>" onkeyup="javascript:proximoCampo(this, 'cel_d')">
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Celular: </label>
                            <div class="col-sm-4">
                                <div class="form-inline">
                                    <input type="text" class="form-control" maxlength="2" size="1" name="cel_d" id="cel_d" value="<?php echo $dados['cel_d']; ?>" onkeyup="javascript:proximoCampo(this, 'cel_1')">
                                    <input type="text" class="form-control mx-sm-2" maxlength="5" size="3" name="cel_1" id="cel_1" value="<?php echo $dados['cel_p']; ?>" onkeyup="javascript:proximoCampo(this, 'cel_2')">
                                    -<input type="text" class="form-control mx-sm-2" maxlength="4" size="2" name="cel_2" id="cel_2" value="<?php echo $dados['cel_u']; ?>" onkeyup="javascript:proximoCampo(this, 'cont')">
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Apenas Contato: </label>
                            <div class="col-sm-3">
                                <div class="custom-control custom-checkbox">
                                    <input class="custom-control-input" type="checkbox" id="cont" name="cont" value="ativo" <?php if($dados['cont'] != 0){echo ' CHECKED';}?>>
                                    <label class="custom-control-label" for="cont"></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">Status: </label>
                            <div class="col-sm-3">
                                <div class="custom-control custom-checkbox">
                                    <input class="custom-control-input" type="checkbox" id="ativo" name="ativo" value="ativo" <?php if($dados['ativo'] != 0){echo ' CHECKED';}?>>
                                    <label class="custom-control-label" for="ativo"></label>
                                </div>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary">Alterar</button>
                        <button type="button" class="btn btn-secondary" align="center" onclick="javascript: window.history.go(-1)>Volta;">Cancelar</button>
                        <button type="button" class="btn btn-danger" align="center" onclick="javascript: window.location.href='del_func.php?id=<?php echo $del;?>';">Apagar</button>
                    </form>
                </div>
            </div>
        </div>
        <?php
            include '../roda_pe.html';
        ?>
    </div>
</body>
</html>