<?php

$id = $_GET['id'];
$sql = $con->prepare("SELECT * FROM `filmes` 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>Data Lançamento</span>
							<input type="text" value="<?=$consulta['year']?>" id="lanc" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>Tempo de Video</span>
							<input type="text" value="<?=$consulta['duration']?>" id="runtime" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>BG</span>
							<input type="text" value="<?=$consulta['bg']?>" id="bg" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>Footer</span>
							<input type="text" value="<?=$consulta['footer']?>" id="footer" placeholder="" required="">
						</div>
						<?php
						if($consulta['tipo'] != 2){
						?>
						<div class="input-group">
							<span>Link 1</span>
							<input type="text" value="<?=$consulta['link1']?>" id="link" placeholder="" required="">
						</div>
						<div class="input-group">
							<span>Link  2</span>
							<input type="text" id="vidLinkLEG" value="<?=$consulta['link2']?>" placeholder="Digite o link Legendado">
						</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 lanc		= $('#lanc').val();
		var runtime		= $('#runtime').val();
		var link 		= $('#link').val();
		var vidLinkLEG  = $('#vidLinkLEG').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(lanc != ''){$('#lanc').css('border','1px solid rgba(0,0,0,.3)');
				if(runtime != ''){$('#runtime').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=vidEdit',
						  data: {
						  	'idVid' : '<?=$_GET['id']?>',
						  	'titulo' : titulo,
						  	'sinopse': sinopse,
						  	'lanc' : lanc,
						  	'runtime' : runtime,
						  	'link1'    : link,
						  	'link2'    : vidLinkLEG,
						  	'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{
					$('#runtime').css('border','1px solid red');
				}
				}else{
					$('#lanc').css('border','1px solid red');
				}
			}else{
				$('#sinopse').css('border','1px solid red');
			}
		}else{
			$('#titulo').css('border','1px solid red');
		}
				
				
	});	

</script>