diff --git a/admin.php b/admin.php index 72d67d3..f1a6570 100644 --- a/admin.php +++ b/admin.php @@ -134,6 +134,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } + if ($action === 'upload_after_file') { + $photoId = (int)($_POST['photo_id'] ?? 0); + if ($photoId < 1) throw new RuntimeException('Некорректный photo_id'); + if (!isset($_FILES['after'])) throw new RuntimeException('Файл не передан'); + + $photo = photoById($photoId); + if (!$photo) throw new RuntimeException('Фото не найдено'); + + $oldAfterPath = (string)($photo['after_path'] ?? ''); + $up = saveSingleImage($_FILES['after'], (string)$photo['code_name'] . 'р', (int)$photo['section_id']); + photoFileUpsert($photoId, 'after', $up['path'], $up['mime'], $up['size']); + + if ($oldAfterPath !== '' && $oldAfterPath !== $up['path']) { + $oldAbs = __DIR__ . '/' . ltrim($oldAfterPath, '/'); + if (is_file($oldAbs)) { + @unlink($oldAbs); + } + } + + $updatedPhoto = photoById($photoId); + $afterFileId = (int)($updatedPhoto['after_file_id'] ?? 0); + $previewUrl = $afterFileId > 0 ? ('index.php?action=image&file_id=' . $afterFileId . '&v=' . rawurlencode((string)time())) : ''; + + $message = 'Фото после обновлено'; + if ($isAjax) { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode([ + 'ok' => true, + 'message' => $message, + 'photo_id' => $photoId, + 'preview_url' => $previewUrl, + ], JSON_UNESCAPED_UNICODE); + exit; + } + } + if ($action === 'photo_delete') { $photoId = (int)($_POST['photo_id'] ?? 0); if ($photoId > 0) { @@ -558,8 +594,10 @@ function nextUniqueCodeName(string $base): string .sec a.active{background:#eef4ff;color:#1f6feb} .small{font-size:12px;color:#667085} .inline-form{margin:0} + .after-slot{display:flex;flex-direction:column;align-items:flex-start;gap:6px} .preview-actions{display:flex;gap:6px;margin-top:6px;flex-wrap:nowrap} .preview-actions form{margin:0} + .is-hidden{display:none} .row-actions{display:flex;flex-direction:column;align-items:flex-start;gap:8px} .modal{position:fixed;inset:0;z-index:90;display:flex;align-items:center;justify-content:center;padding:16px} .modal[hidden]{display:none} @@ -644,7 +682,7 @@ function nextUniqueCodeName(string $base): string
-