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

// Excluir Sorteio
if(isset($_POST['excluir']) && $_POST['excluir'] == 'postagem') {

  $id_blog = $_POST['id'];

  $sql_excluir = $bd->getConexao()->prepare('DELETE FROM blog WHERE id = :id');
  $sql_excluir->bindValue(':id', $id_blog, PDO::PARAM_STR);
  if ($sql_excluir->execute()) ;
}


// BLOG - REGISTROS
$sql_blog = $bd->getConexao()->prepare('
SELECT blog.*,
  DATE_FORMAT(blog.data,"%d/%m/%Y") AS data_post,
  mk1.titulo as marker_titulo1,
  mk2.titulo as marker_titulo2,
  mk3.titulo as marker_titulo3
FROM blog
  LEFT JOIN blog_markers as mk1 ON mk1.id = blog.inf1
  LEFT JOIN blog_markers as mk2 ON mk2.id = blog.inf2
  LEFT JOIN blog_markers as mk3 ON mk3.id = blog.inf3
ORDER BY blog.data DESC');
if( $sql_blog->execute() ) { $resul_blog = $sql_blog->fetchall(PDO::FETCH_ASSOC);}

//Configurações do Controle
$valor_liberado = '1';
$valor_bloqueado = '0';

?>
<!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>
  <link rel="stylesheet" href="js/checkbox/jquery.checkbox.css" />

  <script type="text/javascript" language="javascript" class="init">

    // Script Modal Excluir Cadastro
    $(document).ready(function(){
      $("#modal_excluir").on('show.bs.modal', function(event){
        var button = $(event.relatedTarget);
        var id = button.data('id');
        $(this).find('.id').val(id);
      });
    });

    // Script Modal Registro de Entradas e Saídas
    $(document).ready(function(){
      $("#modal_editar").on('show.bs.modal', function(event){
        var button = $(event.relatedTarget);
        var id = button.data('id');
        $('.modal_editar_conteudo').load('modal/sorteios_editar.php?reg='+id)
      });
    });

    $(document).ready(function() {
      $('#sorteios').DataTable({

        stateSave: false, // Salvar última pesquisa
        "dom": '<"top"fl>rt<"bottom"ip><"clear">', // Layout
        "pagingType": "full_numbers", // Modo Paginação
        "iDisplayLength": 50,

        "aoColumns": [
          null,
          null,
          null,
          null,
          null,
          null,
          null
        ],

        "language": { // Tradução
          "lengthMenu": "Resultados por P&aacute;gina: _MENU_ ",
          "zeroRecords": "N&atilde;o existe Registros para esta pesquisa",
          "info": "P&aacute;gina _PAGE_ de _PAGES_",
          "infoEmpty": "N&atilde;o existe Registros para esta pesquisa",
          "infoFiltered": "(Filtrando de um total de _MAX_ Registros)",
          "search": "Localizar Registro: ",
          "paginate": {
            "first": "Primeira",
            "previous": "Anterior",
            "next": "Pr&oacute;xima",
            "last": "&Uacute;ltima"
          }
        }
      });
    });

    $(document).ready(function() {
      $('input:checkbox:not([safari])').checkbox();
      $('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});
      //$('input:radio').checkbox();
    });

    changeStyle = function(skin)
    {
      jQuery('#myform :checkbox').checkbox((skin ? {cls: skin} : {}));
    }

    $(document).ready(function(){
      $("input[name='status[]']").click(function(){
        var $this = $( this );//guardando o ponteiro em uma variavel, por performance

        var status = $this.attr('checked') ? <?php echo $valor_bloqueado ?> : <?php echo $valor_liberado ?>;
        var id = $this.attr('id');

        var tabela = $this.attr('tabela');
        var controle = $this.attr('controle');
        timestamp()
        $.ajax({
          url: 'js/checkbox/checkbox_bd.php',
          type: 'GET',
          data: 'status='+status+'&id='+id+'&tabela='+tabela+'&controle='+controle+'&time='+dataTimeF,
          success: function(resultado){
            console.log(resultado)
          }

        });

        if($this.attr('checked')){
          $this.attr("checked", false);
        }else{
          $this.attr("checked", true);
        }

      });
    });

    function timestamp(){
      var dataTime = new Date();
      dia  = dataTime.getDate().toString();
      mes  = dataTime.getMonth().toString();
      ano  = dataTime.getFullYear().toString();
      hora = dataTime.getHours().toString();
      min = dataTime.getMinutes().toString();
      sec = dataTime.getSeconds().toString();
      dataTimeF = dia+mes+ano+hora+min+sec
    }

  </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">Blog</h3>

</div>

<section id="content" class="content-sidebar bg-white" style="padding-bottom: 100px">
<section class="main">
<br>

  <div class="col-lg-12">
    <section class="panel">
      <header class="panel-heading">
        <span class="pull-right"><a href="blog_postagem.php" class="btn btn-inverse btn-xs">Nova Postagem</a></span>
        <div style="margin-top: 5px">Postagens</div>
      </header>
      <div class="table-responsive">
        <table id="sorteios" class="table table-striped b-t text-small">
          <thead>
          <tr>
            <th class="text-center" width="10"></th>
            <th class="text-center" width="10">Data</th>
            <th class="text-center">T&iacute;tulo</th>
            <th class="text-center">Mk1</th>
            <th class="text-center">Mk2</th>
            <th class="text-center">Mk3</th>
            <th class="text-center" width="10">Controle</th>
          </tr>
          </thead>
          <tbody>
          <?php foreach($resul_blog as $breg){

            if($breg['status'] == 1){
              $checked = 'checked="checked"';  }else{
              $checked = '';  }

          ?>
            <tr>
              <td>
                <div class="btn-group">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-pencil-square-o fa-lg" data-toggle="tooltip" data-placement="top" title="Editar"></i></a>
                  <ul class="dropdown-menu pull-left">
                    <li><a href="blog_postagem.php?p=<?php echo $breg['id']?>">Editar</a></li>
                    <li><a data-toggle="modal" href="#modal_excluir" data-backdrop="static" data-id="<?php echo $breg['id']?>">Excluir</a></li>
                  </ul>
                </div>
              </td>
              <td class="text-center"><?php echo $breg['data_post'] ?></td>
              <td class="text-center"><?php echo $breg['titulo'] ?></td>
              <td class="text-center"><?php echo $breg['marker_titulo1'] ?></td>
              <td class="text-center"><?php echo $breg['marker_titulo2'] ?></td>
              <td class="text-center"><?php echo $breg['marker_titulo3'] ?></td>
              <td class="text-center">
                <div class="top5 text-center">
                  <input type="checkbox" name="status[]" class="top5" <?php echo $checked?> id="<?php echo $breg['id']?>" tabela="blog" controle="status"/>
                </div>
              </td>
            </tr>
          <?php } ?>
          </tbody>
        </table>
      </div>
    </section>
  </div>

</section>
</section>

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

<!-- Modal Excluir -->
<div id="modal_excluir" class="modal fade bs-example-modal-sm">
  <form class="m-b-none" method="post" action="" enctype="multipart/form-data">
    <input type="hidden" name="excluir" value="postagem" />
    <input type="hidden" class="id" name="id" value=""/>
    <div class="modal-dialog modal-sm" style="width: 350px;">
      <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">Excluir Postagem</h4>
        </div>
        <div class="modal-body">
          <div class="row">
            <div class="col-lg-12 text-center">
              Tem certeza que deseja excluir a postagem?
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Cancelar</button>
          <button type="submit" class="btn btn-sm btn-info" data-loading-text="Excluindo..">Excluir</button>
        </div>
      </div>
    </div>
  </form>
</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>
<!-- checkbox -->
<script src="js/checkbox/jquery.checkbox.min.js"></script>

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