<?php
session_start();
if($_SESSION['logInSucces'] == NULL){
	?><script type="text/javascript">window.location.href="index"</script><?
}
?>
<?php
require("../../conexao/conexao.php");
$sql = "SELECT * FROM `config_flix`";

$name = mysql_query($sql." WHERE action='name'");
$title_site = mysql_query($sql." WHERE action='title_site'");
$descricao_site =mysql_query( $sql." WHERE action='descricao_site'");
$palavra_chave = mysql_query($sql." WHERE action='palavra_chave'");
$facebook_token =mysql_query( $sql." WHERE action='facebook_token'");


$config = mysql_fetch_array($name);
$config1 = mysql_fetch_array($title_site);
$config2 = mysql_fetch_array($descricao_site);
$config3 = mysql_fetch_array($palavra_chave);
$config4 = mysql_fetch_array($facebook_token);

$sl = mysql_query("SELECT * FROM `head_flix` ORDER BY id DESC");
$slide = mysql_fetch_array($sl);
?>
			<div class="content-box">
				<div class="content-config">
					<div class="header-conf">
						<p>Geral</p>
					</div>
					<div class="conteudo-config">
						<div class="input-group">
							<span>Nome do site</span>
							<input type="text" value="<?=$config['value']?>" class="sitname">
						</div>
						<div class="input-group">
							<span>Titulo do site</span>
							<input type="text" value="<?=$config1['value']?>" class="sittitle">
						</div>
						<div class="input-group">
							<span>Descrição do site</span>
							<input type="text" value="<?=$config2['value']?>" class="sitdesc">
						</div>
						<div class="input-group">
							<span>Palavras-chave do site</span>
							<input type="text" value="<?=$config3['value']?>" class="sitkey">
						</div>
						<div class="input-group">
							<span>Token facebook</span>
							<input type="text"  value="<?=$config4['value']?>" class="sitface">
						</div>
						<div class="input-group">
							<button class="cad-success" key="geral">Alterar</button>
						</div>
					</div>
				</div>
			</div>	
			<div class="content-box">
				<div class="content-config">
					<div class="header-conf">
						<p>Slide</p>
					</div>
					<div class="conteudo-config">
						<div class="input-group">
							<span>ID</span>
							<input type="text" value="<?=$slide['id_f']?>" class="tmdb">
						</div>
						<div class="input-group">
							<span>Logo IMG</span>
							<input type="text" value="<?=$slide['img']?>" class="logoImg">
						</div>
						<div class="input-group">
							<span>BG</span>
							<input type="text" value="<?=$slide['bg']?>" class="bg">
						</div>
						<div class="input-group">
							<span>Sinopse</span>
							<textarea class="sinopse"><?=$slide['sinopse']?></textarea>
						</div>
						<div class="input-group">
							<button class="cad-success" key="slide">Alterar</button>
						</div>
					</div>
				</div>
			</div>	

<script type="text/javascript">
	$('.cad-success').click(function(){
		var tipo = $(this).attr('key');
		if(tipo == "geral"){
		var sitname = $('.sitname').val();
		var sittitle = $('.sittitle').val();
		var sitdesc = $('.sitdesc').val();
		var sitkey = $('.sitkey').val();
		var sitface = $('.sitface').val();
		if(sitname != ''){$('.sitname').css('border','1px solid rgba(0,0,0,.3)');
			if(sittitle != ''){$('.sittitle').css('border','1px solid rgba(0,0,0,.3)');
				if(sitdesc != ''){$('.sitdesc').css('border','1px solid rgba(0,0,0,.3)');
					if(sitkey != ''){$('.sitkey').css('border','1px solid rgba(0,0,0,.3)');
						if(sitface != ''){$('.sitface').css('border','1px solid rgba(0,0,0,.3)');
							//POST
							$.ajax({
									  type: "POST",
									  url: 'function/api.php?action=configAlt',
									  data: {
									  	'sitname' : sitname,
									  	'sittitle': sittitle,
									  	'sitdesc' : sitdesc,
									  	'sitkey'  : sitkey,
									  	'sitface' : sitface,
										},
									  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 Alterado.');
										  		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('Alterado Com Sucesso.');
										  		
										  		status_close();
										  	}
									  },
									  
									});
							//POST
						}else{
							$('.sitface').css('border','1px solid red');
						}
					}else{
						$('.sitkey').css('border','1px solid red');
					}
				}else{
					$('.sitdesc').css('border','1px solid red');
				}
			}else{
				$('.sittitle').css('border','1px solid red');
			}
		}else{
			$('.sitname').css('border','1px solid red');
		}
		}
		else if(tipo == "slide"){
			var tmdb 	= $('.tmdb').val();
			var logoImg = $('.logoImg').val();
			var bg 		= $('.bg').val();
			var sinopse = $('.sinopse').val();

			if(tmdb != ''){$('.tmdb').css('border','1px solid rgba(0,0,0,.3)');
				if(logoImg != ''){$('.logoImg').css('border','1px solid rgba(0,0,0,.3)');
					if(bg != ''){$('.bg').css('border','1px solid rgba(0,0,0,.3)');
						if(sinopse != ''){$('.sinopse').css('border','1px solid rgba(0,0,0,.3)');
							//POST
							$.ajax({
									  type: "POST",
									  url: 'function/api.php?action=slideAlt',
									  data: {
									  	'tmdb' 	  : tmdb,
									  	'logo' 	  : logoImg,
									  	'bg'   	  : bg,
									  	'sinopse' : sinopse, 
									 
										},
									  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 Alterado.');
										  		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('Alterado Com Sucesso.');
										  		
										  		status_close();
										  	}
									  },
									  
									});
							//POST
						}else{
							$('.sinopse').css('border','1px solid red');
						}
					}else{
						$('.bg').css('border','1px solid red');
					}
				}else{
					$('.logoImg').css('border','1px solid red');
				}
			}else{
				$('.tmdb').css('border','1px solid red');
			}
		}
	});


</script>