Файл: upload/pages/admin/nodes/edit-section.php
Строк: 116
<?php
require_once ($_SERVER['DOCUMENT_ROOT'] . '/core/core.php');
if ($users_perms['edit_sections'] != 1) {
RedirectToPage('/');
exit();
}
$id = abs((int)($_GET['id'] ?? 0));
$section = FetchAssoc(dbquery("SELECT * FROM `section` WHERE `id` = ?", [$id]));
if (empty($section['id'])) {
header("HTTP/1.0 404 Not Found");
include ($_SERVER['DOCUMENT_ROOT'] . '/pages/err_pages/404.php');
exit();
}
if (isset($_POST['set'])) {
check_csrf();
$section_name = chars($_POST['name']);
// === значение по умолчанию ===
if (empty($section['k_image'])) {
$image_name = 'non-image.png';
} else {
$image_name = $section['k_image'];
}
// === загрузка изображения ===
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$allowed = ['image/jpeg', 'image/png', 'image/gif'];
if (in_array($_FILES['image']['type'], $allowed)) {
$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
$image_name = uniqid("rz_", true) . "." . $ext;
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . "/uploads/sections/";
if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
move_uploaded_file($_FILES['image']['tmp_name'], $uploadDir . $image_name);
if ($section['k_image'] != 'non-image.png' && file_exists($uploadDir . $section['k_image'])) {
unlink($uploadDir . $section['k_image']);
}
}
}
// === запись в базу ===
dbquery("UPDATE `section` SET `name` = ?, `k_image` = ? WHERE `id` = ?", [$section_name, $image_name, $id]);
showAlert('Успешно', 'success', 'Изменения успешно сохранены!');
ReloadPage();
}
echo '<div class="home_us tematic">';
$breadcrumbs = generateBreadcrumbs([
['/', 'Главная'],
['/admin', 'Админ панель'],
['#', 'Редактирование раздела']
]);
$html = $breadcrumbs['html'];
$json_ld = $breadcrumbs['json_ld'];
echo $html;
echo '<script type="application/ld+json">' . $json_ld . '</script>';
echo '<div class="head_box section-header">
<div class="box_title">Редактирование раздела</div>
</div>';
echo '<div class="side_in_count">';
include ($_SERVER['DOCUMENT_ROOT'] . '/core/elements/sidebars/panel.php');
echo '<div class="box-back-pan">
<form action="" method="post" enctype="multipart/form-data">
<div class="punct_settings">
<div class="label-punct">Название</div>
<input type="hidden" name="csrf_token" value="' . $_SESSION['csrf_token'] . '">
<input type="text" name="name" placeholder="Название" value="' . $section['name'] . '" required />
</div>
<div class="punct_settings">
<div class="label-punct">Изображение</div>
<div class="upload-box-images" onclick="document.getElementById('fileInput').click()">
<img id="preview" src="' . homeLink() . '/uploads/sections/' . $section['k_image'] . '" onerror="this.src='' . homeLink() . '/core/templates/' . $theme . '/images/catalog/section/non-image.png'">
<div class="edit-image-icon"><i class="fas fa-edit"></i></div>
</div>
<input type="file" id="fileInput" name="image" accept="image/*">
</div>
<div class="punct_settings bot">
<div class="label-punct"></div>
<input type="submit" name="set" value="Сохранить" />
</div>
</form>
<script>
document.getElementById("fileInput").addEventListener("change", function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(event) {
document.getElementById("preview").src = event.target.result;
};
reader.readAsDataURL(file);
});
</script>
</div>';
echo '</div>';
echo '</div>';
$page_html = ob_get_clean();
require_once ($_SERVER['DOCUMENT_ROOT'] . '/layout.php');
?>