<?php
// print_result.php - final merged + print fixes + watermark
session_start();
require_once "auth/auth_check.php";
require_once 'auth/config.php';

// helpers
function safe($arr, $k, $d = '') { return isset($arr[$k]) ? $arr[$k] : $d; }

// defaults / fallbacks
$defaultLogo = 'logo.png';
$defaultBg   = 'logo.png';

// initialize
$schoolLogo = $defaultLogo;
$schoolBg   = $defaultBg;

$admission_number = $_POST['admission_number'] ?? '';

// Active term & session come from the database, same as finalize_results.php
$active_term_row    = $conn->query("SELECT name FROM terms    WHERE is_active = 1 LIMIT 1")->fetch_assoc();
$active_session_row = $conn->query("SELECT name FROM sessions WHERE is_active = 1 LIMIT 1")->fetch_assoc();
$term    = $active_term_row    ? $active_term_row['name']    : '';
$session = $active_session_row ? $active_session_row['name'] : '';

$resultsFound = false;
$approved = 0;
$student = null;
$message = '';
$notice = '';
$subjectResults = [];
$management = [];
$classTeacher = null;
$punctuality = null;
$totalMarks = 0;
$position = 'N/A';
$classAvg = null;
$average = 0.00;
$promotion_status = 'No promotion status yet';
$teacher_remark = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && trim($admission_number) !== '') {
    $admission_number = trim($admission_number);

    // fetch student
    $stmt = $conn->prepare("SELECT * FROM students WHERE admission_number=? LIMIT 1");
    $stmt->bind_param("s", $admission_number);
    $stmt->execute();
    $student = stmt_get_result($stmt)->fetch_assoc();
    $stmt->close();

    if (!$student) {
        $message = "Student not found for admission number: " . htmlspecialchars($admission_number);
    } else {
        // management
        $mres = $conn->query("SELECT * FROM management LIMIT 1");
        $management = $mres ? $mres->fetch_assoc() : [];
        $schoolLogo = safe($management, 'logo', $defaultLogo) ?: $defaultLogo;
        $schoolBg   = safe($management, 'bg_image', $defaultBg) ?: $defaultBg;

// resumption date & closing date
$next_term_date = '';
$closing_date = '';
$rdate = $conn->query("SELECT next_term_date, closing_date FROM management LIMIT 1");
if ($rdate && $rdate->num_rows > 0) {
    $mgmtDates = $rdate->fetch_assoc();
    $next_term_date = $mgmtDates['next_term_date'] ?? '';
    $closing_date   = $mgmtDates['closing_date'] ?? '';
}

        // fetch result (present logic: if term+session provided, fetch that, else latest)
        if ($term && $session) {
            $rstmt = $conn->prepare("SELECT * FROM results WHERE admission_number=? AND term=? AND session=? LIMIT 1");
            $rstmt->bind_param("sss", $admission_number, $term, $session);
        } else {
            $rstmt = $conn->prepare("SELECT * FROM results WHERE admission_number=? ORDER BY id DESC LIMIT 1");
            $rstmt->bind_param("s", $admission_number);
        }
        $rstmt->execute();
        $resultRow = stmt_get_result($rstmt)->fetch_assoc();
        $rstmt->close();

        if ($resultRow) {
            $resultsFound = true;
            $approved = (int)$resultRow['approved'];
            $notice = safe($resultRow, 'notice', '');
            $term = safe($resultRow, 'term', $term);
            $session = safe($resultRow, 'session', $session);

            if ($approved === 1) {
                // fetch all subject rows for this admission/term/session
                $rst = $conn->prepare("SELECT * FROM results WHERE admission_number=? AND term=? AND session=? ORDER BY subject ASC");
                $rst->bind_param("sss", $admission_number, $term, $session);
                $rst->execute();
                $subjectResults = stmt_get_result($rst)->fetch_all(MYSQLI_ASSOC);
                $rst->close();

                $promotion_status = safe($subjectResults[0], 'promoted_to', 'No promotion status yet');
                $teacher_remark = safe($subjectResults[0], 'teacher_comment', '');

                // calculate totals & grades
                $totalMarks = 0;
                foreach ($subjectResults as &$s) {
                    $first_ca = (int)($s['first_ca'] ?? $s['ca'] ?? 0);
                    $second_ca = (int)($s['second_ca'] ?? 0);
                    $exam = (int)($s['exam'] ?? 0);
                    $ca_total = $first_ca + $second_ca;
                    $total = $ca_total + $exam;

                    if ($total >= 70)      { $grade='A'; $remark='Excellent'; }
                    elseif ($total >= 60) { $grade='B'; $remark='Very Good'; }
                    elseif ($total >= 50) { $grade='C'; $remark='Good'; }
                    elseif ($total >= 45) { $grade='D'; $remark='Fair'; }
                    elseif ($total >= 40) { $grade='E'; $remark='Pass'; }
                    else                  { $grade='F'; $remark='Fail'; }

                    $s['first_ca']=$first_ca;
                    $s['second_ca']=$second_ca;
                    $s['ca_total']=$ca_total;
                    $s['exam']=$exam;
                    $s['total']=$total;
                    $s['grade']=$grade;
                    $s['remark']=$remark;

                    $totalMarks += $total;
                }
                unset($s);

                // average based on number of subjects (adjust if you want fixed denominator)
                $average = round($totalMarks / 12, 2);

                // class average & position
                $student_class = safe($student,'class','');
                $posStmt = $conn->prepare("
                    SELECT r.admission_number,
                           SUM(COALESCE(r.first_ca,0)+COALESCE(r.second_ca,0)+COALESCE(r.exam,0)) AS total
                    FROM results r
                    JOIN students s ON r.admission_number=s.admission_number
                    WHERE s.class=? AND r.term=? AND r.session=?
                    GROUP BY r.admission_number ORDER BY total DESC
                ");
                $posStmt->bind_param("sss",$student_class,$term,$session);
                $posStmt->execute();
                $classTotals=[];
                $posRes=stmt_get_result($posStmt);
                while($row=$posRes->fetch_assoc()) $classTotals[]=$row;
                $posStmt->close();

                if($classTotals){
                    $sum=0;
                    foreach($classTotals as $ct) $sum+=(int)$ct['total'];
                    $classAvg=round(($sum/count($classTotals))/12,2);
                    $pos=1;
                    foreach($classTotals as $ct){
                        if($ct['admission_number']==$admission_number){$position=$pos;break;}
                        $pos++;
                    }
                }

                // punctuality
                $pstmt=$conn->prepare("SELECT * FROM punctuality WHERE admission_number=? AND term=? LIMIT 1");
                $pstmt->bind_param("ss",$admission_number,$term);
                $pstmt->execute();
                $punctuality=stmt_get_result($pstmt)->fetch_assoc();
                $pstmt->close();

                // class teacher
                $tstmt=$conn->prepare("SELECT * FROM teachers WHERE class=? LIMIT 1");
                $tstmt->bind_param("s",$student_class);
                $tstmt->execute();
                $classTeacher=stmt_get_result($tstmt)->fetch_assoc();
                $tstmt->close();
            }
        } else {
            $message = "No results found for this student on the selected period.";
        }
    }
}

// ensure strings for output
$schoolLogo = (string)$schoolLogo;
$schoolBg = (string)$schoolBg;

include 'header.php';
?>

<main class="main">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">

<style>
:root{--primary:#4b0082;--muted:#666}
body{font-family:Arial,Helvetica,sans-serif;background:#f4f6f8;margin:0;padding:1rem}
.container-main{max-width:1000px;margin:auto}
.card{background:#fff;border:2px solid var(--primary);border-radius:10px;overflow:hidden;position:relative;box-shadow:0 6px 18px rgba(75,0,130,0.08)}
.header{display:flex;align-items:center;gap:12px;padding:16px;border-bottom:4px solid var(--primary)}
.logo{width:90px;height:90px;object-fit:contain}
.school-meta{text-align:center;flex:1}
.school-meta h2{margin:0;color:var(--primary)}
.bg-image{position:absolute;inset:0;z-index:0;pointer-events:none;background-image:url('<?= htmlspecialchars($schoolBg) ?>');background-position:center;background-repeat:no-repeat;background-size:contain;opacity:0.08}

/* Hide specific on-screen elements when printing */
@media print{
  .no-print, #searchForm, .controls { display: none !important; }
  .bg-image{opacity:0.06 !important}

  /* Hide the app's own header/sidebar/bottom-nav chrome so only the result sheet prints */
  .top-header, .sidebar, .bottom-nav, .profile-menu, .notify-overlay { display:none !important; }
  .main { margin-left:0 !important; padding:0 !important; }
}

/* Watermark (print only) */
.watermark{
  display:none; /* hidden on screen */
}
@media print{
  .watermark{
    display:block;
    position:fixed;
    left:50%;
    top:45%;
    transform:translate(-50%,-50%) rotate(-30deg);
    font-size:26px;
    letter-spacing:3px;
    opacity:0.08;
    color:#333;
    z-index:9999;
    width:120%;
    text-align:center;
    pointer-events:none;
    font-weight:700;
  }
}

/* content styles */
.student-info{display:flex;gap:12px;align-items:center;padding:12px;border:1px dashed #eee;border-radius:8px;background:#fafafa;z-index:1;box-shadow:0 4px 8px rgba(0,0,0,0.03)}
.student-photo{width:100px;height:100px;object-fit:cover;border-radius:8px;border:1px solid #ddd}
.notice-box{background:#fff3cd;border:1px solid #ffeeba;color:#856404;padding:16px;border-radius:10px;text-align:center;margin-top:20px;font-weight:600;z-index:1}
.table td,.table th{vertical-align:middle}
.table th{background:var(--primary);color:#fff}

/* restored print friendly blocks from old file */
.table-wrap{overflow:auto;margin-top:12px;z-index:1}
.summary{display:flex;gap:12px;flex-wrap:wrap;margin-top:12px;z-index:1}
.summary .box{flex:1;min-width:140px;background:#fff;padding:12px;border:1px solid #eee;border-radius:8px;box-shadow:0 4px 8px rgba(75,0,130,0.03)}
.sign-row{display:flex;gap:12px;justify-content:space-between;align-items:flex-start;margin-top:18px;z-index:1}
.sign-box{width:48%;text-align:center;border:1px solid #eee;padding:14px;border-radius:8px;background:#fff;box-shadow:0 6px 14px rgba(75,0,130,0.03)}
.sign-small{width:48%;text-align:center;border:1px solid #eee;padding:14px;border-radius:8px;background:#fff;box-shadow:0 6px 14px rgba(75,0,130,0.03)}
.sign-box img{max-width:180px;height:auto;display:block;margin:0 auto 6px}
.note{font-style:italic;color:var(--muted);margin-top:6px}
.punct-table th{background:var(--primary);color:#fff}
@media (max-width:720px){
  body{padding:0.35rem}
  .main{padding-left:6px !important; padding-right:6px !important;}
  .container-main{max-width:100%}
  .card{border-radius:8px}
  .header{flex-direction:column;align-items:flex-start;padding:10px}
  .student-info{flex-direction:column;align-items:flex-start}
  .sign-row{flex-direction:column}
  .sign-small{width:100%}
  .sign-box{width:100%}
  .summary{flex-direction:column}
  .p-3{padding:0.75rem !important}
}

/* Ensure background shows on print */
@media print {
  body {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    background-image: url('<?= htmlspecialchars($schoolBg) ?>') !important;
    background-size: cover !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
  }
  @page { margin: 0; }
}

.small-muted{font-size:13px;color:var(--muted)}
</style>

  <!-- Watermark for print -->
  <div class="watermark">
    Albayan Academy Nur & Pri - Official Student Result Copy
  </div>

<div class="container-main">
  <div class="card">
    <div class="header">
      <img src="<?= htmlspecialchars($schoolLogo) ?>" alt="logo" class="logo" onerror="this.style.display='none'">
      <div class="school-meta">
        <h2><?= htmlspecialchars(safe($management,'school_name','Albayan Academy Nursery & Primary School Shd')) ?></h2>
        <div><?= htmlspecialchars(safe($management,'address','Tudun Wada, Shendam, Plateau State Nigeria')) ?></div>
        <div>Phone: <?= htmlspecialchars(safe($management,'phone','+234 8060922001')) ?> | Email: <?= htmlspecialchars(safe($management,'email','albayanacademynurprischshd@gmail.com')) ?></div>
      </div>
      <div style="text-align:right">
        <div class="small-muted">Printed: <?= date('d M, Y') ?></div>
        <div style="margin-top:8px" class="no-print">
          <button class="btn btn-primary btn-sm" onclick="document.getElementById('searchForm').submit()">Fetch result</button>
          <button class="btn btn-dark btn-sm" onclick="window.print()">Print result sheet</button>
        </div>
      </div>
    </div>

    <div class="p-3 controls no-print">
      <form id="searchForm" method="POST" class="row g-2 align-items-center">
        <div class="col-md-6"><input name="admission_number" class="form-control" placeholder="Admission Number" required value="<?= htmlspecialchars($admission_number) ?>"></div>
        <div class="col-md-6">
          <div class="small-muted" style="padding:8px 12px;background:#f4f0fa;border:1px solid #e2d9f0;border-radius:8px">
            Active Term: <strong><?= htmlspecialchars($term ?: 'Not set') ?></strong>
            &nbsp;|&nbsp;
            Active Session: <strong><?= htmlspecialchars($session ?: 'Not set') ?></strong>
          </div>
        </div>
      </form>
    </div>

    <div class="results-area position-relative p-3">
      <div class="bg-image" aria-hidden="true"></div>

      <?php if ($message): ?>
        <div class="alert alert-warning"><?= $message ?></div>

      <?php elseif ($resultsFound && $approved === 0): ?>
        <div class="student-info">
          <img src="<?= 'photos/' . htmlspecialchars(safe($student,'photo','default.png')) ?>" alt="student" class="student-photo" onerror="this.src='default.png'">
          <div style="margin-left:12px">
            <div style="font-weight:700;font-size:16px"><?= htmlspecialchars(safe($student,'first_name','') . ' ' . safe($student,'sur_name','') . ' ' . safe($student,'last_name','')) ?></div>
            <div class="small-muted">Admission No: <strong><?= htmlspecialchars(safe($student,'admission_number','')) ?></strong></div>
            <div class="small-muted">Class: <strong><?= htmlspecialchars(safe($student,'class','')) ?></strong> | House: <strong><?= htmlspecialchars(safe($student,'house','')) ?></strong></div>
            <div class="small-muted">Term: <strong><?= htmlspecialchars($term) ?></strong> | Session: <strong><?= htmlspecialchars($session) ?></strong></div>
          </div>
        </div>
        <div class="notice-box mt-3">
          Result Not Yet Approved<br>
          <em><?= $notice ? htmlspecialchars($notice) : 'Please contact the school management for more information +2348060922001.' ?></em>
        </div>

      <?php elseif ($resultsFound && $approved === 1): ?>
        <!-- FULL APPROVED RESULTS -->
        <div class="student-info">
          <img src="<?= 'photos/' . htmlspecialchars(safe($student,'photo','default.png')) ?>" alt="student" class="student-photo" onerror="this.src='default.png'">
          <div style="margin-left:12px">
            <div style="font-weight:700;font-size:16px"><?= htmlspecialchars(safe($student,'first_name','') . ' ' . safe($student,'sur_name','') . ' ' . safe($student,'last_name','')) ?></div>
            <div class="small-muted">Admission No: <strong><?= htmlspecialchars(safe($student,'admission_number','')) ?></strong></div>
            <div class="small-muted">Class: <strong><?= htmlspecialchars(safe($student,'class','')) ?></strong> | House: <strong><?= htmlspecialchars(safe($student,'house','')) ?></strong></div>
            <div class="small-muted">Term: <strong><?= htmlspecialchars($term) ?></strong> | Session: <strong><?= htmlspecialchars($session) ?></strong></div>
          </div>
         


<div style="margin-left:auto;text-align:center;display:flex;flex-direction:column;align-items:center;gap:2px">
   
    <div style="font-weight:700;margin-top:3px">Position: <?= htmlspecialchars($position) ?></div>

    <?php if ($approved === 1): ?>
        <?php
            $qrData = urlencode($admission_number . "|" . $term . "|" . $session);
            $qrUrl = "https://api.qrserver.com/v1/create-qr-code/?size=80x80&data=https://albayan.ymairiga.com.ng/verify.php?data=$qrData";
        ?>
        <img src="<?= $qrUrl ?>" alt="Verify Result QR Code" style="width:80px;height:80px;border:2px dashed #4b0082;padding:1px;border-radius:6px">

    <?php endif; ?>
</div></div>

        <div class="table-responsive mt-3 table-wrap">
          <table class="table table-bordered table-sm">
            <thead>
              <tr>
                <th>Subject</th>
                <th>CA (1st+2nd)</th>
                <th>Exam</th>
                <th>Total</th>
                <th>Grade</th>
                <th>Remark</th>
              </tr>
            </thead>
            <tbody>
              <?php foreach($subjectResults as $s): ?>
              <tr>
                <td><?= htmlspecialchars($s['subject']) ?></td>
                <td><?= htmlspecialchars($s['ca_total']) ?></td>
                <td><?= htmlspecialchars($s['exam']) ?></td>
                <td><?= htmlspecialchars($s['total']) ?></td>
                <td><?= htmlspecialchars($s['grade']) ?></td>
                <td><?= htmlspecialchars($s['remark']) ?></td>
              </tr>
              <?php endforeach; ?>
            </tbody>
          </table>
        </div>

        <!-- TOTALS & AVERAGE -->
        <div class="d-flex gap-3 flex-wrap mt-3 summary">
          <div class="box">Total Marks: <div style="font-weight:700;font-size:16px"><?= $totalMarks ?></div></div>
          <div class="box"> Total Average: <div style="font-weight:700;font-size:16px"><?= number_format($average,2) ?></div></div>
          <div class="box">Class Average: <div style="font-weight:700;font-size:16px"><?= $classAvg !== null ? number_format($classAvg,2) : 'N/A' ?></div></div>
          <div class="box">Subjects Count: <div style="font-weight:700;font-size:16px"><?= count($subjectResults) ?></div></div>
        </div>

        <!-- PUNCTUALITY -->
        <h6 class="mt-3" style="color:var(--primary)">Punctuality & Conduct</h6>
        <?php if ($punctuality): ?>
        <div style="max-height:150px;overflow-y:auto">
<table class="table table-bordered table-sm punct-table">
          <thead>
            <tr>
              <th>Appearance</th>
              <th>Attendance in Class</th>
              <th>Relationship</th>
              <th>Class Participation</th>
              <th>Physical Activities</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td><?= htmlspecialchars(safe($punctuality,'appearance','')) ?></td>
              <td><?= htmlspecialchars(safe($punctuality,'attendance_in_class','')) ?></td>
              <td><?= htmlspecialchars(safe($punctuality,'relationship','')) ?></td>
              <td><?= htmlspecialchars(safe($punctuality,'class_participation','')) ?></td>
              <td><?= htmlspecialchars(safe($punctuality,'physical_activities','')) ?></td>
            </tr>
          </tbody>
        </table>
        </div>
        <?php else: ?>
          <p class="text-muted">No punctuality record available for this term.</p>
        <?php endif; ?>

        <!-- CLASS TEACHER INFO -->
        <h6 class="mt-3" style="color:var(--primary)">Class Teacher Information</h6>
        <?php if ($classTeacher): ?>
        <div style="max-height:180px;overflow-y:auto">
<table class="table table-bordered table-sm">
          <thead>
            <tr>
              <th>Photo</th>
              <th>Full Name</th>
              <th>Class</th>
              <th>Phone</th>
              <th>Signature</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                <?php
                  $tp = 'uploads/teachers/'.htmlspecialchars(safe($classTeacher,'photo',''));
                  if ($tp && file_exists($tp)): ?>
                    <img src="<?= $tp ?>" alt="teacher" style="width:80px;height:80px;object-fit:cover;border-radius:8px">
                  <?php else: ?>
                    <div style="width:80px;height:80px;background:#f2f2f2;border-radius:8px;display:flex;align-items:center;justify-content:center;color:#999">No photo</div>
                  <?php endif; ?>
              </td>
              <td><?= htmlspecialchars(safe($classTeacher,'fullname', safe($classTeacher,'name','Class Teacher'))) ?></td>
              <td><?= htmlspecialchars(safe($classTeacher,'class','')) ?></td>
              <td><?= htmlspecialchars(safe($classTeacher,'phone','')) ?></td>
              <td>
                <?php
                  $tSig = safe($classTeacher,'signature', safe($classTeacher,'class_teacher_signature',''));
                  if ($tSig && file_exists('uploads/signatures/'.$tSig)) {
                      echo "<img src='uploads/signatures/".htmlspecialchars($tSig)."' style='max-width:180px;height:auto'>";
                  } elseif ($tSig && file_exists('uploads/teachers/'.$tSig)) {
                      echo "<img src='uploads/teachers/".htmlspecialchars($tSig)."' style='max-width:180px;height:auto'>";
                  } else {
                      echo "<div style='height:48px'></div>";
                  }
                ?>
              </td>
            </tr>
          </tbody>
        </table>
        </div>
        <?php endif; ?>

        <!-- Class teacher's remark -->
        <h6 class="mt-3" style="color:var(--primary)">Class Teacher's Remark for this Student</h6>
        <div style="padding:10px;border:1px solid #eee;border-radius:8px;background:#fff;box-shadow:0 4px 10px rgba(75,0,130,0.03)"><?= $teacher_remark ? htmlspecialchars($teacher_remark) : '<em>No comment yet</em>' ?></div>

        <!-- SIGNATURES: Head teacher signature & Stamp -->
        <div class="sign-row mt-3">

  <!-- Head Teacher -->
  <div class="sign-box">
    <h6 style="color:var(--primary)">Head Teacher Sign</h6>
    <?php
      $hSig = safe($management,'head_signature','');
      if (!$hSig) $hSig = safe($management,'head_sig','');

      if ($hSig && file_exists('uploads/signatures/'.$hSig)) {
          echo "<img src='uploads/signatures/".htmlspecialchars($hSig)."' style='height:45px' alt='head sig'>";
      } elseif ($hSig && file_exists('uploads/management/'.$hSig)) {
          echo "<img src='uploads/management/".htmlspecialchars($hSig)."' style='height:45px' alt='head sig'>";
      } else {
          echo "<div style='height:45px'></div>";
      }
    ?>
    <div style="font-weight:700"><?= htmlspecialchars(safe($management,'head_name','Head Teacher')) ?></div>
  </div>

  <!-- CLOSING DATE -->
  <div class="sign-box" style="text-align:center">
    <h6 style="color:var(--primary)">Closing Date</h6>
    <table class="table table-bordered table-sm">
      <tr>
        <td style="font-weight:700">
         <?= $closing_date ? date('d-F-Y', strtotime($closing_date)) : 'Not Set' ?>
        </td>
      </tr>
    </table>
  </div>

  <!-- RESUMPTION DATE -->
  <div class="sign-box" style="text-align:center">
    <h6 style="color:var(--primary)">Resumption Date</h6>
    <table class="table table-bordered table-sm">
      <tr>
        <td style="font-weight:700">
         <?= $next_term_date ? date('d-F-Y', strtotime($next_term_date)) : 'Not Set' ?>
        </td>
      </tr>
    </table>
  </div>

  <!-- Stamp -->
  <div class="sign-small">
    <h6 style="color:var(--primary)">Stamp</h6>
    <?php
      $sStamp = safe($management,'stamp_image','');
      if (!$sStamp) $sStamp = safe($management,'stamp','');

      if ($sStamp && file_exists('uploads/management/'.$sStamp)) {
          echo "<img src='uploads/management/".htmlspecialchars($sStamp)."' style='height:70px' alt='stamp'>";
      } elseif ($sStamp && file_exists('uploads/signatures/'.$sStamp)) {
          echo "<img src='uploads/signatures/".htmlspecialchars($sStamp)."' style='height:70px' alt='stamp'>";
      } else {
          echo "<div style='height:70px'></div>";
      }
    ?>
    <div style="font-weight:700">Official Stamp</div>
  </div>

</div>

          <!-- MANAGEMENT NOTE (restored) -->
        <h6 class="mt-3" style="color:var(--primary)">Management / Head teacher comment</h6>
        <table class="table table-bordered table-sm mb-4">
          <tbody>
            <tr>
              <td><?= htmlspecialchars(safe($management,'mnote','No management note yet')) ?></td>
            </tr>
          </tbody>
        </table>

      <?php else: ?>
        <div class="alert alert-info">Enter student details to view result.</div>
      <?php endif; ?>
    </div>
  </div>
</div>

</main>

<?php include 'footer.php'; ?>