<?php 

    include_once(__DIR__."/../../config.php"); 
    $cs = new cs; 
    if(!$cs->checkLog_unf()) { exit("<script>location='../../login';</script>"); }
    $estatisticas = [];
    if (isset($_GET['id']) && !empty($_GET['id'])) {
	    $id = $cs->filterKey($_GET['id']) ?? ''; 
	    $estatisticas = $cs->fetchQuery($cs->executeQuery("CALL sp_estatisticas($id)"));



    }
    
?>

<!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 - Visualizar 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("../layout/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">Dados do 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-6 col-xs-6">
                                    
	                                <ul>
	                                	<li>
	                                		<strong>ID do gerenciador: </strong> <span type="number" id="id" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Usuario: </strong> <span type="text" id="login" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Senha: </strong> <span type="text" id="senha" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Email: </strong> <span type="text" id="email" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Celular: </strong> <span type="tel" id="celular" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Vencimento: </strong> <span type="text" id="vencimento" readonly="readonly"></span>
	                                    </li>
	                                	<li>
	                                		<strong>Status: </strong> <span type="text" id="status" readonly="readonly"></span>
	                                    </li>
                                        <?php if (count($estatisticas) > 0): ?>                   
                                        
	                                    <li>
	                                		<strong>Total de Usuários Cadastrados: </strong> <span type="text" id="total_users_registed" readonly="readonly"><?= $estatisticas[0]['total_usuarios_cadastrados']; ?></span>
	                                    </li>
	                                    <li>
	                                		<strong>Total de Usuários Ativos: </strong> <span type="text" id="total_users_active" readonly="readonly"><?= $estatisticas[0]['usuarios_ativos_vencimento']; ?></span>
	                                    </li>

	                                    <li>
	                                		<strong>Total de Usuários Expirados: </strong> <span type="text" id="total_users_expired" readonly="readonly"><?= $estatisticas[0]['usuarios_expirados_vencimento']; ?></span>
	                                    </li>

	                                    <li>
	                                		<strong>Total de Usuários Desativados: </strong> <span type="text" id="total_users_desactive" readonly="readonly"><?= $estatisticas[0]['usuarios_desativados']; ?></span>
	                                    </li>
	                                    <li >
	                                    	<strong>Acessado dos seguintes IPS: </strong><span id="ips"></span>
	                                    </li>
	                                    <?php endif; ?>
	                                	
	                                </ul>
	                                
	                            </div>
	                            <div class="col-sm-6 col-xs-6">
                                    <div id="gerenciadoresFilhos"></div>
	                            </div>	
	                        </div>
	                    </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" readonly="readonly"></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>

    <!-- jQuery Mask -->
    <script src="../../plugins/bower_components/jquery-mask/dist/jquery.mask.min.js"></script>
    <!--Style Switcher -->
    <script src="../../plugins/bower_components/styleswitcher/jQuery.style.switcher.js"></script>
    <!--Sweet Alert -->
    <script src="../../plugins/bower_components/sweetalert/sweetalert.min.js"></script>
      
    <!--Functions Js -->
    <script src="../../public/assets/js/functions.js"></script>
    
    <script>
    	jQuery.browser = {};
	        (function () {
	            jQuery.browser.msie = false
	            jQuery.browser.version = 0
	            if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
	                jQuery.browser.msie = true
	                jQuery.browser.version = RegExp.$1
	            }
	        })()
     

		$(document).ready(function () {
            var id
			window.$_GET = new URLSearchParams(location.search);
            id = $_GET.get('id')
			if (id != undefined) {
				$.get("../ajax_search.php?arvore=1&id="+id, function(data) {
					
				    
				    //console.log(data)
				    data = JSON.parse(data)
		            
		            //console.log(data)
				    $(data).each( function( index, value ) {
					    // console.log(index) 
					    if (index == 0) {
						    var status
	                        var statusClass 
	                        //console.log(new Date().toLocaleDateString(), new Date(value.vencimento).toLocaleDateString()) 
						    if(new Date() > new Date(value.vencimento)) {
	                            //console.log(value.status.toString())
	                            if (value.status == 'desativado') {
						    	    value.status = 'desativado'
						        } else {
	                                value.status = 'vencido'
						        }
						    }  

						    switch(value.status)
						    {
						        case "normal":
						            statusClass = "text-success";
						            break;
						        case "desativado":
						            statusClass = "text-warning";
						            break;
						        case "bloqueado":
						            statusClass = "text-info";
						            break; 
						        case "vencido":
						            statusClass = "text-danger";
						            break;           
						        
						    } 
						   // console.log(value.status)	   
						    
						    $('#id').text(value.id)
						    $('#login').text(value.login)
						    $('#senha').text(value.senha)
						    $('#email').text(value.email)
	                        $('#celular').text(value.celular)
						    $('#vencimento').text(new Date(value.vencimento).toLocaleDateString())
						    $('#profile').text(value.profile)
	                        $('#status').text(value.status)
						           	
	                        $('#status').addClass(statusClass) 
                        } 
                        
                        if (index == 1) {
                        	
                        	$('#gerenciadoresFilhos').html(value)
                        } 
                        
                        if (index == 2) {
                        	//console.log(value)
                        	$('#ips').html(value[0].ips)
                        }
		              	//location.reload() 
					})
					 // End GET REQUEST
	            })
            }
           

                    
		})
		
    </script>

    
</body>

</html>