<?php include 'include/header.php';?>
<?php include 'include/navbar.php';?>
<div style="background-image:url('img/about-us.jpg'); background-size: cover; background-repeat: no-repeat;">
<header class="py-5 text-center" style="background-color:rgb(000, 000, 000,0.8);">
  <div class="container">
    <h1 class="text-white section-title">Apply Now</h1>
    <p class="text-white">Start your journey with <?php echo $info['website_name']; ?> — apply now for a fast, secure, and hassle-free visa process!</p>
  </div>
</header>
</div>



 <div class="container mt-5">
    
    
    
    <?php

if (isset($_POST['apply_job'])) {
    
    
        $recaptcha_response = $_POST['g-recaptcha-response'];

    $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$recaptcha_secret}&response={$recaptcha_response}");
    $captcha_success = json_decode($verify);

    if (!$captcha_success->success) {
        echo "<p class='p-2 bg-danger text-white text-center rounded'>reCAPTCHA verification failed. Please try again.</p>";
    } else {
       $name = $_POST['name'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$profession = $_POST['profession'];
$experience = $_POST['experience'];
$salary = $_POST['salary'];
$savings = $_POST['savings'];
$visa_type = $_POST['visa_type'];
$address = $_POST['address'];

$sql = "INSERT INTO visa_applications (name, contact, email, profession, experience, salary, savings, visa_type,address)
        VALUES ('$name', '$contact', '$email', '$profession', '$experience', '$salary', '$savings', '$visa_type', '$address')";

if ($conn->query($sql) === TRUE) {
  echo "<script>alert('Application submitted successfully!'); window.location.href='visas.php';</script>";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}
    }
}
?>

    
    
    <form action="" method="POST" class="bg-white p-4 rounded shadow-sm">
      <div class="mb-3">
        <label>Name 🙋‍♂️</label>
        <input type="text" name="name" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Contact Number 📲</label>
        <input type="text" name="contact" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Email Address 📩</label>
        <input type="email" name="email" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Job Profession 🤷‍♂️</label>
        <input type="text" name="profession" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Working Experience 🧑‍🍳 (Years)</label>
        <input type="text" name="experience" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Monthly Salary</label>
        <input type="text" name="salary" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Current Savings (last 6 months)</label>
        <input type="text" name="savings" class="form-control" required>
      </div>
      <div class="mb-3">
        <label>Complete Address</label>
        <textarea type="text" name="address" class="form-control" required></textarea>
      </div>
      <?php

// Get job_id from URL
$job_id = isset($_GET['job_id']) ? intval($_GET['job_id']) : 0;
$visa_title = "";

if ($job_id > 0) {
  $result = $conn->query("SELECT title FROM visas WHERE id = $job_id LIMIT 1");
  if ($result && $row = $result->fetch_assoc()) {
    $visa_title = $row['title'];
  }
}
?>

<div class="mb-3">
  <label>Visa Title</label>
  <input type="text" name="visa_type" class="form-control" value="<?= htmlspecialchars($visa_title) ?>" readonly>
</div>
<!-- Google reCAPTCHA -->
  <div class="mb-3">
    <div class="g-recaptcha" data-sitekey="<?php echo $recaptcha_site;;?>"></div>
      <button type="submit" name="apply_job" class="btn my-btn w-100">Submit Application</button>
    </form>
  </div>

</div>







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