<?php
ob_start();
session_start();
require('../_app/Config.inc.php');

$login = new Login(1);
$logoff = filter_input(INPUT_GET, 'logoff', FILTER_VALIDATE_BOOLEAN);
$getexe = filter_input(INPUT_GET, 'exe', FILTER_DEFAULT);

if (!$login->CheckLogin()):
    unset($_SESSION['usuariologin']);
    header('Location: index.php?exe=restrito');
else:
    $usuariologin = $_SESSION['usuariologin'];
    $avatar = (empty($_SESSION['usuariologin']['usuario_avatar']) ? 'avatar_small.png' : $_SESSION['usuariologin']['usuario_avatar']);
endif;

if ($logoff):
    $arrUpDado['acesso_logado'] = 0;
    $Update = new Update;
    $Update->ExeUpdate("tp_acessos", $arrUpDado, "WHERE usuario_id = :id", "id={$_SESSION['usuariologin']['usuario_id']}");
    unset($_SESSION['usuariologin']);
    header('Location: index.php?exe=logoff');
endif;
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="UTF-8">
        <title>Área Restrita - Adeltec</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <!-- END GLOBAL MANDATORY STYLES -->
        <!-- BEGIN THEME GLOBAL STYLES -->
        <link href="assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
        <!-- END THEME GLOBAL STYLES -->
        <!-- BEGIN PAGE LEVEL STYLES -->
        <link href="assets/pages/css/pricing.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/apps/css/inbox.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/pages/css/profile.min.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL STYLES -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-summernote/summernote.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/jquery-nestable/jquery.nestable.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME LAYOUT STYLES -->
        <link href="assets/layouts/layout3/css/layout.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/layouts/layout3/css/themes/default.min.css" rel="stylesheet" type="text/css" id="style_color" />
        <!--        <link href="assets/layouts/layout3/css/custom.min.css" rel="stylesheet" type="text/css" />
                
                <link href="assets/layouts/layout/css/layout.min.css" rel="stylesheet" type="text/css" />
                <link href="assets/layouts/layout/css/themes/light.min.css" rel="stylesheet" type="text/css" id="style_color" />-->
        <link href="assets/layouts/layout/css/custom.css" rel="stylesheet" type="text/css" id="style_color" />
        <!-- END THEME LAYOUT STYLES -->
        <link rel="shortcut icon" href="<?= INCLUDE_PATH; ?>/img/favicon.png" />
        <!-- JQUERY -->
        <script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script> 
        <script src="assets/global/plugins/jquery.form.js" type="text/javascript"></script> 
    </head>

    <body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white">
        <!-- BEGIN HEADER -->
        <div class="page-header">
            <!-- BEGIN HEADER TOP -->
            <div class="page-header-top">
                <div class="container-fluid">
                    <!-- BEGIN LOGO -->
                    <div class="page-logo">
                        <a href="./">
                            <img src="images/logo-adeltec-big.png" alt="logo" class="logo-default" />
                        </a>
                    </div>
                    <!-- END LOGO -->

                    <!-- BEGIN RESPONSIVE MENU TOGGLER -->
                    <a href="javascript:;" class="menu-toggler"></a>
                    <!-- END RESPONSIVE MENU TOGGLER -->
                    <!-- BEGIN TOP NAVIGATION MENU -->
                    <div class="top-menu">
                        <ul class="nav navbar-nav pull-right">
                            <!-- BEGIN USER LOGIN DROPDOWN -->
                            <li class="dropdown dropdown-user dropdown-dark">
                                <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                    <img alt="" class="img-circle" src="uploads/users/<?= $avatar ?>" />
                                    <span class="username username-hide-on-mobile"> <?= $_SESSION['usuariologin']['usuario_nome'] ?> </span>
                                </a>
                                <ul class="dropdown-menu dropdown-menu-default">
                                    <li>
                                        <a href="#alterar_senha" data-toggle="modal">
                                            <i class="icon-key"></i> Senha </a>
                                    </li>
                                    <li class="divider"> </li>
                                    <li>
                                        <a href="painel.php?logoff=true">
                                            <i class="icon-logout"></i> Logouf 
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <!-- END USER LOGIN DROPDOWN -->

                        </ul>
                    </div>
                    <!-- END TOP NAVIGATION MENU -->
                </div>
            </div>
            <!-- END HEADER TOP -->
            <!-- BEGIN HEADER MENU -->
            <div class="page-header-menu">
                <div class="container-fluid">
                    <!-- BEGIN MEGA MENU -->
                    <!-- DOC: Apply "hor-menu-light" class after the "hor-menu" class below to have a horizontal menu with white background -->
                    <!-- DOC: Remove data-hover="dropdown" and data-close-others="true" attributes below to disable the dropdown opening on mouse hover -->
                    <div class="hor-menu  ">
                        <ul class="nav navbar-nav">

                            <li class="">
                                <a href="painel.php"> 
                                    <i class="fa fa-dashboard"></i> Dashboard
                                    <span class="arrow"></span>
                                </a>
                            </li>
                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Cadastros
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="">
                                        <a href="./painel.php?exe=categoria/lista-noticia" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Categorias das Notícias
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=categoria/lista-produto" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Categorias dos Produtos
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=cliente/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Clientes
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=destinatario/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Destinatários
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=produto/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Produtos
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=servico/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Serviços
                                        </a>                                        
                                    </li>
                                </ul>
                            </li>
                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Post
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="">
                                        <a href="./painel.php?exe=banner/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Banner
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=pagina/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Pagina
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=noticias/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Noticias
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Contatos
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="">
                                        <a href="./painel.php?exe=contato/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Contatos
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=lead/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Leads
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=newsletter/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Newsletter
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=os/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Ordem de serviços
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=proposta/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Propostas
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Usuarios
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="">
                                        <a href="./painel.php?exe=usuario/perfil-lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Perfil
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=usuario/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Usuarios
                                        </a>
                                    </li>
                                </ul>
                            </li>
                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Configuração
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="">
                                        <a href="./painel.php?exe=acesso/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Acesso
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=informacao/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Informações
                                        </a>
                                    </li>
                                    <li>
                                        <a href="./painel.php?exe=log/lista" class="nav-link">
                                            <i class="fa fa-list-ul"></i> Logs
                                        </a>
                                    </li>
                                </ul>
                            </li>
<!--                            <li class="menu-dropdown classic-menu-dropdown ">
                                <a href="javascript:;">
                                    <i class="fa fa-gear"></i> Configuração
                                    <span class="arrow"></span>
                                </a>
                                <ul class="dropdown-menu pull-left">
                                    <li class="dropdown-submenu ">
                                        <a href="javascript:;" class="nav-link nav-toggle ">
                                            <i class="fa fa-list-ul"></i> Parametros
                                            <span class="arrow"></span>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li class=" ">
                                                <a href="./painel.php?exe=sistema/periodo_lista" class="nav-link ">
                                                    <i class="fa fa-calendar"></i> Periodo </a>
                                            </li>
                                            <li class=" ">
                                                <a href="./painel.php?exe=sistema/plano_lista" class="nav-link ">
                                                    <i class="fa fa-user-plus"></i> Planos </a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>-->

                        </ul>
                    </div>
                    <!-- END MEGA MENU -->
                </div>
            </div>
            <!-- END HEADER MENU -->
        </div>
        <!-- END HEADER -->

        <!-- BEGIN HEADER & CONTENT DIVIDER -->
        <div class="clearfix"> </div>
        <!-- END HEADER & CONTENT DIVIDER -->
        <div class="page-container">
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper" id="painel">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                    <div class="container-fluid">
                        <?php
                        //QUERY STRING
                        if (!empty($getexe)):
                            $includepatch = __DIR__ . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . strip_tags(trim($getexe) . '.php');
                        else:
                            $includepatch = __DIR__ . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'home.php';
                        endif;

                        if (file_exists($includepatch)):
                            require_once($includepatch);
                        else:
                            echo "<div class=\"content notfound\">";
                            WSErro("<b>Erro ao incluir tela:</b> Erro ao incluir o controller /{$getexe}.php!", WS_ERROR);
                            echo "</div>";
                        endif;
                        ?>
                    </div>
                </div>
            </div>
            <!-- END CONTENT BODY -->
        </div>
        <!-- Modal -->
        <div class="modal fade" id="modal_depo" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" style="color: #000">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">Deixei seu depoimento sobre a nossa platafoma.</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-12">
                                <form class="contact-form form-horizontal formulario j_depoimento">
                                    <div class="form-group">
                                        <div class="col-lg-12">
                                            <textarea class="form-control" name="depoimento_descricao" id="depoimento_descricao" rows="3" placeholder="Deixe seu depoimento aqui..."></textarea>
                                        </div>
                                    </div>

                                    <button type="submit" class="btn btn-yellow radius mg-top-10">Enviar Depoimento</button>

                                </form>

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

        <!-- BEGIN FOOTER -->
        <div class="page-footer">
            <div class="container-fluid"> &copy; <?= date('Y') ?> - Adeltec, Todos os Direitos Reservados!
            </div>
        </div>
        <div class="scroll-to-top">
            <i class="icon-arrow-up"></i>
        </div>
        <!-- END FOOTER -->

    </body>
    <!--- MODAL ALTERAR SENHA -->
    <div class="modal fade bs-modal-sm" id="alterar_senha" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Digite sua nova senha</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="formUpPass" name="PassForm" method="POST" action="" enctype="multipart/form-data">
                        <div class="form-body">
                            <div class="form-group ">
                                <label class="col-md-4 control-label" for="form_control_1">Nova Senha
                                    <span class="required">*</span> 
                                </label>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" placeholder="" name="usuario_senha" id="campo_senha">
                                    <div class="form-control-focus"> </div>
                                </div>
                            </div>
                            <div class="form-group ">
                                <label class="col-md-4 control-label" for="form_control_1">Confirmar Nova Senha
                                    <span class="required">*</span> 
                                </label>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" placeholder="" name="confirmar_senha">
                                    <div class="form-control-focus"> </div>
                                </div>
                            </div>

                        </div>
                        <div class="form-actions">
                            <div class="row">
                                <div class="col-md-offset-4 col-md-8">
                                    <button type="submit" name="SendPostForm" value="enviar" class="btn btn-success">
                                        <i class="fa fa-save"></i> <span class="hidden-xs"> Alterar Senha</span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <!--                <div class="modal-footer">
                                    <button type="button" class="btn blue" data-dismiss="modal">OK</button>
                                </div>-->
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!--- MODAL ALTERAR SENHA --->

    <!-- BEGIN CORE PLUGINS -->   
    <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!--    <script src="assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/plupload/js/plupload.full.min.js" type="text/javascript"></script>-->
    <!-- BEGIN THEME GLOBAL SCRIPTS -->
    <script src="assets/global/scripts/app.min.js" type="text/javascript"></script>
    <!--<script src="assets/pages/scripts/ecommerce-products-edit.min.js" type="text/javascript"></script>-->
    <script src="assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-wysihtml5/wysihtml5-0.3.0.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-markdown/lib/markdown.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-markdown/js/bootstrap-markdown.js" type="text/javascript"></script>
    <script src="assets/global/plugins/bootstrap-summernote/summernote.min.js" type="text/javascript"></script>
    <!--
    <script src="assets/global/plugins/jquery-nestable/jquery.nestable.js" type="text/javascript"></script>
    <script src="assets/pages/scripts/ui-nestable.min.js" type="text/javascript"></script>
    -->
    <!-- END THEME GLOBAL SCRIPTS -->
    <!-- BEGIN PAGE LEVEL SCRIPTS -->
    <script src="assets/apps/scripts/inbox.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="__jsc/combo.js"></script>
    <script type="text/javascript" src="__jsc/script.js"></script>
    <!-- END PAGE LEVEL SCRIPTS -->
    <!-- BEGIN THEME LAYOUT SCRIPTS -->
    <script src="assets/layouts/layout/scripts/layout.min.js" type="text/javascript"></script>
    <script src="assets/layouts/layout/scripts/demo.min.js" type="text/javascript"></script>
    <script src="assets/layouts/global/scripts/quick-sidebar.min.js" type="text/javascript"></script>
    <!-- END THEME LAYOUT SCRIPTS -->

    <script src="assets/global/plugins/jquery.validate.min.js" type="text/javascript"></script>
    <script>
        $(function () {
            // Ação de validação e cadastro do formulario de usuario
            $("#formUpPass").validate({
                //definir as regras
                rules: {
                    usuario_senha: {
                        required: true, minlength: 5
                    },
                    confirmar_senha: {
                        required: true, minlength: 5, equalTo: "#campo_senha"
                    }
                },
                //Definir as mensagens de erro para cada regra
                messages: {
                    usuario_senha: {
                        required: "O campo senha é obrigatório", minlength: "precisar ter no mínimo 5 números"
                    },
                    confirmar_senha: {
                        required: "A confirmação é obrigatório", minlength: "precisar ter no mínimo 5 números", equalTo: "Senha não são iguais"
                    }
                },
                submitHandler: function (form) {
                    var dados = $(form).serialize();
                    $(".trigger").remove();
                    console.log(dados);
                    $.ajax({
                        type: "POST",
                        url: "__jsc/ajax/senha_up.php",
                        data: dados,
                        dataType: 'json',
                        success: function (data)
                        {
                            console.log(data);
                            if (data.error[1] == 'accept') {
                                console.log('sucesso')
//                                document.location.href = 'painel.php?exe=usuario/index&create=true';
                                $("<div class=\"trigger trigger-" + data.error[1] + "\">" + data.error[0] + "</div>").prependTo("#formUpPass");
                            } else {
                                $("<div class=\"trigger trigger-" + data.error[1] + "\">" + data.error[0] + "</div>").prependTo("#formUpPass");
                            }
                        }
                    });

                    return false;
                }
            });

            //função de atualizar acesso
            function conectado() {
                $.ajax({
                    type: "POST",
                    url: '__jsc/ajax/usuario_ping.php',
                    dataType: 'json',
                    success: function (data)
                    {
                        console.log(data)
                        if (data.retorno == 'Desconectado') {
                            document.location.href = 'painel.php?logoff=true';
                        } else {
                            setTimeout(conectado, 10000);
                        }
                    }
                });
            }

            //atualização para informar o usuario logado
            setTimeout(conectado, 10000);
        });
    </script>

</html>
<?php ob_end_flush(); ?>