
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
// Set timezone to Riyadh
date_default_timezone_set('Asia/Riyadh');

// DB configuration
$host = 'localhost';
$dbname = 'balubaid_nissan_test_drive';
$user = 'balubaid_nissan_test_drive';
$pass = 'Vision@2050';

// Connect to DB
$conn = new mysqli($host, $user, $pass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$natid = $_POST['natid'] ?? '';
$update_success = false;

if ($natid) {
  $natid = $conn->real_escape_string($natid);
  $start_date = date('Y-m-d H:i:s'); // Time in Riyadh (Asia/Riyadh)

  // Update the status and start date
  $sql = "UPDATE nissan_registrations 
          SET status = 'started', start_date = '$start_date' 
          WHERE id = '$natid'";
  
  if ($conn->query($sql) === TRUE) {
    $update_success = true;
  }
}

$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

  <title>Test Drive Started</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #ddd;
      display: flex;
      justify-content: center;
      padding: 40px;
    }
    .form-container {
      background-color: #e3e3e3;
      padding: 30px;
      width: 350px;
      border-radius: 8px;
      text-align: center;
    }
    .form-container img {
      max-width: 150px;
      margin-bottom: 10px;
    }
    .form-container h1 {
      font-size: 22px;
      margin-bottom: 20px;
    }
    .form-container label {
      display: block;
      text-align: left;
      margin: 10px 0 5px;
    }
    .form-container input[type="text"],
    .form-container input[type="email"],
    .form-container input[type="file"],
    .form-container input[type="tel"] {
      width: 100%;
      padding: 8px;
      margin-bottom: 10px;
      border: none;
      border-radius: 4px;
    }
    .form-container .radio-group {
      display: flex;
      justify-content: space-around;
      margin-bottom: 15px;
    }
    .form-container .radio-group input {
      margin-right: 5px;
    }
    .form-container .submit-btn {
      background-color: #d72626;
      color: white;
      padding: 12px;
      border: none;
      width: 100%;
      font-weight: bold;
      font-size: 16px;
      border-radius: 5px;
      cursor: pointer;
    }
    .form-container .submit-btn:hover {
      background-color: #b01f1f;
    }
    label.error {
      color: red;
      font-size: 13px;
      display: block;
      text-align: left;
      margin-top: -8px;
      margin-bottom: 8px;
    }
  </style>
</head>
<body>

<div class="form-container" novalidate>
  <a href="/"><img src="https://nissan-test-drive.core3.agency/assets/Nissan Logo-01.png" alt="Petromin Logo" />   </a> 
    
  <div class="box">
    <?php if ($update_success): ?>
      <h2>Test Drive Started</h2>
      <p>Test Drive ID: <strong><?= htmlspecialchars($natid) ?></strong></p>
      <p>Status updated and start time recorded in Riyadh timezone.</p>
    <?php else: ?>
      <h2>Error</h2>
      <p>Unable to update the test drive status. Please check the Test Drive ID.</p>
    <?php endif; ?>
  </div>
  
  
  </div>
</body>

 <script>
    setTimeout(function () {
      window.location.href = "https://nissan-test-drive.core3.agency/";
    }, 5000); // 5000 milliseconds = 5 seconds
  </script>
</html>