<?php
session_start();
if($_SESSION['logInSucces'] == NULL){
	?><script type="text/javascript">window.location.href="index"</script><?
}

?>
<?php
require('../../conexao/conexao.php');
require("../../config.php");
$us = mysql_query("SELECT * FROM `login_flix` WHERE validade='0' order by id desc") or die(mysql_error());
?>
			<div class="confirm-question" style="display: none;" idMB="">
				<div class="container-question">
					Deseja realmente excluir o cashOut #<span class="F"></span>
					<button class="Confirm">Sim</button><button class="Nega">Não</button>
				</div>
			</div>
					
			<div class="content-box">
				<button class="add-user">Adicionar Usuario</button>
				<table class="table-user" cellpadding="0" cellspacing="0">
					<thead>
						<tr class="tr-table table-header">
							<td>#</td>
							<td>E-mail</td>
							<td>Valor</td>
							<td>Ações</td>
						</tr>
					</thead>
					<tbody>
						<?php
						$us = mysql_query("SELECT * FROM `cashout` ORDER BY id='ASC'");
						while($user = mysql_fetch_array($us)){
							$idUs = $user['id_member'];
							$mysq = mysql_query("SELECT * FROM `login_flix` where id='$idUs'");
							$mb = mysql_fetch_assoc($mysq);
							

							$ref = mysql_query("SELECT * FROM `login_flix` WHERE ref1='$idUs' && validade='1' or ref2='$idUs' && validade='1' or ref3='$idUs' && validade='1' or ref4='$idUs' && validade='1' or ref5='$idUs' && validade='1' ");
							$ActAccRef = mysql_num_rows($ref);

							$valTotal  = NULL;
							while($val = mysql_fetch_array($ref)){
							  $valTotal = $valTotal+$val['planVal'];

							}
							
							$valTotal = $valTotal*$pct/100;
						?>
						<tr class="tr-table">
							<td><?=$user['id']?></td>
							<td><?=$mb['user']?></td>
							<td><?=number_format($valTotal, 2, ',', '.');?></td>
							<td><button class="exl-user-btn" idmb="<?=$user['id']?>" >Apagar</button></td>
						</tr>
						<? } ?>

					</tbody>
				</table>
				
			</div>	
			
			<script type="text/javascript">
				$('.add-user').click(function(){
				 	
						$('.loading').css('display','block');
						$('.loading').css('opacity','1');
						$('.conteudo').load('pages/user-add.php',function(){
							setTimeout(function(){
								$('.header-content h2').html('Usuario');
								$('.loading').css('display','none');
								$('.loading').css('opacity','0');
							},500);
						});

					
				});
				$('.exl-user-btn').click(function(){
					var idUser = $(this).attr('idmb');
					$('.idUser').html(idUser);
					$('.confirm-question').attr('idMB',idUser);
					$('.confirm-question').css('display','block');
				});
				$('.Confirm').click(function(){
					var idmb = $('.confirm-question').attr('idMB');
					
					$.ajax({
					  type: "POST",
					  url: 'function/api.php?action=cashExl',
					  data: {
					  	'idMB' : idmb
						},
					  success: function(data){
					  	if(data == 'E1'){
					  		$('.status').css('display','block');
					  		$('.status').css('color','white');
					  		$('.status').css('background','rgba(215,50,50,1)');
					  		$('.status p').html('Pedido Não Encotrado.');
					  		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('Excluido com sucesso.');
					  		status_close();
					  	}
					  },
					  
					});
					$('.confirm-question').css('display','none');
				});
				$('.Nega').click(function(){
					$('.confirm-question').css('display','none');
				});
				
			</script>