<?php
   define(URL_BASE, '/simulador');
   define(PATH_BASE, '/views/simulador');
   include $_SERVER["DOCUMENT_ROOT"].'/inc/conexao.php';
   include $_SERVER["DOCUMENT_ROOT"].'/api/api.php';
   include $_SERVER["DOCUMENT_ROOT"].'/inc/functions.php';

   // ini_set('display_errors',1);
   // ini_set('display_startup_erros',1);
   // error_reporting(E_ALL);


   $urlbase = $_SERVER['SERVER_NAME'].$_SERVER ['REQUEST_URI'];
   $parts = parse_url($urlbase);
   parse_str($parts['query'], $query);
   foreach ($query as $k => $v) { $_GET[$k] = $v; }
?>
<!DOCTYPE html>
<html lang="pt-BR">
   <head>
      <meta charset="utf-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
      <title>Apostas</title>
      <meta content="Apostas esportivas" name="description" />
      <meta content="Betbox" name="author" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <link rel="stylesheet" href="/views/simulador/css/style.css">
      <link rel="stylesheet" href="/assets/vendor_components/bootstrap/dist/css/bootstrap.css">
      <link type="text/css" rel="stylesheet" href="http://fscores.sysfbet.com.br/css/flags.css?v=5">
      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
   </head>
   <body>
      <section id="top">
         <div class="container">
            <div class="row">
               <div class="col-lg-4 col-md-4 col-sm-12 col-12 logo"><a href="<?php echo URL_BASE; ?>/home"><img src="http://www.bets123.club/img/sao_paulo.png" alt=""></a></div>
               <div class="col-lg-3 col-md-3 col-sm-12 col-12 login">
                  <a href="" class="btn btn-danger bg-danger2 btn-flat btn-lg">Cadastre-se</a>
                  <span class="ou">ou</span>
               </div>
               <div class="col-lg-5 col-md-5 col-sm-12 col-12 login" id="loadingData">
                  <?php if(!isset($_SESSION["usuario"])){ ?>
                  <form action="/api/login" method="POST" id="loginForm">
                     <input type="text" name="user" class="form-control" placeholder="Usuário" />
                     <input type="password" name="pass" class="form-control itemSenha" placeholder="Senha" />
                     <button type="submit" class="btn btn-info btn-flat" id="btnLoginForm">Entrar</button>
                  </form>
                  <?php } else { ?>
                  <div class="logged_user">Olá, <b><?php echo utf8_encode($_SESSION["usuario"]["nome"]); ?></b>! &nbsp; <a href="/sair" class="btn btn-danger btn-xs btn-flat">Sair</a></div>
                  <?php } ?>
               </div>
            </div>
         </div>
      </section>
      <section id="menu">
         <div class="container">
            <div class="row menu_bg">
               <div class="col-12">
                  <ul class="menu">
                     <li class="sports_menu">
                        <select id="sportMenu" name="" class="form-control btn-flat" id="">
                            <?php
                              $perms = $_SESSION["usuario"]["permissoes"];
                              $sql = $mysqli->query("SELECT * FROM esportes WHERE esporte_exibido = '1' ORDER BY esporte_ordem ASC");
                              while($e = $sql->fetch_assoc()){
                                if($e["esporte_codigo"] == 'aovivo'){ continue; } else {
                                  if(isset($_SESSION["usuario"]) && !in_array($e["esporte_codigo"], $perms) && !in_array('betAllSports', $perms)){ continue; }
                                }
                                echo '<option '; if(utf8_encode($e["esporte_codigo"]) == $_GET['esporte'] || (!isset($_GET['esporte']) && utf8_encode($e["esporte_codigo"]) == 'futebol')){ echo 'selected'; } echo ' value="'.URL_BASE.'/home?esporte='.utf8_encode($e["esporte_codigo"]).'">'.utf8_encode($e["esporte_nome"]).'</option>';
                              }
                            ?>
                        </select>
                     </li>
                     <li><a class="<?php if($_GET['page'] == 'aovivo'){ echo 'active'; } ?>" href="<?php echo URL_BASE; ?>/aovivo">Ao Vivo</a></li>
                     <li><a class="<?php if($_GET['page'] == 'consultar-bilhete'){ echo 'active'; } ?>" href="<?php echo URL_BASE; ?>/consultar-bilhete">Consultar Bilhete</a></li>
                     <li><a class="<?php if($_GET['page'] == 'regulamento'){ echo 'active'; } ?>" href="<?php echo URL_BASE; ?>/regulamento">Regulamento</a></li>
                     <li><a href="https://play.google.com/store/apps/details?id=com.fbet.apostas">Baixar APP</a></li>
                     <?php
                        if(in_array('21', $perms)){ echo '<li><a href="'.URL_BASE.'/caixa?type=personal">Caixa</a></li>'; }
                        if(isset($_SESSION["usuario"])){
                     ?>
                        <li><a href="/nova-aposta">Acessar Sistema</a></li>
                        <li class="pull-right"><a href="#">Crédito: <b>R$<?php echo formataReal($_SESSION["usuario"]["credito"]); ?></b></a></li>
                     <?php
                        }
                     ?>
                  </ul>
               </div>
            </div>
         </div>
      </section>