
        <?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 Type</li>
                        </ol>

                        <div class=" mt-4">
                            
<?php

if (isset($_GET['delete'])) {
    $id = intval($_GET['delete']);
    $conn->query("DELETE FROM visa_types WHERE id = $id");
    header("Location: add-visa-type.php");
    
}


if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $visa_type = trim($_POST["visa_type"]);

  if (!empty($visa_type)) {
    $stmt = $conn->prepare("INSERT INTO visa_types (visa_type) VALUES (?)");
    $stmt->bind_param("s", $visa_type);

    if ($stmt->execute()) {
      echo "<script>alert('Visa Type Added Successfully');</script>";
    } else {
      echo "Error: " . $stmt->error;
    }

    $stmt->close();
  } else {
    echo "Visa type cannot be empty.";
  }
}


// Fetch all visa types
$result = $conn->query("SELECT * FROM visa_types");
?>

  <form action="" method="POST">
    <div class="mb-3">
      <label for="visa_type" class="form-label">Visa Type</label>
      <input type="text" name="visa_type" id="visa_type" class="form-control" required>
    </div>
    <button type="submit" class="btn btn-primary">Add Visa Type</button>
  </form>
  
    <h3>All Visa Types</h3>
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>ID</th>
        <th>Visa Type</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <?php while ($row = $result->fetch_assoc()) { ?>
        <tr>
          <td><?= $row['id'] ?></td>
          <td><?= htmlspecialchars($row['visa_type']) ?></td>
          <td><a href="?delete=<?= $row['id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Delete this visa type?')">Delete</a></td>
        </tr>
      <?php } ?>
    </tbody>
  </table>
</div>
 
                    </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>
