<?php
ob_start();
session_start();
require('../_app/Config.inc.php');
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <meta charset="utf-8" />
        <title><?= SITENAME ?> | Login</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="http://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/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <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/login.min.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/layouts/layout/css/custom.css" rel="stylesheet" type="text/css" id="style_color" />
        <!-- END PAGE LEVEL STYLES -->
        <link rel="shortcut icon" href="<?= INCLUDE_PATH; ?>/img/favicon.png" /> 
    </head>
    <body class="login">
        <!-- BEGIN LOGO -->
        <div class="logo">
            <a href="../">
                <img src="../img/layout/logo.png" alt="" width="160" />
            </a>
        </div>
        <!-- END LOGO -->
        <div id="login">
            <div class="content">

                <?php
                $login = new Login(1);
                if ($login->CheckLogin()):
                    header('Location: painel.php');
                endif;

                $dataLogin = filter_input_array(INPUT_POST, FILTER_DEFAULT);
                if (!empty($dataLogin['AdminLogin'])):

                    $login->ExeLogin($dataLogin);
                    if (!$login->getResult()):
                        WSErro($login->getError()[0], $login->getError()[1]);
                    else:
                        header('Location: painel.php');
                    endif;

                endif;

                $get = filter_input(INPUT_GET, 'exe', FILTER_DEFAULT);
                if (!empty($get)):
                    if ($get == 'restrito'):
                        WSErro('<b>Oppss:</b> Acesso negado. Favor efetue login para acessar o painel', WS_ALERT);
                    elseif ($get == 'logoff'):
                        WSErro('<b>Sucesso ao deslogar:</b> Sua sessão foi finalizada. Volte sempre!', WS_ACCEPT);
                    elseif ($get == 'confirmar'):
                        WSErro('<b>Deu tudo certo!!!</b><br> Realize o seu Login agora e aproveite!', WS_INFOR);
                    endif;
                endif;
                ?>

                <!-- BEGIN LOGIN FORM -->
                <form name="AdminLoginForm" class="login-form" action="index.php" method="post">
                    <h3 class="form-title font-orange">Faça Login</h3>

                    <div class="form-group">
                        <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
                        <label class="control-label visible-ie8 visible-ie9">Usuario</label>
                        <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="Usuario" name="user" /> </div>
                    <div class="form-group">
                        <label class="control-label visible-ie8 visible-ie9">Senha</label>
                        <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="Senha" name="pass" /> </div>
                    <div class="form-actions">
                        <input type="submit" name="AdminLogin" value="Logar" class="btn orange uppercase" />
                        <a href="javascript:;" id="forget-password" class="forget-password">Esqueceu a senha?</a>
                    </div>
                </form>
                <!-- END LOGIN FORM -->
                <!-- BEGIN FORGOT PASSWORD FORM -->
                <form name="AdminEmailForm" class="forget-form" action="" method="post">
                    <h3 class="font-orange">Esqueceu sua senha ?</h3>
                    <p> Digite seu email abaixo para redefinir sua senha. </p>
                    <div class="form-group">
                        <input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="email" id="email" /> </div>
                    <div class="form-actions">
                        <button type="button" id="back-btn" class="btn orange btn-outline">Voltar</button>
                        <button type="submit" name="AdminEmail" id="AdminEmail" class="btn orange uppercase pull-right">Enviar</button>
                    </div>
                </form>
                <!-- END FORGOT PASSWORD FORM -->
            </div>
            <!--<div class="copyright"> Desenvolvido por <a href="www.tagpage.com.br" target="_blanck" title="TagPage" alt="TagPage"><img src="images/logo-tag.png" width="80"></a>. </div>-->
        </div>
        <!-- BEGIN CORE PLUGINS -->
        <script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $('#forget-password').click(function () {
                    jQuery('.login-form').hide();
                    jQuery('.forget-form').show();
                });

                $('#back-btn').click(function () {
                    jQuery('.login-form').show();
                    jQuery('.forget-form').hide();
                });

                $('.forget-form').submit(function () {
                    var dados = $(this).serialize();
                    $(".trigger").remove();
                    $.ajax({
                        url: '__jsc/ajax/esqueceu_senha.php',
                        data: dados,
                        type: 'POST',
                        dataType: 'json',
                        beforeSend: function () {
                            console.log('LOADING...');
                        },
                        success: function (data) {
                            console.log(data);
                            $("<div class=\"trigger trigger-" + data.error[1] + "\">" + data.error[0] + "</div>").prependTo(".forget-form");
                            if (data.error[1] == 'accept') {
                                $('#email').val('');
                            }
                        }
                    })

                    return false;
                })
            })
        </script>
        <!-- END CORE PLUGINS -->
    </body>
</html>
<?php ob_end_flush(); ?>