<?php
session_start();

include("../config/config.php"); // add this

if (!isset($_SESSION['admin'])) {
    header("Location: " . BASE_URL . "auth/login.php");
    exit;
}
?>
<?php
include("../config/db.php");
include("../includes/header.php");
include("../includes/sidebar.php");

$result = $conn->query("SELECT * FROM districts ORDER BY id DESC");
?>

<h3>Districts</h3>

<a href="add.php" class="btn btn-primary mb-3">+ Add District</a>

<table class="table table-bordered">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Action</th>
    </tr>

    <?php while($row = $result->fetch_assoc()) { ?>
    <tr>
        <td><?= $row['id'] ?></td>
        <td><?= $row['name'] ?></td>
        <td>
            <a href="edit.php?id=<?= $row['id'] ?>" class="btn btn-warning btn-sm">Edit</a>
            <a href="delete.php?id=<?= $row['id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Delete?')">Delete</a>
        </td>
    </tr>
    <?php } ?>
</table>

<?php include("../includes/footer.php"); ?>