<?php
include "../db.php";

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$search = $_GET['search'] ?? "";

$limit = 10;
$start = ($page - 1) * $limit;

/* SEARCH CONDITION */

$where = "";

if($search != ""){
$search = $conn->real_escape_string($search);
$where = "WHERE menu_name LIKE '%$search%' OR menu_slug LIKE '%$search%'";
}

/* FETCH DATA */

$query = $conn->query("
SELECT * FROM menus
$where
ORDER BY id DESC
LIMIT $start,$limit
");

while($s = $query->fetch_assoc()){
?>

<tr>

<td><?php echo $s['id']; ?></td>

<td><?php echo htmlspecialchars($s['menu_name']); ?></td>

<td><?php echo htmlspecialchars($s['menu_slug']); ?></td>

<td>
<?php
if($s['status']==1){
echo "<span class='status-active'>Active</span>";
}else{
echo "<span class='status-off'>Disabled</span>";
}
?>
</td>

<td>

<a class="btn edit"
href="edit_station.php?id=<?php echo $s['id']; ?>">
Edit
</a>

<a class="btn delete"
href="manage_stations.php?delete=<?php echo $s['id']; ?>"
onclick="return confirm('Delete this station?')">
Delete
</a>

</td>

</tr>

<?php } ?>