<?php 

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

    $id_unf = $_SESSION['info_unf']['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 Usuario</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">Dados usuario</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">
                                    
	                                <ul id="details">
	                                	<li>
	                                		<strong>ID: </strong> <span type="number" id="id" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Nome: </strong> <span type="text" id="nome" 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>Profile: </strong> <span type="text" id="profile" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Situacao do login: </strong> <span type="text" id="status" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Limite de conexoes : </strong> <span type="text" id="max_conexao" readonly="readonly"></span>
	                                	</li>
                                        
                                        <li>
                                        	<strong>Login: </strong> <span type="text" id="login" class="copy" readonly="readonly"></span>
                                        </li>
	                                	<li>
	                                		<strong>Senha: </strong> <span type="text" id="senha" class="copy" readonly="readonly"></span>
	                                	</li>
	                                	<li>
	                                		<strong>Lista M3U: </strong> <span type="text" id="iptv_url_lista" class="copy" readonly="readonly"></span>
	                                	</li>
	                                </ul>

	                                <ul id="list" style="display: none;">
	                                	<li class="login"></li>
	                                	<li class="senha"></li>
	                                	<li class="iptv_url_lista"></li>	
	                                </ul> 

	                                
                                    
	                                <!-- <input type="hidden" id="loginCopy">
	                                <input type="hidden" id="senha"> -->

	                                
	                                
	                            </div>
	                            <div class="col-md-6">
                                	<textarea class="textarea form-control" rows="3"></textarea>
                                </div>
                                <div class="col-md-6"></div>
                                <button id="btnCopy" type="button" class="btn btn-success waves-effect waves-light m-r-10">Copiar dados</button>
	                        </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 || id == '') return
            
				$.get("../ajax_search.php?id="+id, function(data) {
					  
                       
				    data = JSON.parse(data)

				    // console.log(data)
		            
		            //console.log(data)
				    $(data).each( function( index, value ) {
					    
					    var status
                        var statusClass 
                        var dataHoje = new Date()  
                        var vencimento = new Date(value.user[0].vencimento)
					    
					    console.log(dataHoje.getTime(), vencimento.getTime())
					    status = (dataHoje.getTime() > vencimento.getTime()) ? 'vencido' : value.user[0].status                       
                       
					    switch(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;           
					        
					    } 
					    
					    // var $copy = $("#copy")                        
                        
         //                $("body").append($copy)
					    
					    $('#id').text(value.user[0].id)
					    $('#nome').text(value.user[0].display_name)
					    $('#email').text(value.user[0].email)
                        $('#celular').text(value.user[0].celular)
					    $('#vencimento').text(new Date(value.user[0].vencimento).toLocaleDateString())
					    $('#profile').text(value.user[0].profile)
                        $('#status').text(status)
					    $('#max_conexao').text(value.user[0].max_con)
					    $('#login, .login').text(value.user[0].login)
					    $('#senha, .senha').text(value.user[0].senha)
					    $('#iptv_url_lista, .iptv_url_lista').text(value.user[0].iptv_url_lista)	              	
                        $('#status').addClass(statusClass) 
			            $('.textarea').val(`Login: ${value.user[0].login} \nSenha: ${value.user[0].senha} \nLista: ${value.user[0].iptv_url_lista}`)
                        
					})

			        var copyTextarea = document.querySelector('textarea')
		            
                    copyTextarea.select()    
					
					 // End GET REQUEST

					$('#btnCopy').click( function () {        
                        
				        var copiar = document.execCommand('copy')

						if(copiar){
				            alert('Copiado');
				        } else {
				            alert('Erro ao copiar, seu navegador pode não ter suporte a essa função.');
				        }
			        })

					
	            })
                    
		})
		
    </script>

    
</body>

</html>