prepare("SELECT full_name FROM users WHERE id = ?"); $stmt->execute([$_SESSION['user_id']]); $prefillOwnerName = $stmt->fetchColumn() ?: ''; } catch (Throwable $e) {} } 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'] ?? ''); 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'); $flash = get_flash(); ?>
= e(t('welcome_back_owner') ?? 'Find loads and submit your best rate.') ?>
= e(t('available_shipments')) ?>
= e(t('total_offers')) ?>
= e(t('won_shipments')) ?>
= 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')) ?>
|