160 lines
7.4 KiB
PHP
160 lines
7.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
|
|
$errors = [];
|
|
$flash = null;
|
|
|
|
$id = (int)($_GET['id'] ?? 0);
|
|
if (!$id) {
|
|
header('Location: admin_shipments.php'); exit;
|
|
}
|
|
|
|
$stmt = db()->prepare("SELECT * FROM shipments WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$shipment = $stmt->fetch();
|
|
|
|
if (!$shipment) {
|
|
header('Location: admin_shipments.php'); exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$shipper_name = trim($_POST['shipper_name'] ?? '');
|
|
$shipper_company = trim($_POST['shipper_company'] ?? '');
|
|
$origin_city = trim($_POST['origin_city'] ?? '');
|
|
$destination_city = trim($_POST['destination_city'] ?? '');
|
|
$cargo_description = trim($_POST['cargo_description'] ?? '');
|
|
$weight_tons = (float)($_POST['weight_tons'] ?? 0);
|
|
$pickup_date = trim($_POST['pickup_date'] ?? '');
|
|
$delivery_date = trim($_POST['delivery_date'] ?? '');
|
|
$payment_method = trim($_POST['payment_method'] ?? 'thawani');
|
|
$status = trim($_POST['status'] ?? 'posted');
|
|
|
|
if ($shipper_name === '') $errors[] = "Shipper name is required.";
|
|
if ($origin_city === '') $errors[] = "Origin city is required.";
|
|
if ($destination_city === '') $errors[] = "Destination city is required.";
|
|
|
|
if (empty($errors)) {
|
|
$updateSql = "
|
|
UPDATE shipments
|
|
SET shipper_name = ?, shipper_company = ?, origin_city = ?, destination_city = ?,
|
|
cargo_description = ?, weight_tons = ?, pickup_date = ?, delivery_date = ?,
|
|
payment_method = ?, status = ?
|
|
WHERE id = ?
|
|
";
|
|
db()->prepare($updateSql)->execute([
|
|
$shipper_name, $shipper_company, $origin_city, $destination_city,
|
|
$cargo_description, $weight_tons, $pickup_date, $delivery_date,
|
|
$payment_method, $status, $id
|
|
]);
|
|
$flash = "Shipment updated successfully.";
|
|
|
|
// Refresh
|
|
$stmt->execute([$id]);
|
|
$shipment = $stmt->fetch();
|
|
}
|
|
}
|
|
|
|
render_header('Edit Shipment', 'admin');
|
|
?>
|
|
|
|
<div class="row g-4">
|
|
<div class="col-lg-3">
|
|
<?php render_admin_sidebar('shipments'); ?>
|
|
</div>
|
|
<div class="col-lg-9">
|
|
<div class="d-flex align-items-center gap-3 mb-4">
|
|
<a href="admin_shipments.php" class="btn btn-light border text-secondary" title="Back">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
|
|
<path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8z"/>
|
|
</svg>
|
|
</a>
|
|
<div>
|
|
<h1 class="section-title mb-1">Edit Shipment #<?= e((string)$shipment['id']) ?></h1>
|
|
<p class="muted mb-0">Update shipment details and status.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($flash): ?>
|
|
<div class="alert alert-success" data-auto-dismiss="true"><?= e($flash) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($errors): ?>
|
|
<div class="alert alert-danger">
|
|
<ul class="mb-0">
|
|
<?php foreach ($errors as $error): ?>
|
|
<li><?= e($error) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="panel p-4">
|
|
<form method="post">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label class="form-label">Shipper Name</label>
|
|
<input type="text" name="shipper_name" class="form-control" value="<?= e($shipment['shipper_name']) ?>" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Shipper Company</label>
|
|
<input type="text" name="shipper_company" class="form-control" value="<?= e((string)$shipment['shipper_company']) ?>">
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label">Origin City</label>
|
|
<input type="text" name="origin_city" class="form-control" value="<?= e($shipment['origin_city']) ?>" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Destination City</label>
|
|
<input type="text" name="destination_city" class="form-control" value="<?= e($shipment['destination_city']) ?>" required>
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
<label class="form-label">Cargo Description</label>
|
|
<input type="text" name="cargo_description" class="form-control" value="<?= e((string)$shipment['cargo_description']) ?>">
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<label class="form-label">Weight (Tons)</label>
|
|
<input type="number" step="0.1" name="weight_tons" class="form-control" value="<?= e((string)$shipment['weight_tons']) ?>">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">Pickup Date</label>
|
|
<input type="date" name="pickup_date" class="form-control" value="<?= e((string)$shipment['pickup_date']) ?>">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label">Delivery Date</label>
|
|
<input type="date" name="delivery_date" class="form-control" value="<?= e((string)$shipment['delivery_date']) ?>">
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<label class="form-label">Payment Method</label>
|
|
<select name="payment_method" class="form-select">
|
|
<option value="thawani" <?= $shipment['payment_method'] === 'thawani' ? 'selected' : '' ?>>Thawani</option>
|
|
<option value="bank_transfer" <?= $shipment['payment_method'] === 'bank_transfer' ? 'selected' : '' ?>>Bank Transfer</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label">Status</label>
|
|
<select name="status" class="form-select">
|
|
<option value="posted" <?= $shipment['status'] === 'posted' ? 'selected' : '' ?>>Posted</option>
|
|
<option value="offered" <?= $shipment['status'] === 'offered' ? 'selected' : '' ?>>Offered</option>
|
|
<option value="confirmed" <?= $shipment['status'] === 'confirmed' ? 'selected' : '' ?>>Confirmed</option>
|
|
<option value="in_transit" <?= $shipment['status'] === 'in_transit' ? 'selected' : '' ?>>In Transit</option>
|
|
<option value="delivered" <?= $shipment['status'] === 'delivered' ? 'selected' : '' ?>>Delivered</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4 pt-3 border-top d-flex justify-content-end">
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php render_footer(); ?>
|