Файл: upload/pages/admin/theme/del-theme.php
Строк: 15
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/core.php';
if ($users_perms['edit_templates'] != 1) {
RedirectToPage('/');
exit();
}
$id = $_GET['id'] ?? null;
if (!$id) {
RedirectToPage('/admin/themes');
exit;
}
// Получаем тему
$theme = FetchAssoc(dbquery("SELECT * FROM themes WHERE id = ?", [$id]));
if (!$theme) {
showAlert('Ошибка', 'fail', 'Тема не найдена');
RedirectToPage('/admin/themes');
exit;
}
// Нельзя удалить тему по умолчанию
if ($id === 'default') {
showAlert('Ошибка', 'fail', 'Нельзя удалить тему по умолчанию');
RedirectToPage('/admin/themes');
exit;
}
// Путь к теме
$themePath = $_SERVER['DOCUMENT_ROOT'] . '/core/templates/' . $id;
// Рекурсивное удаление директории
function rrmdir($dir) {
if (!is_dir($dir)) return;
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object == "." || $object == "..") continue;
$path = $dir . "/" . $object;
if (is_dir($path)) {
rrmdir($path);
} else {
unlink($path);
}
}
rmdir($dir);
}
// Удаляем файлы темы
rrmdir($themePath);
dbquery("UPDATE themes SET is_active = 1 WHERE id = 'default'");
showAlert('Успешно', 'success', 'Тема успешно удалена');
RedirectToPage('/admin/themes');
exit;
?>