diff --git a/admin.php b/admin.php index 37c93c1..57f6cd6 100644 --- a/admin.php +++ b/admin.php @@ -45,6 +45,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!sectionById($sectionId)) throw new RuntimeException('Раздел не найден'); sectionUpdate($sectionId, $name, $sort); $message = 'Раздел обновлён'; + if ($isAjax) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['ok' => true, 'message' => $message], JSON_UNESCAPED_UNICODE); + exit; + } } if ($action === 'delete_section') { @@ -52,6 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($sectionId < 1) throw new RuntimeException('Некорректный раздел'); if (!sectionById($sectionId)) throw new RuntimeException('Раздел не найден'); + removeSectionImageFiles($sectionId); sectionDelete($sectionId); deleteSectionStorage($sectionId); $message = 'Раздел удалён'; @@ -173,9 +179,12 @@ $photos = $activeSectionId > 0 ? photosBySection($activeSectionId) : []; $commenters = commentersAll(); $latestComments = commentsLatest(80); $welcomeText = settingGet('welcome_text', 'Добро пожаловать в галерею. Выберите раздел слева, чтобы посмотреть фотографии.'); -$adminMode = (string)($_GET['mode'] ?? 'media'); -if (!in_array($adminMode, ['media', 'comments', 'welcome'], true)) { - $adminMode = 'media'; +$adminMode = (string)($_GET['mode'] ?? 'photos'); +if ($adminMode === 'media') { + $adminMode = 'photos'; +} +if (!in_array($adminMode, ['sections', 'photos', 'comments', 'welcome'], true)) { + $adminMode = 'photos'; } function h(string $v): string { return htmlspecialchars($v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } @@ -300,6 +309,30 @@ function deleteDirRecursive(string $dir): void @rmdir($dir); } +function removeSectionImageFiles(int $sectionId): void +{ + $st = db()->prepare('SELECT pf.file_path + FROM photo_files pf + JOIN photos p ON p.id = pf.photo_id + WHERE p.section_id = :sid'); + $st->execute(['sid' => $sectionId]); + $paths = $st->fetchAll(PDO::FETCH_COLUMN); + if (!is_array($paths)) { + return; + } + + foreach ($paths as $path) { + if (!is_string($path) || $path === '') { + continue; + } + + $abs = __DIR__ . '/' . ltrim($path, '/'); + if (is_file($abs)) { + @unlink($abs); + } + } +} + function nextSortOrderForSection(int $sectionId): int { $st = db()->prepare('SELECT COALESCE(MAX(sort_order),0)+10 FROM photos WHERE section_id=:sid'); @@ -341,43 +374,25 @@ function nextUniqueCodeName(string $base): string

Меню

- Разделы и фото + Разделы + Фото Приветственное сообщение Комментаторы и комментарии
- +
-

Разделы

+

- () + ()
- -
-

Редактировать выбранный

-
- -

-

- -
-
- - -
+ +
Создай раздел во вкладке "Разделы", чтобы загружать фото.
- -
-
- -

-

- -
@@ -407,11 +422,42 @@ function nextUniqueCodeName(string $base): string - + +
+

Редактировать выбранный раздел

+ +
+ +

+

+
Сохраняется автоматически при выходе из поля.
+
+
+ + +
+ +

Нет разделов для редактирования.

+ +
+ +
+

Создать раздел

+
+ +

+

+ +
+
+ + + +

Загрузка фото “до” в выбранный раздел

0): ?> -
+

@@ -431,7 +477,7 @@ function nextUniqueCodeName(string $base): string - +

@@ -441,7 +487,7 @@ function nextUniqueCodeName(string $base): string
-
+
@@ -507,9 +553,8 @@ function nextUniqueCodeName(string $base): string