<?php

$idM = $_GET['id'];
$us = $con->prepare("SELECT * FROM `login_admin` WHERE id= :id");
$us->bindValue(':id', $idM);
$us->execute();
$user = $us->fetch(PDO::FETCH_ASSOC);
?>
			<div class="content-box">
				<div class="content-config">
					<div class="header-conf">
						<p>Novo Usuario</p>
					</div>
					<div class="conteudo-config">
						<div class="input-group">
							<span>Nome</span>
							<input type="text"  value="<?=$user['user']?>" id="nome" placeholder="Digite um nome para este usuario" required="">
						</div>
						<div class="input-group">
							<span>E-mail</span>
							<input type="email"  value="<?=$user['email']?>" id="email" placeholder="Digite um e-mail para este usuario" required="">
						</div>
						<div class="input-group">
							<span>Nova Senha (opcional)</span>
							<input type="password" value="" id="pass" placeholder="Digite uma senha para este usuario" >
						</div>
						
						<input type="hidden" id="idmb" value="<?=$nome['idMC']?>">
						<div class="input-group">
							<button class="cad-success">Cadastrar</button>
						</div>
					</div>
				</div>
			</div>	
<script type="text/javascript">
	$('.cad-success').click(function(){
		var nome = $('#nome').val();
		var email= $('#email').val();
		var pass = $('#pass').val();
		var tipo = $('#tipo').val();
		var nomel = $('#nome').val().length;
		var emaill= $('#email').val().length;
		var passl = $('#pass').val().length;
		var idm = "<?=$idM?>";
		var idmb = $('#idmb').val();

		if(nomel != 0){ $('#nome').css('border','1px solid rgba(0,0,0,.3)');
			if(emaill != 0){$('#email').css('border','1px solid rgba(0,0,0,.3)');
				$.ajax({
						  type: "POST",
						  url: 'function/api.php?action=editUser',
						  data: {
						  	'nome' : nome,
						  	'email': email,
						  	'pass' : pass
							},
						  success: function(data,status){
						  	console.log(data);
						  	if(data == 'E1'){
						  		$('.status').css('display','block');
					  			$('.status').css('color','white');
					  			$('.status').css('background','rgba(215,50,50,1)');
						  		$('.status p').html('Erro ao Editar.');
						  		status_close();
						  	}else if(data == 'S1'){
						  		$('.status').css('display','block');
						  		$('.status').css('color','white');
					  			$('.status').css('background','rgba(50,215,50,1)');
						  		$('.status p').html('Editado Com Sucesso.');
						  		status_close();
						  	}
						  },
						  
						});
				
			}else{
				$('#email').css('border','1px solid red');
			}
		}else{
			$('#nome').css('border','1px solid red');
		}
				
				
	});	

</script>