<?php
include 'includes/header.php';
require_permission('slider_view');
?>
<div class="row mb-4">
<div class="col">
<h3 class="fs-4 mb-3">إدارة السلايدر</h3>
</div>
<div class="col text-start">
<a href="slider_form.php" class="btn btn-success"><i class="fas fa-plus"></i> إضافة شريحة جديدة</a>
</div>
</div>
<div class="row">
<div class="col">
<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>
<th scope="col">العنوان الفرعي</th>
<th scope="col">السيارة المرتبطة</th>
<th scope="col">الحالة</th>
<th scope="col">الإجراءات</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT s.*, c.name as car_name, c.brand as car_brand, c.model as car_model
FROM slider s
LEFT JOIN cars c ON s.car_id = c.id
ORDER BY s.id DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$image_path = '../uploads/slider/' . htmlspecialchars($row["image_path"]);
$status = $row['active'] ? '<span class="badge bg-success">فعال</span>' : '<span class="badge bg-secondary">غير فعال</span>';
$linked_car = "---";
if (!empty($row['car_id'])) {
$linked_car = htmlspecialchars(trim(($row['car_brand'] ?? '') . ' ' . $row['car_name'] . ' ' . ($row['car_model'] ?? '')));
}
echo "<tr>";
echo "<th scope='row'>" . $row["id"] . "</th>";
echo "<td><img src='" . $image_path . "' width='150' class='rounded'></td>";
echo "<td>" . htmlspecialchars($row["title"]) . "</td>";
echo "<td>" . htmlspecialchars($row["subtitle"]) . "</td>";
echo "<td>" . $linked_car . "</td>";
echo "<td>" . $status . "</td>";
echo "<td>
<a href='slider_form.php?id=" . $row["id"] . "' class='btn btn-primary btn-sm'><i class='fas fa-edit'></i></a>
<a href='slider_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='7' class='text-center'>لا توجد شرائح مضافة حالياً.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>