<?php

$id = $_GET['id'];
$sql = $con->prepare("SELECT * FROM `tv` WHERE id= :id");
$sql->bindValue(':id', $id);
$sql->execute();
$consulta = $sql->fetch(PDO::FETCH_ASSOC);

?>
			<div class="content-box">
				<div class="content-config">
					<div class="header-conf">
						<p><?=$consulta['titulo']?></p>
					</div>
					<div class="conteudo-config">
						<div class="input-group">
							<span>Titulo</span>
							<input type="text"   id="titulo" value="<?=$consulta['titulo']?>" required="">
						</div>
						<div class="input-group">
							<span>Descrição</span>
							<textarea id="sinopse"><?=$consulta['descricao']?></textarea>
						</div>
					
						<div class="input-group">
							<span>BG</span>
							<input type="text" value="<?=$consulta['img']?>" id="bg" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>Logo</span>
							<input type="text" value="<?=$consulta['logo']?>" id="footer" placeholder="" required="">
						</div>
						
						<div class="input-group">
							<span>Link  2</span>
							<input type="text" id="link" value="<?=$consulta['link']?>" placeholder="Digite o link">
						</div>
						
						<div class="input-group">
							<button class="cad-success">Alterar</button>
						</div>
					</div>
				</div>
			</div>	
<script type="text/javascript">
	$('.cad-success').click(function(){
		var titulo 	= $('#titulo').val();
		var sinopse 	= $('#sinopse').val();
		var link 		= $('#link').val();
		var bg 			= $('#bg').val();
		var footer 		= $('#footer').val();

		if(titulo != ''){ $('#titulo').css('border','1px solid rgba(0,0,0,.3)');
			if(sinopse != ''){$('#sinopse').css('border','1px solid rgba(0,0,0,.3)');
				if(link != ''){$('#link').css('border','1px solid rgba(0,0,0,.3)');
				$.ajax({
						  type: "POST",
						  url: 'function/api.php?action=tvedit',
						  data: {
						  	'idVid' : '<?=$_GET['id']?>',
						  	'titulo' : titulo,
						  	'sinopse': sinopse,
						  	'link1'    : link,
						  	'footer'   : footer,
						  	'bg' 	   : bg
							},
						  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('Email já existente.');
						  		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('Cadastrado Com Sucesso.');
						  		status_close();
						  	}
						  },
						  
						});
				}else{
					$('#link').css('border','1px solid red');
				}
				
			}else{
				$('#sinopse').css('border','1px solid red');
			}
		}else{
			$('#titulo').css('border','1px solid red');
		}
				
				
	});	

</script>