prepare("SELECT * FROM " . DB_PREFIX . "orders WHERE id = ?"); $stmt->execute([$id]); $order = $stmt->fetch(); if (!$order) { die("Zamówienie nie istnieje."); } // 1. OBSŁUGA ZMIANY STATUSU ARCHIWUM if (isset($_POST['archive_action'])) { $new_archive_status = $order['is_archived'] ? 0 : 1; $update_arch = $pdo->prepare("UPDATE " . DB_PREFIX . "orders SET is_archived = ? WHERE id = ?"); $update_arch->execute([$new_archive_status, $id]); $action_msg = $new_archive_status ? "Przeniesiono do archiwum." : "Przywrócono z archiwum do aktualnych."; $hist_arch = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)"); $hist_arch->execute([$id, $_SESSION['user_id'], $action_msg]); // Wracamy na listę, uwzględniając czy lądujemy w archiwum czy nie $redirect_url = $new_archive_status ? "index.php?archive=1" : "index.php"; header("Location: $redirect_url"); exit(); } // 2. OBSŁUGA DODAWANIA KOMENTARZA if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['add_comment'])) { $comment_text = trim($_POST['comment_text'] ?? ''); if (!empty($comment_text)) { try { $ins_comm = $pdo->prepare("INSERT INTO " . DB_PREFIX . "order_comments (order_id, user_id, comment_text) VALUES (?, ?, ?)"); $ins_comm->execute([$id, $_SESSION['user_id'], $comment_text]); // Przeładowanie strony (PRG - Post/Redirect/Get), aby uniknąć ponownego wysłania przy odświeżaniu F5 header("Location: edit_order.php?id=" . $id); exit(); } catch (PDOException $e) { $message = "