diff --git a/admin_dashboard.php b/admin_dashboard.php index 52684bb..804c894 100644 --- a/admin_dashboard.php +++ b/admin_dashboard.php @@ -7,21 +7,7 @@ ensure_schema(); $errors = []; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'update_status') { - $shipmentId = (int) ($_POST['shipment_id'] ?? 0); - $status = $_POST['status'] ?? 'posted'; - - $allowed = ['posted', 'offered', 'confirmed', 'in_transit', 'delivered']; - if ($shipmentId <= 0 || !in_array($status, $allowed, true)) { - $errors[] = t('error_invalid'); - } else { - $stmt = db()->prepare("UPDATE shipments SET status = :status WHERE id = :id"); - $stmt->execute([':status' => $status, ':id' => $shipmentId]); - set_flash('success', t('success_status')); - header('Location: ' . url_with_lang('admin_dashboard.php')); - exit; - } -} +// Removed inline status update logic as per UI cleanup $shipments = []; try { @@ -142,18 +128,9 @@ render_header(t('admin_dashboard'), 'admin'); -
- - - - -
+ + View Details + diff --git a/admin_shipment_edit.php b/admin_shipment_edit.php index 77ff653..b18d7f0 100644 --- a/admin_shipment_edit.php +++ b/admin_shipment_edit.php @@ -19,9 +19,44 @@ if (!$shipment) { header('Location: admin_shipments.php'); exit; } +// Fetch all countries for dropdowns +$countries = []; +try { + $countries = db()->query("SELECT * FROM countries ORDER BY name_en ASC")->fetchAll(); +} catch (Throwable $e) {} + +// Helper to find country_id by city name +function find_country_id_by_city_name($cityName) { + if (!$cityName) return null; + $stmt = db()->prepare("SELECT country_id FROM cities WHERE name_en = ? LIMIT 1"); + $stmt->execute([$cityName]); + return $stmt->fetchColumn() ?: null; +} + +// Pre-fetch country IDs for existing cities +$origin_country_id = find_country_id_by_city_name($shipment['origin_city']); +$destination_country_id = find_country_id_by_city_name($shipment['destination_city']); + +// Fetch initial city lists for the pre-selected countries +$origin_cities_list = []; +if ($origin_country_id) { + $stmt = db()->prepare("SELECT * FROM cities WHERE country_id = ? ORDER BY name_en ASC"); + $stmt->execute([$origin_country_id]); + $origin_cities_list = $stmt->fetchAll(); +} + +$destination_cities_list = []; +if ($destination_country_id) { + $stmt = db()->prepare("SELECT * FROM cities WHERE country_id = ? ORDER BY name_en ASC"); + $stmt->execute([$destination_country_id]); + $destination_cities_list = $stmt->fetchAll(); +} + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $shipper_name = trim($_POST['shipper_name'] ?? ''); $shipper_company = trim($_POST['shipper_company'] ?? ''); + // These are now selected from dropdowns, but the value is still the city name $origin_city = trim($_POST['origin_city'] ?? ''); $destination_city = trim($_POST['destination_city'] ?? ''); $cargo_description = trim($_POST['cargo_description'] ?? ''); @@ -50,9 +85,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ]); $flash = "Shipment updated successfully."; - // Refresh + // Refresh data $stmt->execute([$id]); $shipment = $stmt->fetch(); + + // Re-fetch derived data for the form + $origin_country_id = find_country_id_by_city_name($shipment['origin_city']); + $destination_country_id = find_country_id_by_city_name($shipment['destination_city']); + + $origin_cities_list = []; + if ($origin_country_id) { + $stmt = db()->prepare("SELECT * FROM cities WHERE country_id = ? ORDER BY name_en ASC"); + $stmt->execute([$origin_country_id]); + $origin_cities_list = $stmt->fetchAll(); + } + + $destination_cities_list = []; + if ($destination_country_id) { + $stmt = db()->prepare("SELECT * FROM cities WHERE country_id = ? ORDER BY name_en ASC"); + $stmt->execute([$destination_country_id]); + $destination_cities_list = $stmt->fetchAll(); + } } } @@ -102,13 +155,62 @@ render_header('Edit Shipment', 'admin'); + +
+ + +
- + +
+ + +
+ +
- +
@@ -156,4 +258,44 @@ render_header('Edit Shipment', 'admin');
- + + + \ No newline at end of file