<?php
error_reporting(0);
ini_set(“display_errors”, 0);
include "protege_professor.php";

?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>Immobile | SMS</title>

    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />

    <!-- ================== BEGIN BASE CSS STYLE ================== -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/css/animate.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/css/style.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/css/style-responsive.min.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/css/theme/default.css" rel="stylesheet" id="theme" />
    <!-- ================== END BASE CSS STYLE ================== -->

    <!-- ================== BEGIN PAGE LEVEL CSS STYLE ================== -->
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-calendar/css/bootstrap_calendar.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/gritter/css/jquery.gritter.css" rel="stylesheet" />
    <link href="https://immobilebusiness.com.br/admin/assets/plugins/morris/morris.css" rel="stylesheet" />
    <!-- ================== END PAGE LEVEL CSS STYLE ================== -->

    <!-- ================== BEGIN BASE JS ================== -->
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/pace/pace.min.js"></script>
    <!-- ================== END BASE JS ================== -->

    <link rel="shortcut icon" href="https:/immobilebusiness.com.br/home/favicon.ico">

    <style>
        @media (max-width: 767px) {
            .content {
                margin-top: 30% !important;
            }
        }

        .panel-body.no-padding,
        .panel-body.panel-form,
        .panel-body.panel-full-width,
        .panel-body.panel-table {
            padding: 0 !important;
            margin-top: 15px;
        }

        .cadastro {
            float: right;
            margin-top: 13px;
            font-size: 15px;
        }
    </style>
</head>

<body>
    <?php include_once "topo.php";
    include_once "func_painel.php";
    include_once "func_painel_inadimplencia.php";
    include "conexao.php";

    $recebe = mysqli_query($db, "SELECT * FROM usuario_sms WHERE status = '1'");
    if (mysqli_num_rows($recebe)) {
        while ($recebe = mysqli_fetch_assoc($recebe)) {
            $hash = $recebe['hash'];
            $senha = $recebe['senha'];
        }

        $dados['acao'] = 'consultar';
        $dados['hash'] = "$hash";
        $dados['senha'] = "$senha";
        $dado[] = json_encode($dados);

        // Estrutura da requisição
        $ch = curl_init("https://smsmobile.com.br/sms/routes/usuario.php");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $dado);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $server_output = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);

        $dados =  json_decode($server_output, true);

        $nome       = $dados['dados']['nome_user'];
        $email      = $dados['dados']['email_user'];
        $senha      = $dados['dados']['senha_user'];
        $cep        = $dados['dados']['cep_user'];
        $endereco   = $dados['dados']['endereco_user'];
        $cidade     = $dados['dados']['cidade_user'];
        $estado     = $dados['dados']['estado_user'];
        $telefone   = $dados['dados']['telefone_user'];
        $cpf        = $dados['dados']['cpf'];
        $numero     = $dados['dados']['numero'];
        $bairro     = $dados['dados']['bairro'];
    }

    ?>

    <div id="page-container" class="fade in page-sidebar-fixed page-header-fixed">
        <div id="content" class="content">
            <!-- Area de cadastro do usuario -->
            <div class="row">
                <!-- begin col-6 -->
                <div class="col-md-12">
                    <!-- begin panel -->
                    <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                        <div class="panel-heading">
                            <h4 class="panel-title">Formulario de Cadastro</h4>
                        </div>
                        <div class="panel-body panel-form">
                            <form action="routes_usuario_sms.php" data-parsley-validate="true" name="cadastro" method="POST">
                                <div class="form-group col-md-6">
                                    <label class="control-label"><strong>Nome:</strong></label>
                                    <input class="form-control" type="text" name="nome" value="<?php echo "$nome"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label " for="email"><strong>Email:</strong></label>
                                    <input class="form-control" type="text" name="email" value="<?php echo "$email"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Senha:</strong></label>
                                    <input class="form-control" type="password" name="senha" value="<?php echo "$senha"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Cep:</strong></label>
                                    <input class="form-control" type="text" name="cep" value="<?php echo "$cep"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Estado:</strong></label>
                                    <input class="form-control" type="text" name="estado" value="<?php echo "$estado"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>CPF:</strong></label>
                                    <input type="tel" class="form-control" id="cpf" name="cpf" value="<?php echo "$cpf"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Bairro:</strong></label>
                                    <input class="form-control" type="text" name="bairro" value="<?php echo "$bairro"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Numero:</strong></label>
                                    <input class="form-control" type="text" name="numero" value="<?php echo "$numero"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Cidade:</strong></label>
                                    <input class="form-control" type="text" name="cidade" value="<?php echo "$cidade"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Telefone:</strong></label>
                                    <input type="tel" class="form-control" id="telefone" name="telefone" value="<?php echo "$telefone"; ?>" required />
                                </div>

                                <div class="form-group col-md-6">
                                    <label class="control-label "><strong>Endereço:</strong></label>
                                    <input class="form-control col-md-6" type="text" name="endereco" value="<?php echo "$endereco"; ?>" required />
                                </div>

                                <div class="form-group col-md-12">
                                    <label class="control-label "></label>
                                    <?php
                                    $recebe = mysqli_query($db, "SELECT * FROM usuario_sms WHERE status = '1'");
                                    if (mysqli_num_rows($recebe)) {
                                        ?>
                                        <button type="submit" id="cadastro" name="alterar_usuario" class="btn btn-primary">Alterar</button>
                                        <i class="ion-checkmark fa-2x text-inverse">
                                            <label class="cadastro" style="color:#00FF00;"><i class="fa fa-check fa-2x"></i> <strong>Usuario Cadastrado</strong></label>
                                        <?php
                                        } else {
                                            ?>
                                            <button type="submit" id="cadastro" name="cadastra_usuario" class="btn btn-primary">Cadastrar</button>
                                            <label class="cadastro" style="color:#ff0000;"><i class="fa fa-close fa-2x"></i> <strong>Usuario Não Cadastrado</strong></label>
                                        <?php
                                        }
                                        ?>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-1.9.1.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/ui/minified/jquery-ui.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-cookie/jquery.cookie.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/morris/raphael.min.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/plugins/morris/morris.js"></script>
    <script src="https://immobilebusiness.com.br/admin/assets/js/apps.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.min.js"></script>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


    <?php
    $status = -1;
    if (isset($_GET['status'])) {
        $_GET['status'] == 1 ? $status = 1 : $status = 0;
    }

    if ($status == 1) {
        ?>
        <script>
            swal("Dados salvados com Sucesso", "", "success")
        </script>
    <?php
    } elseif ($status == 0) {
        ?>
        <script>
            swal("Seus dados Não foram salvados", "", "error")
        </script>
    <?php
    }
    ?>

    <script>
        $(document).ready(function() {
            App.init();
            TableManageButtons.init();
        });
    </script>

    <script>
        // mascara do cpf
        $('#cpf').mask('000.000.000-00', {
            reverse: true
        });
    </script>

    <script>
        jQuery("input#telefone")
            .mask("(99) 99999-9999")
            .focusout(function(event) {
                var target, phone, element;
                target = (event.currentTarget) ? event.currentTarget : event.srcElement;
                phone = target.value.replace(/\D/g, '');
                element = $(target);
                element.unmask();
                if (phone.length > 10) {
                    element.mask("(99) 99999-9999");
                } else {
                    element.mask("(99) 99999-9999");
                }
            });
    </script>

    <!--/* Executa a requisição quando o campo CEP perder o foco */-->
    <script>
        $(document).on('blur', 'input[name="cep"]', function() {
            /* Configura a requisição AJAX */

            $.ajax({
                url: 'consultar_cep.php',
                /* URL que será chamada */
                type: 'POST',
                /* Tipo da requisição */
                data: 'cep=' + $(this).val(),
                /* dado que será enviado via POST */
                dataType: 'json',
                /* Tipo de transmissão */
                success: function(data) {
                    $('input[name="estado"]').val(data.estado);
                    $('input[name="endereco"]').val(data.rua);
                    $('input[name="cidade"]').val(data.cidade);
                    $('input[name="bairro"]').val(data.bairro);
                }
            });
            return false;
        })
    </script>

</body>

</html>