<?php
$idTurma = $_GET['id_turma'];
$idDisciplina = $_GET['id_disciplina'];
$notaRecebida = $_GET['identificadorTarefa']; // Ex: NT1, NT2, ..., NT30
$tituloTarefa = $_GET['titulo'];
$disciplina = $_GET['disciplina'];
$turma = $_GET['turma'];
$professor = $_GET['professor'];
$tipo = $_GET['tipo'];
$data = $_GET['data'];
$trimestre = $_GET['trimestre'];
$nometrimestre = $_GET['nometrimestre'];

// Valida se a entrada está no formato NT1 até NT30
if (!preg_match('/^NT([1-9]|[1-2][0-9]|30)$/', $notaRecebida)) {
    die("Identificador de tarefa inválido.");
}

// Converte NTx para Tx (removendo o N)
$colunaNota = 't' . substr($notaRecebida, 2);

// Conexão com banco
$pdo = new PDO('mysql:host=localhost;dbname=kaltekgo_avila', 'kaltekgo_admin', 'kaltek@2024');

// Monta a consulta SQL
$sql = "SELECT *
        FROM nota_tarefas_entregues
        WHERE $colunaNota IN ('F', 'N') AND id_turma = :idTurma AND id_disciplina = :idDisciplina AND idTrimestre = :trimestre";

$stmt = $pdo->prepare($sql);
$stmt->execute([
    ':idTurma' => $idTurma,
    ':idDisciplina' => $idDisciplina,
    ':trimestre' => $trimestre
]);

$alunos = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Colégio Ávila</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #ffffff;
      margin: 20px;
      color: #000000;
    }

    .topo-logo {
      display: flex;
      align-items: flex-start;
      gap: 20px;
      margin-bottom: 20px;
    }

    .topo-logo img {
      max-width: 200px;
      height: auto;
      position: absolute;
      margin-left: 1100px;
    }

    .info-topo {
      flex: 1;
    }

    .container-fluid {
      width: 80%;
    }

    h4, h5 {
      margin: 0 0 10px;
    }

    .btn-cadastrar, .filtro-btns {
      margin-left: 15px;
      margin-bottom: 10px;
    }

    .table-responsive-custom {
      overflow-x: auto;
      margin: 0 15px 20px 15px;
      display: block;
    }

    table {
      white-space: nowrap;
      width: 100%;
      border-collapse: collapse;
      background-color: #ffffff;
      box-shadow: 0 0 10px rgba(0,0,0,0.1);
      text-transform: uppercase;
      min-width: 700px;
    }

    th, td {
      padding: 12px 15px;
      text-align: left;
      font-size: 12px;
      border: 1px solid #000;
      vertical-align: middle !important;
    }

    th {
      background-color: #000;
      color: #fff;
    }

    tr:nth-child(even) {
      background-color: #f4f4f4;
    }

    tr:hover {
      background-color: #e0e0e0;
    }

    @media (max-width: 768px) {
      .btn-cadastrar, .filtro-btns .btn {
        width: 100% !important;
        margin: 10px auto;
        font-size: 16px;
        height: 45px;
        padding: 10px 12px;
      }

      .form-group label,
      .form-control {
        font-size: 14px;
      }

      .form-control,
      input[type="text"],
      select {
        height: 40px;
      }

      .table-responsive-custom {
        overflow-x: auto;
        display: block;
      }

      table {
        width: auto;
      }

      .table th, .table td {
        min-width: 125px;
        font-size: 14px;
        padding: 8px 10px;
      }

      h4 {
        text-align: center;
      }
    }
  </style>
</head>
<body class="container-fluid">
    <h3 style="text-align:center;" class="text-uppercase">Aluno que não apresentaram tarefa N<?= htmlspecialchars($colunaNota) ?></h3>
    <p style="font-size: 14px;" class="text-uppercase">Titulo da Tarefa: <?= $tituloTarefa;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Disciplina: <?= $disciplina;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Turma: <?= $turma;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Professor: <?= $professor;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Tipo Tarefa: <?= $tipo;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Data: <?= $data;?></p>
    <p style="font-size: 14px;" class="text-uppercase">Trimestre: <?= $nometrimestre;?></p>
    <table>
        <tr>
            <th>Matrícula</th>
            <th>Nome</th>
            <th>N<?= htmlspecialchars($colunaNota) ?></th>
        </tr>
        <?php foreach ($alunos as $aluno): ?>
            <tr>
                <td><?= htmlspecialchars($aluno['matricula']) ?></td>
                <td><?= htmlspecialchars($aluno['nome']) ?></td>
                <td>
    <?= 
        $aluno[$colunaNota] === 'F' ? 'Aluno Ausente' :
        ($aluno[$colunaNota] === 'N' ? 'Não Apresentou a Tarefa' : htmlspecialchars($aluno[$colunaNota]))
    ?>
</td>

            </tr>
        <?php endforeach; ?>
    </table><br>
    <button class="btn btn-success" onclick="window.location.href='https://avilagoiania.kaltekgoiania.com.br/simulados/tarefas/tarefas-cadastradas/'">
    Voltar
   </button><br>
</body>
</html>
