@@ -327,28 +281,16 @@ render_header('Shipper & Truck Owner Registration');
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
@@ -422,4 +352,4 @@ syncCities();
toggleFields();
-
+
\ No newline at end of file
diff --git a/truck_owner_dashboard.php b/truck_owner_dashboard.php
index deaaeea..8e492c6 100644
--- a/truck_owner_dashboard.php
+++ b/truck_owner_dashboard.php
@@ -3,189 +3,107 @@ declare(strict_types=1);
require_once __DIR__ . '/includes/layout.php'; require_role('truck_owner');
-ensure_schema();
+$userId = $_SESSION['user_id'];
-$errors = [];
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_truck') {
+ $truckType = trim($_POST['truck_type'] ?? '');
+ $loadCapacity = trim($_POST['load_capacity'] ?? '');
+ $plateNo = trim($_POST['plate_no'] ?? '');
+ $regExpiry = trim($_POST['registration_expiry_date'] ?? '');
+ $insExpiry = trim($_POST['insurance_expiry_date'] ?? '');
-// Try to prefill owner name from profile if logged in
-$prefillOwnerName = '';
-if (isset($_SESSION['user_id'])) {
- try {
- $stmt = db()->prepare("SELECT full_name FROM users WHERE id = ?");
- $stmt->execute([$_SESSION['user_id']]);
- $prefillOwnerName = $stmt->fetchColumn() ?: '';
- } catch (Throwable $e) {}
+ if ($truckType === '' || $loadCapacity === '' || $plateNo === '' || $regExpiry === '' || $insExpiry === '') {
+ set_flash('error', 'All truck details including expiry dates are required.');
+ } elseif (!is_numeric($loadCapacity) || (float)$loadCapacity <= 0) {
+ set_flash('error', 'Load capacity must be numeric and greater than zero.');
+ } else {
+ $stmt = db()->prepare("INSERT INTO trucks (user_id, truck_type, load_capacity, plate_no, registration_expiry_date, insurance_expiry_date, is_approved) VALUES (?, ?, ?, ?, ?, ?, 0)");
+ $stmt->execute([$userId, $truckType, $loadCapacity, $plateNo, $regExpiry, $insExpiry]);
+ set_flash('success', 'Truck added successfully, pending admin approval.');
+ }
+ header('Location: ' . url_with_lang('truck_owner_dashboard.php'));
+ exit;
}
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'submit_offer') {
- $shipmentId = (int) ($_POST['shipment_id'] ?? 0);
- $offerOwner = trim($_POST['offer_owner'] ?? '');
- $offerPrice = trim($_POST['offer_price'] ?? '');
+$trucks = db()->prepare("SELECT * FROM trucks WHERE user_id = ?");
+$trucks->execute([$userId]);
+$myTrucks = $trucks->fetchAll();
- if ($shipmentId <= 0 || $offerOwner === '' || $offerPrice === '') {
- $errors[] = t('error_required');
- } elseif (!is_numeric($offerPrice)) {
- $errors[] = t('error_invalid');
- }
-
- if (!$errors) {
- $stmt = db()->prepare(
- "UPDATE shipments SET offer_owner = :offer_owner, offer_price = :offer_price, status = 'offered'
- WHERE id = :id AND status IN ('posted','offered')"
- );
- $stmt->execute([
- ':offer_owner' => $offerOwner,
- ':offer_price' => $offerPrice,
- ':id' => $shipmentId,
- ]);
- if ($stmt->rowCount() > 0) {
- $_SESSION['last_offer_owner'] = $offerOwner; // Save for next time
- set_flash('success', t('success_offer'));
- header('Location: ' . url_with_lang('truck_owner_dashboard.php'));
- exit;
- } else {
- $errors[] = t('error_invalid');
- }
- }
-}
-
-$ownerName = $_SESSION['last_offer_owner'] ?? $prefillOwnerName;
-
-$shipments = [];
-try {
- $stmt = db()->query("SELECT * FROM shipments WHERE status IN ('posted','offered') ORDER BY created_at DESC LIMIT 20");
- $shipments = $stmt->fetchAll();
-} catch (Throwable $e) {
- $shipments = [];
-}
-
-$stats = [
- 'available' => count($shipments),
- 'my_offers' => 0,
- 'won' => 0,
-];
-
-try {
- if ($ownerName) {
- $stats['my_offers'] = (int)db()->query("SELECT COUNT(*) FROM shipments WHERE offer_owner = " . db()->quote($ownerName))->fetchColumn();
- $stats['won'] = (int)db()->query("SELECT COUNT(*) FROM shipments WHERE offer_owner = " . db()->quote($ownerName) . " AND status IN ('confirmed','in_transit','delivered')")->fetchColumn();
- }
-} catch (Throwable $e) {}
-
-render_header(t('owner_dashboard'), 'owner');
+render_header('Truck Owner Dashboard', 'owner');
$flash = get_flash();
?>
-
= e(t('owner_dashboard')) ?>
-
= e(t('welcome_back_owner') ?? 'Find loads and submit your best rate.') ?>
+
Truck Owner Dashboard
+
Manage your trucks and view their approval status.
-
-
-
-
-
-
-
= $stats['available'] ?>
-
= e(t('available_shipments')) ?>
+
+
= e($flash['message']) ?>
+
+
+
-
-
-
-
-
= $stats['my_offers'] ?>
-
= e(t('total_offers')) ?>
+
+
-
-
-
-
-
-
= $stats['won'] ?>
-
= e(t('won_shipments')) ?>
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
-
= e(t('available_shipments')) ?>
- = e(count($shipments)) ?> = e(t('total_label') ?? 'total') ?>
-
-
-
-
= e($flash['message']) ?>
-
-
-
= e(implode(' ', $errors)) ?>
-
-
-
-
-
-
= e(t('no_shipments')) ?>
-
-
-
-
-
-
- | = e(t('shipper_company')) ?> |
- = e(t('route_label') ?? 'Route') ?> |
- = e(t('cargo')) ?> |
- = e(t('offer')) ?> |
- = e(t('actions')) ?> |
-
-
-
-
-
- |
- = e($row['shipper_company']) ?>
- = e(date('M d', strtotime($row['pickup_date']))) ?>
- |
-
-
- = e($row['origin_city']) ?>
-
- = e($row['destination_city']) ?>
-
- |
-
- = e($row['weight_tons']) ?> Ton(s)
- = e($row['cargo_description']) ?>
- |
-
-
- $= e($row['offer_price']) ?>
- = e($row['offer_owner']) ?>
-
- = e(t('no_offers')) ?>
-
- |
-
-
- |
-
-
-
-
-
-
+
+
My Trucks
+
+
+
+ | Truck Type |
+ Capacity (T) |
+ Plate No |
+ Reg Expiry |
+ Ins Expiry |
+ Status |
+
+
+
+
+
+
+ | = e($truck['truck_type']) ?> |
+ = e($truck['load_capacity']) ?> |
+ = e($truck['plate_no']) ?> |
+ = e($truck['registration_expiry_date']) ?> |
+ = e($truck['insurance_expiry_date']) ?> |
+
+
+ Expired
+
+ Approved
+
+ Pending
+
+ |
+
+
+
+
\ No newline at end of file