<?php
include 'includes/header.php';
if (!has_permission('themes_view')) { // Assuming 'themes_view' is the permission to manage themes
echo "<div class='alert alert-danger'>ليس لديك الصلاحية للقيام بهذه العملية.</div>";
include 'includes/footer.php';
exit;
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Make sure the theme is not active before deleting
$stmt = $conn->prepare("SELECT `is_active` FROM `themes` WHERE `id` = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
$theme = $result->fetch_assoc();
if ($theme && $theme['is_active']) {
echo "<div class='alert alert-danger'>لا يمكن حذف الثيم النشط.</div>";
} else {
$stmt = $conn->prepare("DELETE FROM `themes` WHERE `id` = ?");
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
echo "<div class='alert alert-success'>تم حذف الثيم بنجاح.</div>";
} else {
echo "<div class='alert alert-danger'>حدث خطأ أثناء حذف الثيم.</div>";
}
}
echo '<a href="themes.php" class="btn btn-secondary">العودة إلى قائمة الثيمات</a>';
} else {
header('Location: themes.php');
}
include 'includes/footer.php';
?>