<?php
session_start();
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    
    exit;
    
}
require 'conexao.php';

$player = $_SESSION['user_name'];
$msgsis = $_SESSION['msg'];
?>

<!DOCTYPE html>
<html>
<head>
    <title>Criar jogo</title>
<link rel="stylesheet" type="text/css" href="style.css">

<style>
submit {
width: 50px;
}
</style>

</head>
<body><center>
  <img class="bn" src="bn.png" alt=""><br><br><br>
     <a href="dashboard.php"><button class="btnmenu">Menu principal</button></a><br><br>



<?php
// Consulta SQL para selecionar jogos disponíveis
$sql = "SELECT game, bet, p1, p2, time, limite FROM games WHERE p2 = '' and p1 != '$player'";
$stmt = $pdo->query($sql);
$games = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>


<div class="saldos"><b>
    <br><span style="color: red"><?php echo $msgsis; ?></span>
  </b> </div> 
  
<br><br>
    <h1>Jogos Disponíveis</h1>
    <table border="1">
        <tr>
            <th>Jogo</th>
            <th>Aposta</th>
            <th>Jogador 1</th>
            <th>Tempo</th>
            <th>Limite</th>
            <th>Ação</th>
        </tr>
        <?php foreach ($games as $game) : ?>
            <tr>
                <td><?php echo $game['game']; ?></td>
                <td><?php echo $game['bet']; ?></td>
                <td><?php echo $game['p1']; ?></td>
                <td><?php echo $game['time']; ?></td>
                <td><?php echo $game['limite']; ?></td>
                <td>
                    <form method="POST" action="confirmarentrada.php">
                        <input type="hidden" name="game_id" value="<?php echo $game['game']; ?>">
                        <input class="btnentrargame" type="submit" name="entrar" value="Entrar">
                    </form>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
</body>
</html>