36363-vm/place-order.php
Flatlogic Bot 38f186919c 1.0
2025-11-27 10:50:02 +00:00

154 lines
6.8 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$message = '';
$message_type = '';
// Create table if it doesn't exist
try {
$db = db();
$db->exec("CREATE TABLE IF NOT EXISTS orders (
id INT AUTO_INCREMENT PRIMARY KEY,
pickup_location VARCHAR(255) NOT NULL,
delivery_location VARCHAR(255) NOT NULL,
goods_description TEXT,
estimated_weight DECIMAL(10, 2),
status VARCHAR(50) DEFAULT 'PENDING',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);");
} catch (PDOException $e) {
// In a real app, log this error. For this prototype, we'll show it.
$message = 'Database setup failed: ' . $e->getMessage();
$message_type = 'danger';
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pickup_location = $_POST['pickup_location'] ?? '';
$delivery_location = $_POST['delivery_location'] ?? '';
$goods_description = $_POST['goods_description'] ?? '';
$estimated_weight = $_POST['estimated_weight'] ?? '';
if (empty($pickup_location) || empty($delivery_location) || empty($estimated_weight)) {
$message = 'Please fill in all required fields: Pickup Location, Delivery Location, and Estimated Weight.';
$message_type = 'warning';
} else {
try {
$sql = "INSERT INTO orders (pickup_location, delivery_location, goods_description, estimated_weight) VALUES (:pickup_location, :delivery_location, :goods_description, :estimated_weight)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':pickup_location', $pickup_location, PDO::PARAM_STR);
$stmt->bindParam(':delivery_location', $delivery_location, PDO::PARAM_STR);
$stmt->bindParam(':goods_description', $goods_description, PDO::PARAM_STR);
$stmt->bindParam(':estimated_weight', $estimated_weight, PDO::PARAM_STR);
if ($stmt->execute()) {
$message = 'Your order has been placed successfully! A transporter will be in touch soon.';
$message_type = 'success';
} else {
$message = 'There was an error placing your order. Please try again.';
$message_type = 'danger';
}
} catch (PDOException $e) {
$message = 'Database error: ' . $e->getMessage();
$message_type = 'danger';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Place an Order - LogPort</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #F8F9FA;
}
.navbar-brand {
font-weight: 700;
}
.form-card {
max-width: 700px;
margin: 40px auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="/">
<i class="bi bi-truck"></i> LogPort
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="/place-order.php">Ship Now</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Track Order</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container">
<div class="card form-card shadow-sm border-0">
<div class="card-body p-4 p-md-5">
<h1 class="h3 mb-4 text-center">Place a New Shipment Order</h1>
<?php if ($message): ?>
<div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
<?php echo htmlspecialchars($message); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php if ($message_type !== 'success'): ?>
<form action="place-order.php" method="POST">
<div class="mb-3">
<label for="pickup_location" class="form-label">Pickup Location</label>
<input type="text" class="form-control" id="pickup_location" name="pickup_location" placeholder="Enter full pickup address" required>
</div>
<div class="mb-3">
<label for="delivery_location" class="form-label">Delivery Location</label>
<input type="text" class="form-control" id="delivery_location" name="delivery_location" placeholder="Enter full delivery address" required>
</div>
<div class="mb-3">
<label for="goods_description" class="form-label">Goods Description</label>
<textarea class="form-control" id="goods_description" name="goods_description" rows="3" placeholder="e.g., 10 boxes of electronics, household items"></textarea>
</div>
<div class="mb-4">
<label for="estimated_weight" class="form-label">Estimated Weight (in kg)</label>
<input type="number" step="0.01" class="form-control" id="estimated_weight" name="estimated_weight" placeholder="e.g., 50.5" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Request Pickup</button>
</div>
</form>
<?php else: ?>
<div class="text-center">
<a href="/" class="btn btn-secondary">Back to Home</a>
</div>
<?php endif; ?>
</div>
</div>
</main>
<footer class="bg-white border-top text-center p-4 mt-5">
<p class="mb-0">&copy; <?php echo date("Y"); ?> LogPort. All Rights Reserved.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>