
        <?php include 'include/navbar.php';?>
        <?php include 'include/sidebar.php';?>
     
            <div id="layoutSidenav_content">
                <main>
                    <div class="container-fluid px-4">
                        <h1 class="mt-4">Dashboard</h1>
                        <ol class="breadcrumb mb-4">
                            <li class="breadcrumb-item active">Add Visa</li>
                        </ol>

                        <div class=" mt-4">

<?php
// DB connection
$visa_types = $conn->query("SELECT * FROM visa_types");
?>
<?php


// Fetch countries for dropdown
$countries = mysqli_query($conn, "SELECT * FROM countries ORDER BY country_name ASC");

if (isset($_POST['submit'])) {
    $title = $_POST['title'];
    $short_detail = $_POST['short_detail'];
    $full_detail = $_POST['full_detail'];
    $country_id = $_POST['country_id'];
    $apply_link = $_POST['apply_link'];
    $visa_type = $_POST['visa_type'];
    $sub_visa_type = $_POST['sub_visa_type'];

    $insert = mysqli_query($conn, "INSERT INTO visas (title, short_detail, full_detail, country_id, apply_link, visa_type, sub_visa_type) VALUES ('$title', '$short_detail', '$full_detail', '$country_id', '$apply_link','$visa_type', '$sub_visa_type')");

    echo $insert ? "<script>alert('Visa uploaded successfully');</script>" : "<script>alert('Error uploading visa');</script>";
}
?>

<form method="POST" >
  <input type="text" name="title" class="form-control mb-3" placeholder="Visa Title" required>
  
  <input type="text" name="apply_link" class="form-control mb-3" placeholder="Apply Now Link" required>
  <textarea name="short_detail" class="form-control mb-3" placeholder="Short Detail" required></textarea>
  
  
  <select name="country_id" class="form-control mb-3" required>
    <option value="">Select Country</option>
    <?php while ($row = mysqli_fetch_assoc($countries)): ?>
      <option value="<?= $row['id']; ?>"><?= $row['country_name']; ?></option>
    <?php endwhile; ?>
  </select>
  
    <div class="mb-3">
      <select name="visa_type" id="visa_type" class="form-select">
        <option value="">Select Visa Service</option>
        <?php while($row = $visa_types->fetch_assoc()) { ?>
          <option value="<?= $row['id'] ?>"><?= htmlspecialchars($row['visa_type']) ?></option>
        <?php } ?>
      </select>
    </div>

    <div class="mb-3">
      <select name="sub_visa_type" id="sub_visa_type" class="form-select">
        <option value="">Select Visa Candidats</option>
      </select>
    </div>


<script>
  $(document).ready(function(){
    $('#visa_type').on('change', function(){
      var visa_type_id = $(this).val();
      if(visa_type_id != ""){
        $.ajax({
          url: "get_sub_visa_types.php",
          type: "GET",
          data: { visa_type_id: visa_type_id },
          success: function(data){
            $('#sub_visa_type').html(data);
          }
        });
      } else {
        $('#sub_visa_type').html('<option value="">Select Sub Visa Type</option>');
      }
    });
  });
</script>
      
      
  <textarea name="full_detail" class="form-control mb-3" id="arContent" placeholder="Full Detail" required></textarea>
  
  <button type="submit" name="submit" class="btn btn-primary">Upload Visa</button>
</form>

 
                    </div>
                </main>
                <?php include "include/footer.php";?>
            </div>
        </div>
<!-- JS TextEditor -->
<script src="//cdn.ckeditor.com/4.13.1/standard/ckeditor.js"></script>
         <script>
        CKEDITOR.replace('arContent');
    </script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        <script src="js/scripts.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
        <script src="assets/demo/chart-area-demo.js"></script>
        <script src="assets/demo/chart-bar-demo.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" crossorigin="anonymous"></script>
        <script src="js/datatables-simple-demo.js"></script>
    </body>
</html>
