<?php 
    require_once(__DIR__."/../../config.php");
    
    $cs = new cs;
    if(!$cs->checkLog_unf()) { exit("<script>location='../../login';</script>"); }

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="<?= SITE_PAINEL; ?>/plugins/images/favicon.png">
    <title>Space Code 2.0 - Buscar Gerenciador</title>
    <!-- Bootstrap Core CSS -->
    <link href="../../public/assets/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../plugins/bower_components/bootstrap-extension/css/bootstrap-extension.css" rel="stylesheet">
    <!-- Menu CSS -->
    <link href="../../plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.css" rel="stylesheet">
    <!-- toast CSS -->
    <link href="../../plugins/bower_components/toast-master/css/jquery.toast.css" rel="stylesheet">
    <!-- morris CSS -->
    <link href="../../plugins/bower_components/morrisjs/morris.css" rel="stylesheet">
    <!-- animation CSS -->
    <link href="../../public/assets/css/animate.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="../../public/assets/css/style.css" rel="stylesheet">
    <!-- color CSS -->
    <link href="../../public/assets/css/colors/default-dark.css" id="theme" rel="stylesheet">
    <!-- dataTable CSS -->
    <!--  <link rel="stylesheet" href="<//?= BASE_URL; ?>/painel/plugins/bower_components/datatables/jquery.dataTables.min.css"> -->

    <!-- Editable CSS -->
    <link rel="stylesheet" href="../../plugins/bower_components/jquery-datatables-editable/datatables.css">
    
    <!-- SELECT 2 --> 
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
    <!-- DATAPICKER --> 
    <link href="../../plugins/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet">
    <!-- SWEETALERT --> 
    <link href="../../plugins/bower_components/sweetalert/sweetalert.css">
    

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
    <!-- <script>
    (function(i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r;
        i[r] = i[r] || function() {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
        a = s.createElement(o), m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m)
    })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-19175540-9', 'auto');
    ga('send', 'pageview');
    </script> -->
    
</head>

<?php     
    include_once(__DIR__."/../../layout/header.php");
    include_once(__DIR__."/../../layout/left-sidebar.php"); 
    include_once(__DIR__."/../../layout/breadcrumbs.php");

?>
   
	    <!-- Page Content -->
	    <div id="page-wrapper">
	        <div class="container-fluid">
	            <div class="row bg-title">
	                <div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
	                    <h4 class="page-title">Buscar Gerenciador</h4></div>
	                <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12"> 
	                    <?php echo breadcrumbs(); ?>
	                </div>
	                <!-- /.col-lg-12 -->
	            </div>

				<div class="row">
				    <div class="col-md-12">
	                    <div class="white-box">
	                        
	                        <div class="row">
	                            <div class="col-sm-12 col-xs-12">
	                                <form method="POST" id="search">
	                                	<input id="token" name="token" value="<?= $_SESSION['tkn_log'] = $cs->setToken(); ?>" type="hidden"/>
                                        <input type="hidden" id="usuario" name="usuario">
                                         
	                                </form>
                                    
	                            </div>
	                        </div>

                            <!-- Tabela DataTable -->
                            <div class="tableSearch m-t-10"> 
                                
                                <div id="editable-datatable" class="dataTables_wrapper form-inline dt-bootstrap">
                                    
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <table id="mainTable" class="table editable-table table-bordered table-striped" >
                                                <thead>
                                                    <tr >
                                                        <th class="selectAll m-center" ><div class="m-l-15"><button type="button" class="input btn btn-xs btn-default btn-outline waves-effect waves-light">All</button></div></th>
                                                        <th>Id</th>
                                                        <th>Login</th>
                                                        <th>Email</th>
                                                        <th>Celular</th>
                                                        <th>Vencimento</th>
                                                        <th>Status</th>
                                                        <th>Ativos</th>
                                                        <th>Pai</th>
                                                        <th>Acoes</th>
                                                    </tr>
                                                </thead>

                                                
                                            </table>
                                        </div>
                                    </div>
                                    
                                </div>
<!-- 
                                <button class="btn btn-default m-r-5">Ativar</button>
                                <button class="btn btn-default m-r-5">Desativar</button>
                                <button class="btn btn-default">Alterar Vencimento</button> -->
                            
                            </div>
                            <!-- End Tabela DataTable -->


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

               
	        <?php include_once(__DIR__."/../../layout/right-sidebar.php");?>
	        </div>
	        <!-- /.container-fluid -->
	        <?php include_once(__DIR__.'/../../layout/footer.php'); ?>
	    </div>
	    <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
    <!-- jQuery -->
    <script src="../../plugins/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="../../public/assets/bootstrap/dist/js/tether.min.js"></script>
    <script src="../../public/assets/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../../plugins/bower_components/bootstrap-extension/js/bootstrap-extension.min.js"></script>
    <!-- Menu Plugin JavaScript -->
    <script src="../../plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js"></script>
    <!--slimscroll JavaScript -->
    <script src="../../public/assets/js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="../../public/assets/js/waves.js"></script>
    <!-- Custom Theme JavaScript -->
    <script src="../../public/assets/js/custom.min.js"></script>

    <script src="../../plugins/bower_components/moment-js/moment.min.js"></script>   
    <!--Style Switcher -->
    <script src="../../plugins/bower_components/styleswitcher/jQuery.style.switcher.js"></script>
    <!--Style Switcher -->
    <script src="../../plugins/bower_components/styleswitcher/jQuery.style.switcher.js"></script>
    <!-- DATAPICKER --> 
    <script src="../../plugins/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>

    <script src="../../plugins/bower_components/jquery-datatables-editable/jquery.dataTables.js"></script> 
    <script src="../../plugins/bower_components/datatables/dataTables.bootstrap.js"></script> 
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
    <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>

    <script>
        $(document).ready( function() {
               
            var table = $('#mainTable').DataTable({
                        "language": {
                            "sEmptyTable": "Nenhum registro encontrado",
                            "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                            "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                            "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                            "sInfoPostFix": "",
                            "sInfoThousands": ".",
                            "sLengthMenu": "_MENU_ resultados por página",
                            "sLoadingRecords": "Carregando...",
                            "sProcessing": "Processando...",
                            "sZeroRecords": "Nenhum registro encontrado",
                            "sSearch": "Pesquisar",
                            "oPaginate": {
                                "sNext": "Próximo",
                                "sPrevious": "Anterior",
                                "sFirst": "Primeiro",
                                "sLast": "Último"
                            },
                            "oAria": {
                                "sSortAscending": ": Ordenar colunas de forma ascendente",
                                "sSortDescending": ": Ordenar colunas de forma descendente"
                            }
                        },
                        
                        responsive: true,
                        'ajax' : {
                            "url": "../ajax_search.php",
                            "type": "POST",
                            "data":   function( d ) {
                                d.usuario = $('#usuario').val()
                                d.token   = $('#token').val()
                                
                            },
                            dataSrc:"" 
                                     
                             
                        },
                        
                        select: true, 
                        
                        columns: [
                            {
                                className: "text-center",
                                sortable: false,
                                "render": function ( data, type, row, meta ) {
                                    
                                    return `<input type="checkbox" class="iCheck text-center" name="iCheck" value="${row.id}">`;
                                },
                                visible: false

                            },
                            
                            { data : "id" },
                            { data : "login" },
                            { data : "email" },
                            {   
                                className : "celular",
                                data      : "celular" 
                            },
                            {   
                                className : "vencimento", 
                                data      : "vencimento", 
                                render: function(data, type, row) {
                                    if(type === "sort" || type === "type"){
                                        return row.vencimento
                                    }
                                   
                                    return moment(new Date(row.vencimento)).format("DD/MM/YYYY"); 
                                }
                                
                            },
                            
                            { 
                                data : "status",
                                render: function(data, type, row) {
                                    
                                    if (new Date(row.vencimento) < Date.now()) {
                                        row.status = 'vencido'   
                                    }

                                    return row.status
                                   
                                     
                                }
                            },
                            { data : "ativos" },
                            { data : "pai_login" },
                            {
                                sortable: false,
                                "render": function ( data, type, row, meta ) {
                                    
                                    return `<a href='../visualizar/index.php?id=${row.id}'><button class='btn btn-sm btn-outline btn-default waves-effect waves-light'><i class="ti-eye"></i></button></a> 
                                            <a href='../editar/index.php?id=${row.id}'><button class='btn btn-sm btn-outline btn-default waves-effect waves-light'><i class="ti-pencil-alt"></i></button></a>`;
                                }
                                

                            }, 

                        ],
                        "columnDefs": [
                            { width: '10', targets: 0 },
                           
                            {
                                targets: 5,
                            }, 
                            

                        ],

                       
                        'order': [[1, 'asc']],
                        //destroy: true
  
                                             
                       

                })
                 
               

        })
    </script>
    
</body>

</html>