<?php
session_start();
if($_SESSION['logInSucces'] == NULL){
	?><script type="text/javascript">window.location.href="index"</script><?
}
?>
<?php
require('../../conexao/conexao.php');
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = mysql_query("SELECT * FROM `tv` WHERE id='$id'");
$consulta = mysql_fetch_array($sql);

?>
			<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>Logo</span>
							<input type="text" value="<?=$consulta['logo']?>" id="logo" placeholder="" required="">
						</div>

						<div class="input-group">
							<span>Categoria</span>
							<select name="categorie" id="categorie">
								<?php
									$check = mysql_query("SELECT * FROM `tvcategory` ORDER BY category ASC");
									while($category = mysql_fetch_array($check)){
										?>
										<option value="<?=$category['id']?>" <?php if($consulta['categoria'] == $category['id']){ ?> selected <?}?>><?=$category['category']?></option>
										<?
									}

								?>
							</select>		
						</div>

						<div class="input-group">
							<span>Link</span>
							<input type="text" value="<?=$consulta['url']?>" id="link" 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 logo 		= $('#logo').val();
		var link 		= $('#link').val();
		var categorie	= $('#categorie').val();

		if(titulo != ''){ $('#titulo').css('border','1px solid rgba(0,0,0,.3)');
				$.ajax({
						  type: "POST",
						  url: 'function/api.php?action=tvEdit',
						  data: {
						  	'idVid' : '<?=$_GET['id']?>',
						  	'titulo' : titulo,
						  	'logo': logo,
						  	'link'    : link,
						  	'categorie': categorie,
							},
						  success: function(data,status){
						  	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{
			$('#titulo').css('border','1px solid red');
		}
				
				
	});	

</script>