<?php 
	/*$token = $_GET['token'];
	
	if(!empty($token)){
		
	}else{
		header("Location: https://artefeitoscrap.com.br/admin");
	} */
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Importação</title>
	<link rel="stylesheet" href="./assets/style.css">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
	<div class="content">
		            <form method="post" id="form_abrirModal" enctype="multipart/form-data" onSubmit="ChamadaPadrao(
                    this.id,
                    'btn_modalEdt',
                    'span_modalEdt',
                    'main?view=usuarios'
                    );return false;">
		
			<small>(Adicione um arquivo para importação clicando na caixa.)</small>
			<label id="thumbnail" title="Clique aqui para adicionar um arquivo.">
				<input type="file" name="file_arquivo" id="file_arquivo"  onchange="getFileExtension2(this.value);"  required>
				<input type="hidden" name="token" value="<?= $token; ?>" required>
			</label>
			<button type="submit" name="BTNINPORT" id="BTNINPORT" onclick="clickteste();" ><i class="fa fa-upload"></i> IMPORTAR AGORA</button>
			<button id="BTNINPORT10" disabled style="display: none" ><i class="fa fa-refresh fa-spin fa-3x fa-fw"></i></button>
		</form>
	</div>
	<script>
		function getFileExtension2(filename) {
		  var ab = filename.split('.').pop();
		  
		  if(ab == "xml"){
			  
		  }else{
			  document.getElementById('file_arquivo').value = "";
			  alert("Arquivo Invalido, insira um arquivo no formato XML.");
		  }		  
		}
		function clickteste(){
			
			document.getElementById("BTNINPORT").style.display = "none";
			document.getElementById("BTNINPORT10").style.display = "block";
			
			
		}
		
	</script>
		<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
		<script>
		function ChamadaPadrao(form_id,btn_id,span_id,caminho){
	
    var formulario = document.getElementById(form_id);
    var formData = new FormData(formulario);
    let mensagem = '';
    $.ajax({
        url: "./import.php",
        type: "POST",
        data: formData,
        dataType: 'json',
        processData: false,  
        contentType: false,
        beforeSend: function(){
            $("#"+btn_id).attr("disabled", true);
            $("#"+span_id).html("<img src='utils/img/gifs.gif' width='15' height='15'/>");
        },   
        error: function(jqXHR, textStatus, errorThrown) {
            console.log('jqXHR: \n'+jqXHR);
            console.log('textStatus: \n'+textStatus);
            console.log('errorThrown: \n'+errorThrown);
            $("#"+btn_id).attr("disabled", false);
            $("#"+span_id).empty();
        },
        success: function(retorno){
			//var data = JSON.parse(jsonretorno);
			for(var i = 0; i < retorno.length; i++) {
			   alert(retorno[i][3]);
			}
           
        }
    });
}
		
		
		</script>
</body>
</html>