<?php
    $servidor = "localhost";
    $usuario = "kaltekgo_painel";
    $senha = "painel@2024";
    $dbname = "kaltekgo_painel";    
    //Criar a conexao
    $conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
    
    if(!$conn){
        die("Falha na conexao: " . mysqli_connect_error());
    }else{
        echo "";
    }      
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="10">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
    <title>Painel de Senha</title>
    <style>
body {
    font-family: "Barlow", sans-serif;
    font-weight: 700;
    font-style: normal; 
    background-color: #396f33;
    color: #fff;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    text-align: center;
}

.painel {
    width: 100%;
    max-width: 1200px;
    background-color: #0a1e55;
    padding: 20px;
    border-radius: 10px;
    box-sizing: border-box;
    margin: 10px;
}

.header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-top: -10px;
}

.header h1 {
    font-size: 24px;
    margin: 0;
    flex: 1;
}

.img img {
    max-width: 100px;
    height: auto;
}

.senha-atual {
    font-size: 3.5em;
    margin: 15px 0;
    color: #ffff00;
    text-transform: uppercase;
}

.guiche-atual {
    font-size: 2.5em;
    margin: 20px 0;
    color: #ffffff;
    text-transform: uppercase;
}

table {
    width: 100%;
    margin-top: 20px;
    border-collapse: collapse;
}

table th, table td {
    padding: 8px;
    font-size: 2em;
    text-transform: uppercase;
    word-break: break-word;
}

table th {
    background-color: #001c4a;
    color: #ffffff;
}

table td {
    background-color: #0a1e55;
    color: #ffffff;
    
}

.relogio {
    font-size: 1.2em;
    margin-top: 20px;
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: center;
        margin-bottom: 10px;
    }

    .header h1 {
        font-size: 1.5em;
        margin-bottom: 10px;
    }

    .senha-atual {
        font-size: 1.6em;
    }

    .guiche-atual {
        font-size: 1.2em;
    }

    table th, table td {
        font-size: 0.9em;
        padding: 6px;
    }

    .img img {
        max-width: 80px;
    }
     .menor {
        width: 220px;
        padding: 10px 2px 10px 2px;
    }
    tr{
        border: 3px solid #ffffff ;
    }
}

@media (max-width: 480px) {
    .painel {
        padding: 15px;
    }

    .senha-atual {
        font-size: 1.8em;
    }

    .guiche-atual {
        font-size: 1.2em;
    }

    .relogio {
        font-size: 1.2em;
    }
    
    table th, table td {
        font-size: 1.1em;
        padding: 3px;
    }
}

    </style>
</head>
<body>
    <div class="painel">
        <div class="header">
            <h1>Painel Atendimento</h1>
            <span class="img"><img src="https://colegioavila.com.br/wp-content/uploads/2019/02/logo-chanfrado01.png" width="100px"></span>
        </div>
<?php
	$painel_senha_atual = "SELECT * FROM senhasPainelFundamental WHERE status = 'ativo' ORDER BY id DESC";
	$resultado_painel_senha_atual = mysqli_query($conn, $painel_senha_atual);
    $row_painel_senha_atual = mysqli_fetch_assoc($resultado_painel_senha_atual);
?>

        <div class="senha-atual">
           <strong> Senha Atual: <?php echo $row_painel_senha_atual['senha']; ?></strong>
        </div>
        <div class="guiche-atual">
            <strong><?php echo $row_painel_senha_atual['nomeProfessor'];?></strong> - 
            <strong><?php echo $row_painel_senha_atual['disciplinaProfessor'];?></strong> - 
            <strong>Sala <?php echo $row_painel_senha_atual['salaProfessor']; ?></strong>
        </div>


<table>
<tr>
<th>Senha</th>
<th>Professor</th>
<th>Sala</th>
</tr>
<?php
$painel_senha_atual_lista = "SELECT professor.*, s.* FROM professor INNER JOIN (SELECT idProfessor, MAX(id) AS id FROM senhasPainelFundamental GROUP BY idProfessor ORDER BY id DESC) AS s_max ON professor.idProfessor = s_max.idProfessor INNER JOIN senhasPainelFundamental s ON s.id = s_max.id WHERE s.status = 'ativo' LIMIT 10";
$resultado_painel_senha_atual_lista = mysqli_query($conn, $painel_senha_atual_lista);
while($row_painel_senha_atual_lista = mysqli_fetch_assoc($resultado_painel_senha_atual_lista)){
echo'<tr>
<td>'.$row_painel_senha_atual_lista['senha'].'</td>
<td class="menor">'.$row_painel_senha_atual_lista['nomeProfessor'].' / '.$row_painel_senha_atual_lista['disciplinaSeries'].'</td>
<td>'.$row_painel_senha_atual_lista['salaProfessor'].'</td>
</tr>';
}
?>
</table>
<br>
<?php
date_default_timezone_set('America/Sao_Paulo');
$date = date('d-m-Y H:i');
echo '<p class="relogio">'.$date.'</p>';
?>
</div>
</body>
</html>
