<?php
// === Turn on error reporting ===
error_reporting(E_ALL);
ini_set('display_errors', 1);

// === Get logged-in student reg number (replace with your session variable) ===
$studentreg = $student_reg_number;

// === Fetch attendance records ===
$query = "SELECT `id`, `reg_number`, `name`, `date`, `term`, `session`, `class`, `roll_call`, `afternoonrollcall` 
          FROM `student_attendance` 
          WHERE reg_number = ?";
$stmt = $connection->prepare($query);
$stmt->bind_param("s", $studentreg);
$stmt->execute();
$result = $stmt->get_result();
?>




  <!-- DataTables CSS -->
  <link href="https://cdn.datatables.net/1.13.7/css/dataTables.bootstrap5.min.css" rel="stylesheet">
  <link href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.bootstrap5.min.css" rel="stylesheet">



  <style>
 
    .page-header {
      background: linear-gradient(135deg, #0d6efd, #198754);
      color: #fff;
      padding: 20px 25px;
      border-radius: 10px;
      margin-bottom: 25px;
      box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    }
    .table-container {
      background: #fff;
      padding: 25px;
      border-radius: 10px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }
    table.dataTable thead {
      background-color: #198754;
      color: #fff;
    }
    .dt-buttons .btn {
      border-radius: 8px !important;
    }
  </style>


<div class="container-fluid mt-4">
  <div class="page-header">
    <h3><i class="fa fa-clipboard-check me-2"></i>My Attendance Record</h3>
    <p class="mb-0">View your attendance history for all terms and sessions.</p>
  </div>

  <div class="table-container">
    <table id="attendanceTable" class="table table-striped table-hover align-middle">
      <thead>
        <tr>
          <th>#</th>
          <th>Date</th>
          <th>Term</th>
          <th>Session</th>
          <th>Class</th>
          <th>Morning Roll Call</th>
          <th>Afternoon Roll Call</th>
        </tr>
      </thead>
      <tbody>
        <?php 
        $count = 1;
        while ($row = $result->fetch_assoc()): 
        ?>
        <tr>
          <td><?= $count++; ?></td>
          <td><?= htmlspecialchars($row['date']); ?></td>
          <td><?= htmlspecialchars($row['term']); ?></td>
          <td><?= htmlspecialchars($row['session']); ?></td>
          <td><?= htmlspecialchars($row['class']); ?></td>
          <td>
            <?php if ($row['roll_call'] == 'Present'): ?>
              <span class="badge bg-success"><i class="fa fa-check"></i> Present</span>
            <?php elseif ($row['roll_call'] == 'Absent'): ?>
              <span class="badge bg-danger"><i class="fa fa-times"></i> Absent</span>
            <?php else: ?>
              <span class="badge bg-secondary">N/A</span>
            <?php endif; ?>
          </td>
          <td>
            <?php if ($row['afternoonrollcall'] == 'Present'): ?>
              <span class="badge bg-success"><i class="fa fa-check"></i> Present</span>
            <?php elseif ($row['afternoonrollcall'] == 'Absent'): ?>
              <span class="badge bg-danger"><i class="fa fa-times"></i> Absent</span>
            <?php else: ?>
              <span class="badge bg-secondary">N/A</span>
            <?php endif; ?>
          </td>
        </tr>
        <?php endwhile; ?>
      </tbody>
    </table>
  </div>
</div>

<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<!-- DataTables Scripts -->
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.bootstrap5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.print.min.js"></script>


