Zamówienie dodane pomyślnie. Możesz dodać kolejne."; } if ($_SERVER["REQUEST_METHOD"] === "POST") { requireCsrfToken(); $product_name = trim($_POST['product_name'] ?? ''); $quantity = (int)($_POST['quantity'] ?? 0); $purchase_place = trim($_POST['purchase_place'] ?? ''); $price = (float)str_replace(',', '.', $_POST['price_per_unit'] ?? '0'); $delivery_date = $_POST['delivery_date'] ?? ''; $notes = trim($_POST['notes'] ?? ''); $recipient = trim($_POST['recipient'] ?? ''); $delivery_address = trim($_POST['delivery_address'] ?? ''); $company = trim($_POST['company'] ?? ''); $submit_action = $_POST['submit_action'] ?? 'save_and_list'; if ($product_name !== '' && $quantity > 0) { try { $pdo->beginTransaction(); $sql = "INSERT INTO " . DB_PREFIX . "orders (product_name, quantity, purchase_place, price_per_unit, delivery_date, notes, recipient, delivery_address, company, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'nowe')"; $stmt = $pdo->prepare($sql); $stmt->execute([$product_name, $quantity, $purchase_place, $price, $delivery_date, $notes, $recipient, $delivery_address, $company]); $order_id = $pdo->lastInsertId(); $hist_sql = "INSERT INTO " . DB_PREFIX . "order_history (order_id, user_id, action) VALUES (?, ?, ?)"; $hist_stmt = $pdo->prepare($hist_sql); $hist_stmt->execute([$order_id, $_SESSION['user_id'], 'Utworzono nowe zamówienie.']); $pdo->commit(); if ($submit_action === 'save_and_add_new') { header("Location: add_order.php?saved=1"); exit(); } header("Location: index.php"); exit(); } catch (PDOException $e) { $pdo->rollBack(); error_log($e->getMessage()); $message = "
Nie udało się zapisać zamówienia.
"; } } else { $message = "
Wypełnij nazwę produktu i podaj ilość większą od zera.
"; } } ?> Dodaj zamówienie - <?php echo e(APP_NAME); ?>
Nowe zamówienie
Powrót do listy