<?php
session_start();
if($_SESSION['logInSucces'] == NULL){
	?><script type="text/javascript">window.location.href="index"</script><?
}
?>
	<?php
	require('../../conexao/conexao.php');
	$busca = "SELECT * FROM `tv` ORDER BY id DESC";
	
	$todos = mysql_query("$busca");
 
$tr = mysql_num_rows($todos); // verifica o número total de registros
	?>
			<div class="content-box">
				<div class="action"><button class="add-user">Adicionar Video</button></div>
				
<?php
while ($vid = mysql_fetch_array($todos)) {
?>
				<div class="video-card">
					<div class="shadow">
						<p class="title"><?=$vid['titulo']?></p>
						<button class="edit-video-btn edit-vid" idVid="<?=$vid['id']?>"><i class="fas fa-pencil-alt"></i></button>
						<button class="edit-video-btn exl-vid" idVid="<?=$vid['id']?>"><i class="fas fa-trash-alt"></i></button>
					</div>
					<div class="poster">
						<img src="<?=$vid['logo']?>">
					</div>
				</div>
<? } ?>

			</div>	
			<script type="text/javascript">
				$('.add-user').click(function(){
				 	
						$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/vid-add.php',function(){
							$('.loading').css('display','none');
						});
				});
				$('.exl-vid').click(function(){
					var idVid = $(this).attr('idVid');
					$.ajax({
						  type: "POST",
						  url: 'function/api.php?action=exlTV',
						  data: {
						  	'idVid' : idVid,
						  	
							},
						  success: function(data,status){
						  	
						  	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('Erro ao Exluir.');
						  		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('Exluido Com Sucesso.');
						  		status_close();
						  		loading();
						  	}
						  },
						  
						});
					$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/vidtv.php',function(){
							setTimeout(function(){
							$('.header-content h2').html('Videos');
							$('.loading').css('display','none');
							$('.loading').css('opacity','0');
						},500);
						});
				});
				$('.edit-vid').click(function(){
					var edit = $(this).attr('idVid');
					$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/vidtv-edit.php?id='+edit,function(){
							setTimeout(function(){
							$('.header-content h2').html('Videos');
							$('.loading').css('display','none');
							$('.loading').css('opacity','0');
						},500);
						});
				});
			</script>