<?php

$id = $_GET['id'];
$sql = $con->prepare("SELECT * FROM `episode` 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>Sinopse</span>
							<textarea id="sinopse"><?=$consulta['sinopse']?></textarea>
						</div>
						<div class="input-group">
							<span>BG</span>
							<input type="text" value="<?=$consulta['bg']?>" id="img" placeholder="" required="">
						</div>
						
						<div class="input-group">
							<span>Link</span>
							<input type="text" value="<?=$consulta['link1']?>" id="link" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>Link 2</span>
							<input type="text" value="<?=$consulta['link2']?>" id="link2" placeholder="" required="">
						</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 bg 	   = $('#img').val();
		var link   = $('#link').val();
		var link2   = $('#link2').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(bg != ''){$('#img').css('border','1px solid rgba(0,0,0,.3)');
					if(link != ''){$('#link').css('border','1px solid rgba(0,0,0,.3)');

								    $('.loading').css('display','block');
									$('.loading').css('opacity','1');
									//POST
									$.ajax({
									  type: "POST",
									  url: 'function/api.php?action=editEp',
									  data: {
									  	'titulo'  : titulo,
									  	'sinopse' : sinopse,
									  	'bg'	  : bg,
									  	'link1'	  :link,
									  	'link2'	  :link2,
									  	'idvid'   : "<?=$id?>",
										},
									  success: function(data,status){
									  	$('.loading').css('display','none');
										$('.loading').css('opacity','0');
										  	if(data == 'E1'){
										  		$('.loading').css('display','none');
												$('.loading').css('opacity','0');
										  		$('.status').css('display','block');
									  			$('.status').css('color','white');
									  			$('.status').css('background','rgba(215,50,50,1)');
										  		$('.status p').html('Não Editado.');
										  		status_close();
										  	}else if(data == 'S1'){
										  		$('.loading').css('display','none');
												$('.loading').css('opacity','0');
										  		$('.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{
						$('#link').css('border','1px solid red');
					}
				}else{
					$('#img').css('border','1px solid red');
				}
			}else{
				$('#sinopse').css('border','1px solid red');
			}
			
		}else{
			$('#titulo').css('border','1px solid red');
		}
				
				
	});	

</script>