<?php
include 'auth.php';
require_permission('categories_view');
include 'includes/header.php';
?>
<div class="row mb-4">
<div class="col">
<h3 class="fs-4 mb-3">إدارة الفئات</h3>
</div>
<div class="col text-start">
<a href="category_form.php" class="btn btn-success"><i class="fas fa-plus"></i> إضافة فئة جديدة</a>
</div>
</div>
<div class="row">
<div class="col-md-8 mx-auto">
<div class="glass-card p-3">
<table class="table table-dark table-hover align-middle">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">اسم الفئة</th>
<th scope="col">الإجراءات</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM categories ORDER BY name ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<th scope='row'>" . $row["id"] . "</th>";
echo "<td>" . htmlspecialchars($row["name"]) . "</td>";
echo "<td>
<a href='category_form.php?id=" . $row["id"] . "' class='btn btn-primary btn-sm'><i class='fas fa-edit'></i></a>
<a href='category_delete.php?id=" . $row["id"] . "' class='btn btn-danger btn-sm' onclick='return confirm(\"هل أنت متأكد من حذف هذه الفئة؟\");'><i class='fas fa-trash'></i></a>
</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='3' class='text-center'>لا توجد فئات مضافة حالياً.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>