88 lines
3.4 KiB
PHP
88 lines
3.4 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) && empty($_SESSION['dealer_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
header('Location: service_requests.php');
|
|
exit;
|
|
}
|
|
|
|
$shipment_id = $_GET['id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM shipment_details WHERE id = ?");
|
|
$stmt->execute([$shipment_id]);
|
|
$shipment = $stmt->fetch();
|
|
|
|
if (!$shipment) {
|
|
header('Location: service_requests.php');
|
|
exit;
|
|
}
|
|
|
|
$service_request_id = $shipment['service_request_id'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$carrier = trim($_POST['carrier']);
|
|
$tracking_number = trim($_POST['tracking_number']);
|
|
$shipment_date = trim($_POST['shipment_date']);
|
|
|
|
if (empty($carrier) || empty($tracking_number) || empty($shipment_date)) {
|
|
$error_message = "All fields are required.";
|
|
} else {
|
|
$stmt_update = $pdo->prepare(
|
|
"UPDATE shipment_details SET carrier = ?, tracking_number = ?, shipment_date = ? WHERE id = ?"
|
|
);
|
|
$stmt_update->execute([$carrier, $tracking_number, $shipment_date, $shipment_id]);
|
|
|
|
header("Location: service_request_details.php?id=$service_request_id");
|
|
exit;
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
die("Database error: " . $e->getMessage());
|
|
}
|
|
?>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h1 class="h3 mb-0">Edit Shipment Details</h1>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (!empty($error_message)): ?>
|
|
<div class="alert alert-danger" role="alert">
|
|
<?php echo $error_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<form action="edit_shipment_details.php?id=<?php echo $shipment_id; ?>" method="POST">
|
|
<div class="mb-3">
|
|
<label for="carrier" class="form-label">Carrier</label>
|
|
<input type="text" class="form-control" id="carrier" name="carrier" value="<?php echo htmlspecialchars($shipment['carrier']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="tracking_number" class="form-label">Tracking Number</label>
|
|
<input type="text" class="form-control" id="tracking_number" name="tracking_number" value="<?php echo htmlspecialchars($shipment['tracking_number']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="shipment_date" class="form-label">Shipment Date</label>
|
|
<input type="date" class="form-control" id="shipment_date" name="shipment_date" value="<?php echo htmlspecialchars($shipment['shipment_date']); ?>" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Update Shipment</button>
|
|
<a href="service_request_details.php?id=<?php echo $service_request_id; ?>" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'includes/footer.php';
|
|
?>
|