<?php
include 'config.php';
$lastID = $_GET['lastid'] ?? '';
$regNo  = $_GET['regno'] ?? '';
$name   = $_GET['name'] ?? '';

if (!empty($lastID) && !empty($regNo) && !empty($name)) {
    $sql = "SELECT * FROM graduation2025 
            WHERE id='" . mysqli_real_escape_string($conn, $lastID) . "' 
            AND reg_no='" . mysqli_real_escape_string($conn, $regNo) . "' 
            AND name='" . mysqli_real_escape_string($conn, $name) . "'";
    $result  = mysqli_query($conn, $sql);
    $numrows = mysqli_num_rows($result);
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Success</title>
  <style>
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: #f8f9fa;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      margin: 0;
      padding: 20px;
    }
    .box {
      background: #fff;
      padding: 40px 30px;
      border-radius: 16px;
      box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
      text-align: center;
      max-width: 650px;
      width: 100%;
      animation: fadeInScale 0.6s ease forwards;
    }
    .icon {
      margin-bottom: 20px;
    }
    .icon svg {
      width: 80px;
      height: 80px;
      fill: none;
      stroke-linecap: round;
      stroke-linejoin: round;
    }
    .circle {
      stroke-width: 3;
      stroke-dasharray: 240;
      stroke-dashoffset: 240;
      animation: circleAnim 1s ease forwards;
    }
    .check {
      stroke-width: 5;
      stroke-dasharray: 50;
      stroke-dashoffset: 50;
      animation: checkAnim 0.8s ease forwards 1s;
    }
    .cross-line {
      stroke-width: 5;
      stroke-linecap: round;
    }
    h1 {
      font-size: 26px;
      margin: 15px 0 10px;
    }
    p {
      font-size: 16px;
      margin-bottom: 25px;
    }
    .btn-back {
      display: inline-block;
      background: #0d6efd;
      color: white;
      padding: 12px 25px;
      border-radius: 8px;
      text-decoration: none;
      font-weight: 500;
      transition: 0.3s;
    }
    .btn-back:hover {
      background: #0b5ed7;
    }
    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 1.5rem;
    }
    th, td {
      text-align: left;
      padding: 10px;
      border-bottom: 1px solid #dee2e6;
      word-break: break-word;
    }
    th {
      width: 35%;
    }
    tr:nth-child(even) td {
      background-color: #f9f9f9;
    }
    /* Animations */
    @keyframes circleAnim { to { stroke-dashoffset: 0; } }
    @keyframes checkAnim  { to { stroke-dashoffset: 0; } }
    @keyframes fadeInScale {
      from { opacity: 0; transform: scale(0.9); }
      to   { opacity: 1; transform: scale(1); }
    }
    /* Color variations */
    .success h1, .success p { color: #198754; }
    .success .circle, .success .check { stroke: #198754; }
    .error h1, .error p { color: #dc3545; }
    .error .circle, .error .cross-line { stroke: #dc3545; }
  </style>
</head>
<body>
<?php if ($numrows > 0) {
    $fetchArr = mysqli_fetch_assoc($result);
?>
  <!-- Success Box -->
  <div class="box success">
    <div class="icon">
      <svg viewBox="0 0 80 80">
        <circle class="circle" cx="40" cy="40" r="38"></circle>
        <path class="check" d="M22 42 L34 54 L60 28"></path>
      </svg>
    </div>
    <h1>Success!</h1>
    <p>Your request has been processed successfully.</p>
    <div class="table-responsive">
      <table>
        <tr><th colspan="2" style="text-align:center;background:#198754;color:#fff;">Registration Details</th></tr>
        <tr><th>Name</th><td><?php echo $fetchArr['name']; ?></td></tr>
        <tr><th>Register No</th><td><?php echo $fetchArr['reg_no']; ?></td></tr>
        <tr><th>Email</th><td><?php echo $fetchArr['email']; ?></td></tr>
        <tr><th>Phone</th><td><?php echo $fetchArr['mobile']; ?></td></tr>
        <tr><th>Course</th><td><?php echo $fetchArr['course']; ?></td></tr>
        <tr><th>Batch</th><td><?php echo $fetchArr['batch']; ?></td></tr>
        <tr><th>Submitted On</th><td><?php echo $fetchArr['regon']; ?></td></tr>
      </table>
    </div>
    <a href="index.php" class="btn-back">Go Back Home</a>
  </div>
<?php } else { ?>
  <!-- Error Box -->
  <div class="box error">
    <div class="icon">
      <svg viewBox="0 0 80 80">
        <circle class="circle" cx="40" cy="40" r="38"></circle>
        <line class="cross-line" x1="25" y1="25" x2="55" y2="55"></line>
        <line class="cross-line" x1="55" y1="25" x2="25" y2="55"></line>
      </svg>
    </div>
    <h1>Error!</h1>
    <p>Record not found. Please check your details and try again.</p>
    <a href="index.php" class="btn-back">Go Back Home</a>
  </div>
<?php } ?>
</body>
</html>
<?php } ?>
