<?php include('fncr-geral/configuracao_geral.php');
$pagina = "suporte";
$blq_pag = "suporte_logs";
include('fncr-geral/permissoes_restricao.php');

$sql = $bd->getConexao()->prepare('
SELECT
  DATE_FORMAT(l.data_hora,"%d/%m/%Y - %H:%i") AS data_hora,
  l.id,
  IF(l.post_json is null, 1, 0) as acesso,
  u.nome as usuario,
  c.nome as clube
FROM usuarios_logs l
  LEFT JOIN usuarios_suporte u ON u.id = l.usuario_id
  LEFT JOIN clubes c ON c.id = l.clube_id
WHERE (l.usuario_id=1 AND l.post_json is null OR l.usuario_id>1) AND c.interno = 0
ORDER BY l.data_hora DESC LIMIT 500');
if($sql->execute()){$logs = $sql->fetchall(PDO::FETCH_ASSOC);}

?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
  <?php include('fncr-geral/html-head.php');?>

  <link rel="stylesheet" type="text/css" href="js/datatables2/media/css/jquery.dataTables.css">
  <script type="text/javascript" language="javascript" src="js/datatables2/media/js/jquery.dataTables.js"></script>

  <script type="text/javascript" language="javascript" class="init">
    $(document).ready(function() {
      $('#logs').DataTable({
        stateSave: false, // Salvar última pesquisa
        "dom": '<"top"fl>rt<"bottom"ip><"clear">', // Layout
        "pagingType": "full_numbers", // Modo Paginação
        "iDisplayLength": 50,
        "order":[],
        "language": { // Tradução
          "lengthMenu": "Resultados por P&aacute;gina: _MENU_ ",
          "zeroRecords": "N&atilde;o existe Clubes para esta pesquisa",
          "info": "P&aacute;gina _PAGE_ de _PAGES_",
          "infoEmpty": "N&atilde;o existe Clubes para esta pesquisa",
          "infoFiltered": "(Filtrando de um total de _MAX_ Clubes)",
          "search": "Localizar Clubes: ",
          "paginate": {
            "first": "Primeira",
            "previous": "Anterior",
            "next": "Pr&oacute;xima",
            "last": "&Uacute;ltima"
          }
        }
      });
    });

    function getJson(id){
      $.ajax({
        url: 'scripts/suporte/script_ajax.php',
        type: 'POST', cache: false,
        data:{
          acao: "log_post_json",
          registro: id
        },
        success: function(r){
          $('#modal_log_json #json_conteudo').html(r)
          $('#modal_log_json').modal('show')
        }
      });
    }

  </script>

</head>
<body>

<!-- BARRA SUPERIOR -->
<?php include('barra-sup.php');?>
<!-- MENU PRINCIPAL -->
<?php include('menu.php');?>

<section id="content">

<div class="clearfix padder bg-fncr-clearfix">
  <h3 class="m-b">Clubes Ativos</h3>
</div>

<section id="content" class="content-sidebar bg-white">
<section class="main">

<div class="col-lg-12" style="margin-top: 15px">
  <section class="panel">
    <header class="panel-heading">
      Logs
    </header>
    <div class="table-responsive">
      <table id="logs" class="table table-striped b-t text-small">
        <thead>
        <tr>
          <th class="text-center" width="120">Data / Hora</th>
          <th>Usuário</th>
          <th>Clube</th>
          <th width="270">Tipo</th>
          <th width="1"></th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($logs as $l){ ?>
          <tr>
            <td><?php echo $l['data_hora']?></td>
            <td><?php echo $l['usuario']?></td>
            <td><?php echo $l['clube']?></td>
            <td class="text-center"><?php echo $l['acesso']==1 ? "Acesso / Login" : "Ação"?></td>
            <td class="text-center">
              <?php if($l['acesso']==0){ ?>
                <a href="javascript:void(0)" onclick="getJson(<?php echo $l['id']?>)" class="btn btn-info btn-pagar" style="padding-top: 1px">Dados</a>
              <?php } ?>
            </td>
          </tr>
        <?php } ?>
        </tbody>
      </table>
    </div>
  </section>
</div>

</section>
</section>

<!-- FOOTER -->
<?php include('footer.php');?>

<div id="modal_log_json" class="modal fade bs-example-modal-sm">
  <div class="modal-dialog modal-sm" style="width: 500px;">
    <div class="modal-content">
      <div class="modal-header bg-info">
        <button type="button" class="close" data-dismiss="modal"><i class="fa fa-times"></i></button>
        <h4 class="modal-title" id="myModalLabel">Ação Realizada</h4>
      </div>
      <div class="modal-body"><div id="json_conteudo"></div></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Fechar</button>
      </div>
    </div>
  </div>
</div>

<!-- app -->
<script src="js/app.js"></script>
<script src="js/app.plugin.js"></script>
<script src="js/app.data.js"></script>
<!-- Sparkline Chart -->
<script src="js/charts/sparkline/jquery.sparkline.min.js"></script>
<!-- Easy Pie Chart -->
<script src="js/charts/easypiechart/jquery.easy-pie-chart.js"></script>
  <!-- select2 -->
<script src="js/select2/select2.min.js"></script>
  <!-- fuelux -->
<script src="js/fuelux/fuelux.js"></script>
<!-- datepicker -->
<script src="js/datepicker/bootstrap-datepicker.js"></script>
<!-- slider -->
<script src="js/slider/bootstrap-slider.js"></script>
<!-- file input -->
<script src="js/file-input/bootstrap.file-input.js"></script>
<!-- combodate -->
<script src="js/combodate/moment.min.js"></script>
<script src="js/combodate/combodate.js"></script>
<!-- parsley -->
<script src="js/parsley/parsley.min.js"></script>

</body>
</html>
<?php $bd = null; $bd_fn = null;?>