<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_erros', 1);
// error_reporting(E_ALL);
    include_once(__DIR__."/../config.php"); 

    $cs = new cs;

    if(!$cs->checkLog_unf()) { exit("<script>location='../login';</script>"); }
    
    if(!isset($_SESSION['token_validar'])) {
        $_SESSION['token_validar']=md5(rand());
    }
    $info_unf = $_SESSION['info_unf'];
    $id_unf   = $_SESSION['info_unf']['id'];
   
    $estatisticas = $cs->executeQuery("CALL sp_estatisticas('{$id_unf}')");
    
    if($cs->num_rows($estatisticas) > 0) {

        $estatisticas = $cs->fetchQuery($estatisticas);   
        $cs->con->next_result();
    }

    $gerenciadoresVencimento = $cs->getGerenciadoresVencimento($id_unf);

?>

<!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">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="<?= SITE_PAINEL; ?>/betanew/plugins/images/favicon.png">
    <title>Space Code 2.0 - Dashboard</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">Painel </h4> </div>
                <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                    <?php echo breadcrumbs(); ?>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                
                <div class="col-lg-12 col-md-6">
                    <div class="white-box">
                        <h3 class="box-title">Seu vencimento</h3>
                        <div class="row">
                            <div class="col-md-6 col-sm-6 col-xs-6  m-t-30">
                                <h1 class="text-warning"><?= date('d',strtotime($_SESSION['info_unf']['vencimento']));?></h1>
                                <p class="text-muted">de <?= date('M',strtotime($_SESSION['info_unf']['vencimento'])); ?> <?= date('Y',strtotime($_SESSION['info_unf']['vencimento'])); ?></p>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div id="sales1" class="text-center"><canvas width="100" height="100" style="display: inline-block; width: 100px; height: 100px; vertical-align: top;"></canvas></div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php if ($gerenciadoresVencimento): ?>
                <div class="col-lg-12 col-md-6">
                    <div class="white-box">
                        <h3 class="box-title">Gerenciadores a vencer</h3>
                        <div class="row">
                            <div class="col-md-6 col-sm-6 col-xs-6  m-t-30">
                                <?php  foreach ($gerenciadoresVencimento as $key => $value): ?>
                               
                                <p class=""><a class="text-warning" href="<?= SITE_PAINEL; ?>/beta/gerenciador/visualizar/index.php?id=<?=$value['id']?>"><?= $value['id']; ?> - <?= $value['login']; ?> - <?= $value['email']; ?></a></p>
                                <?php endforeach; ?>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-6">
                                <div id="sales1" class="text-center"><canvas width="100" height="100" style="display: inline-block; width: 100px; height: 100px; vertical-align: top;"></canvas></div>
                            </div>
                        </div>
                    </div>                    
                </div>
                <?php endif ?>
            </div>
            <?php if (count($estatisticas) > 0):  ?>
            <?php foreach ($estatisticas as $estatistica): ?>   
            <h3 class="box-title">Total de usuarios </h3>
            <div class="row">
                <div class="col-md-12 col-lg-12 col-sm-12">
                    <div class="white-box">
                        <div class="row row-in">
                            <div class="col-lg-3 col-sm-6 row-in-br">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-people"></i>
                                        <h5 class="text-muted vb">Cadastrados</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-success"><?= $estatistica['total_usuarios_cadastrados'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?= $estatistica['total_usuarios_cadastrados'];?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_usuarios']; ?>" style="width: <?= getProgressBar($estatistica['total_usuarios_cadastrados'], $estatistica['limite_usuarios']) ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['total_usuarios_cadastrados'], $estatistica['limite_usuarios']) ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-sm-6 row-in-br  b-r-none">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-eye" ></i>
                                        <h5 class="text-muted vb">Ativos</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-info"><?= $estatistica['usuarios_ativos_vencimento'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="<?= $estatistica['usuarios_ativos_vencimento'];?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_usuarios']; ?>" style="width: <?= getProgressBar($estatistica['usuarios_ativos_vencimento'], $estatistica['limite_usuarios']) ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['usuarios_ativos_vencimento'], $estatistica['limite_usuarios']) ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-sm-6 row-in-br">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-user-unfollow"></i>
                                        <h5 class="text-muted vb">Desativados</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-warning"><?= $estatistica['usuarios_desativados']; ?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="<?= $estatistica['usuarios_desativados']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_usuarios']; ?>" style="width: <?= getProgressBar($estatistica['usuarios_desativados'], $estatistica['limite_usuarios']) ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['usuarios_desativados'], $estatistica['limite_usuarios']) ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-sm-6  b-0">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-ban"></i>
                                        <h5 class="text-muted vb">Vencidos</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-danger"><?= $estatistica['usuarios_expirados_vencimento']; ?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="<?= $estatistica['usuarios_expirados_vencimento'];?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_usuarios']; ?>" style="width: <?= getProgressBar($estatistica['usuarios_expirados_vencimento'], $estatistica['limite_usuarios']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['usuarios_expirados_vencimento'], $estatistica['limite_usuarios']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--row -->
            <!-- /.row -->

            <h3 class="box-title">Total de gerenciadores</h3>
            <div class="row">
                <div class="col-md-12 col-lg-12 col-sm-12">
                    <div class="white-box">
                        <div class="row row-in">
                            <div class="col-lg-3 col-sm-6 row-in-br">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-people"></i>
                                        <h5 class="text-muted vb">Cadastrados</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-success"><?= $estatistica['total_gerenciadores'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?= $estatistica['total_gerenciadores']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['total_gerenciadores'], $estatistica['limite_gerenciadores']); ?>%"> 
                                                <span class="sr-only"><?= getProgressBar($estatistica['total_gerenciadores'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> 
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-sm-6 row-in-br  b-r-none">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-eye" ></i>
                                        <h5 class="text-muted vb">Ativos</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-info"><?= $estatistica['total_gerenciadores_ativos'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="<?= $estatistica['total_gerenciadores_ativos']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['total_gerenciadores_ativos'], $estatistica['limite_gerenciadores']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['total_gerenciadores_ativos'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="col-lg-3 col-sm-6  b-0">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-ban"></i>
                                        <h5 class="text-muted vb">Vencidos</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-danger"><?= $estatistica['total_gerenciadores_vencidos'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="$estatistica['total_gerenciadores_vencidos']" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['total_gerenciadores_vencidos'], $estatistica['limite_gerenciadores']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['total_gerenciadores_vencidos'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                        </div>
                    </div>
                </div>
            </div>
            <!--row -->
            <!-- /.row -->
            <div style="display: inline-block;">
                
                
                
            </div>
            <div class="row">
                <div class="col-md-12 col-lg-12 col-sm-12">
                    <h3 class="">Expiram Hoje - <?= date('d/m/Y'); ?></h3>
                    <div class="white-box">
                        <div class="row row-in">
                            
                            <div class="col-lg-6 col-sm-12 row-in-br">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-people"></i>
                                        <h5 class="text-muted vb">Usuarios</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-success"><?= $estatistica['usuarios_a_expirar'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?= $estatistica['usuarios_a_expirar']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['usuarios_a_expirar'], $estatistica['limite_gerenciadores']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['usuarios_a_expirar'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-sm-12  b-r-none">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-eye" ></i>
                                        <h5 class="text-muted vb">Gerenciadores</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-info"><?= $estatistica['gerenciadores_a_vencer'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="<?= $estatistica['gerenciadores_a_vencer']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['gerenciadores_a_vencer'], $estatistica['limite_gerenciadores']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['gerenciadores_a_vencer'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

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

                <div class="col-md-12 col-lg-12 col-sm-12">
                    <h3 class="">Limite para cadastro</h3> 
                    <div class="white-box">
                        <div class="row row-in">
                            <div class="col-lg-6 col-sm-12 row-in-br">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-people"></i>
                                        <h5 class="text-muted vb">Usuarios</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-success"><?= $_SESSION['info_unf']['limite_usuarios'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">

                                        <div class="progress">
                                            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?= $estatistica['total_usuarios_cadastrados'] ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['total_usuarios_cadastrados']  ?>" style="width: <?= getProgressBar($estatistica['total_usuarios_cadastrados'], $estatistica['limite_usuarios']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['total_usuarios_cadastrados'], $estatistica['limite_usuarios']); ?>% Complete (success)</span> </div>
                                        </div>
                                    
                                    </div>
                                </div>
                            </div>
                            

                            <div class="col-lg-6 col-sm-12 b-r-none">
                                <div class="col-in row">
                                    <div class="col-md-6 col-sm-6 col-xs-6"> <i class="icon-eye" ></i>
                                        <h5 class="text-muted vb">Gerenciadores</h5> </div>
                                    <div class="col-md-6 col-sm-6 col-xs-6">
                                        <h3 class="counter text-right m-t-15 text-info"><?= $_SESSION['info_unf']['limite_gerenciadores'];?></h3> </div>
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="progress">
                                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="<?= $estatistica['total_gerenciadores']; ?>" aria-valuemin="0" aria-valuemax="<?= $estatistica['limite_gerenciadores']; ?>" style="width: <?= getProgressBar($estatistica['total_gerenciadores'], $estatistica['limite_gerenciadores']); ?>%"> <span class="sr-only"><?= getProgressBar($estatistica['total_gerenciadores'], $estatistica['limite_gerenciadores']); ?>% Complete (success)</span> </div>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                <?php endforeach ?>
                <?php endif ?>
                </div>
            </div>
            <!--row -->
            <!-- /.row -->

           
                
                
        <?php include_once(__DIR__.'/../layout/right-sidebar.php');?>
        </div>
        <!-- /.container-fluid -->
        <?php include_once(__DIR__.'/../layout/footer.php');?>
    </div>
    <!-- /#page-wrapper -->
    
    <!-- /#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>
    <!--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>
    <!-- SELECT 2 -->   
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>0
    <!-- Custom Theme JavaScript -->
    <script src="../public/assets/js/search.js"></script>
    <script>
        $(document).ready(function() {
            $('.multiSelect').select2();
            //Open-Close-right sidebar
             
        });


         //Loads the correct sidebar on window load,
        //collapses the sidebar on window resize.
        // Sets the min-height of #page-wrapper to window size
        $(function () {
            $(window).bind("load resize", function () {
                topOffset = 60;
                width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
                if (width < 768) {
                    $('div.navbar-collapse').addClass('collapse');
                    topOffset = 100; // 2-row-menu
                }
                else {
                    $('div.navbar-collapse').removeClass('collapse');
                }
                height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
                height = height - topOffset;
                if (height < 1) height = 1;
                if (height > topOffset) {
                    $("#page-wrapper").css("min-height", (height) + "px");
                }
            });
            var url = window.location;
            var element = $('ul.nav a').filter(function () {
                return this.href == url || url.href.indexOf(this.href) == 0;
            }).addClass('active').parent().parent().addClass('in').parent();
            if (element.is('li')) {
                element.addClass('active');
            }
        });
    </script>

    
</body>

</html>
        
  