updating regestaration 2

This commit is contained in:
Flatlogic Bot 2026-03-24 03:30:29 +00:00
parent b587241984
commit e67be138ad
4 changed files with 233 additions and 292 deletions

View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/layout.php'; require_role('admin');
render_header('Truck Expiry Report', 'admin', true);
?>
<div class="row g-0">
<div class="col-md-2 bg-white border-end min-vh-100">
<?php render_admin_sidebar('truck_owners'); ?>
</div>
<div class="col-md-10 p-4">
<h1 class="section-title mb-4">Truck Expiry Report</h1>
<div class="panel p-4">
<table class="table table-bordered">
<thead>
<tr>
<th>Owner</th>
<th>Plate No</th>
<th>Registration Expiry</th>
<th>Insurance Expiry</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$trucks = db()->query("
SELECT t.*, u.full_name as owner_name
FROM trucks t
JOIN users u ON t.user_id = u.id
WHERE t.registration_expiry_date < DATE_ADD(NOW(), INTERVAL 30 DAY)
OR t.insurance_expiry_date < DATE_ADD(NOW(), INTERVAL 30 DAY)
")->fetchAll();
foreach ($trucks as $truck):
$regExpired = strtotime($truck['registration_expiry_date']) < time();
$insExpired = strtotime($truck['insurance_expiry_date']) < time();
$isExpired = $regExpired || $insExpired;
?>
<tr class="<?= $isExpired ? 'table-danger' : 'table-warning' ?>">
<td><?= e($truck['owner_name']) ?></td>
<td><?= e($truck['plate_no']) ?></td>
<td><?= e($truck['registration_expiry_date']) ?></td>
<td><?= e($truck['insurance_expiry_date']) ?></td>
<td><?= $isExpired ? 'Expired' : 'Near Expiry' ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php render_footer(); ?>

View File

@ -48,60 +48,68 @@ $countries = db()->query("SELECT id, name_en, name_ar FROM countries ORDER BY na
$cities = db()->query("SELECT id, country_id, name_en, name_ar FROM cities ORDER BY name_en ASC")->fetchAll();
if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
$fullName = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$countryId = (int)($_POST['country_id'] ?? 0);
$cityId = (int)($_POST['city_id'] ?? 0);
$addressLine = trim($_POST['address_line'] ?? '');
$status = trim($_POST['status'] ?? '');
$password = $_POST['password'] ?? '';
$bankAccount = trim($_POST['bank_account'] ?? '');
$bankName = trim($_POST['bank_name'] ?? '');
$bankBranch = trim($_POST['bank_branch'] ?? '');
$isCompany = isset($_POST['is_company']) ? 1 : 0;
if (isset($_POST['approve_truck'])) {
$truckId = (int)$_POST['truck_id'];
db()->prepare("UPDATE trucks SET is_approved = 1 WHERE id = ? AND user_id = ?")->execute([$truckId, $userId]);
$flash = 'Truck approved successfully.';
} elseif (isset($_POST['reject_truck'])) {
$truckId = (int)$_POST['truck_id'];
db()->prepare("UPDATE trucks SET is_approved = 0 WHERE id = ? AND user_id = ?")->execute([$truckId, $userId]);
$flash = 'Truck status set to unapproved.';
} else {
$fullName = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$countryId = (int)($_POST['country_id'] ?? 0);
$cityId = (int)($_POST['city_id'] ?? 0);
$addressLine = trim($_POST['address_line'] ?? '');
$status = trim($_POST['status'] ?? '');
$password = $_POST['password'] ?? '';
$bankAccount = trim($_POST['bank_account'] ?? '');
$bankName = trim($_POST['bank_name'] ?? '');
$bankBranch = trim($_POST['bank_branch'] ?? '');
$isCompany = isset($_POST['is_company']) ? 1 : 0;
if ($fullName === '') $errors[] = 'Full name is required.';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Valid email is required.';
if ($phone === '') $errors[] = 'Phone number is required.';
if (!in_array($status, ['pending', 'active', 'rejected'], true)) $errors[] = 'Invalid status.';
if ($countryId <= 0 || $cityId <= 0) {
$errors[] = 'Please select country and city.';
}
if ($fullName === '') $errors[] = 'Full name is required.';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Valid email is required.';
if ($phone === '') $errors[] = 'Phone number is required.';
if (!in_array($status, ['pending', 'active', 'rejected'], true)) $errors[] = 'Invalid status.';
if ($countryId <= 0 || $cityId <= 0) {
$errors[] = 'Please select country and city.';
}
if (!$errors) {
try {
db()->beginTransaction();
if (!$errors) {
try {
db()->beginTransaction();
$stmtUser = db()->prepare("UPDATE users SET full_name = ?, email = ?, status = ? WHERE id = ? AND role = 'truck_owner'");
$stmtUser->execute([$fullName, $email, $status, $userId]);
if ($password !== '') {
$stmtPass = db()->prepare("UPDATE users SET password = ? WHERE id = ? AND role = 'truck_owner'");
$stmtPass->execute([password_hash($password, PASSWORD_DEFAULT), $userId]);
$stmtUser = db()->prepare("UPDATE users SET full_name = ?, email = ?, status = ? WHERE id = ? AND role = 'truck_owner'");
$stmtUser->execute([$fullName, $email, $status, $userId]);
if ($password !== '') {
$stmtPass = db()->prepare("UPDATE users SET password = ? WHERE id = ? AND role = 'truck_owner'");
$stmtPass->execute([password_hash($password, PASSWORD_DEFAULT), $userId]);
}
$stmtProfile = db()->prepare("
UPDATE truck_owner_profiles
SET phone = ?, address_line = ?, country_id = ?, city_id = ?,
bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ?
WHERE user_id = ?
");
$stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $userId]);
db()->commit();
$flash = 'Truck Owner profile updated successfully.';
} catch (Throwable $e) {
db()->rollBack();
$errors[] = 'Failed to update truck owner profile. Please try again.';
}
$stmtProfile = db()->prepare("
UPDATE truck_owner_profiles
SET phone = ?, address_line = ?, country_id = ?, city_id = ?,
bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ?
WHERE user_id = ?
");
$stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $userId]);
db()->commit();
$flash = 'Truck Owner profile updated successfully.';
} catch (Throwable $e) {
db()->rollBack();
$errors[] = 'Failed to update truck owner profile. Please try again.';
}
}
}
$idCards = json_decode($owner['id_card_path'] ?? '[]', true) ?: [];
// -- OUTPUT START --
if (!$isAjax):
render_header('Edit Truck Owner', 'admin', true);
@ -207,16 +215,45 @@ if (!$isAjax):
<thead>
<tr>
<th>Truck Type</th>
<th>Load Capacity (T)</th>
<th>Capacity (T)</th>
<th>Plate No</th>
<th>Reg Expiry</th>
<th>Ins Expiry</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($ownerTrucks as $truck): ?>
<tr>
<?php
$isExpired = (strtotime($truck['registration_expiry_date'] ?? '1900-01-01') < time()) || (strtotime($truck['insurance_expiry_date'] ?? '1900-01-01') < time());
?>
<tr class="<?= $isExpired ? 'table-danger' : '' ?>">
<td><?= e($truck['truck_type']) ?></td>
<td><?= e($truck['load_capacity']) ?></td>
<td><?= e($truck['plate_no']) ?></td>
<td><?= e($truck['registration_expiry_date'] ?? 'N/A') ?></td>
<td><?= e($truck['insurance_expiry_date'] ?? 'N/A') ?></td>
<td>
<?php if ($isExpired): ?>
<span class="badge bg-danger">Expired/Disabled</span>
<?php elseif ($truck['is_approved']): ?>
<span class="badge bg-success">Approved</span>
<?php else: ?>
<span class="badge bg-warning text-dark">Pending</span>
<?php endif; ?>
</td>
<td>
<form method="post" action="admin_truck_owner_edit.php?id=<?= $userId ?>">
<?= csrf_field() ?>
<input type="hidden" name="truck_id" value="<?= e((string)$truck['id']) ?>">
<?php if ($truck['is_approved'] && !$isExpired): ?>
<button type="submit" name="reject_truck" class="btn btn-sm btn-outline-danger">Reject</button>
<?php elseif (!$isExpired): ?>
<button type="submit" name="approve_truck" class="btn btn-sm btn-outline-success">Approve</button>
<?php endif; ?>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -16,9 +16,6 @@ $values = [
'city_id' => '',
'address_line' => '',
'company_name' => '',
'truck_type' => '',
'load_capacity' => '',
'plate_no' => '',
'bank_account' => '',
'bank_name' => '',
'bank_branch' => '',
@ -48,9 +45,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
'city_id' => $cityId > 0 ? (string)$cityId : '',
'address_line' => $addressLine,
'company_name' => $companyName,
'truck_type' => trim($_POST['truck_type'] ?? ''),
'load_capacity' => trim($_POST['load_capacity'] ?? ''),
'plate_no' => trim($_POST['plate_no'] ?? ''),
'bank_account' => trim($_POST['bank_account'] ?? ''),
'bank_name' => trim($_POST['bank_name'] ?? ''),
'bank_branch' => trim($_POST['bank_branch'] ?? ''),
@ -107,16 +101,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
);
$shipperStmt->execute([$userId, $companyName, $phone, $countryId, $cityId, $addressLine]);
} else {
$truckType = trim($_POST['truck_type'] ?? '');
$loadCapacity = trim($_POST['load_capacity'] ?? '');
$plateNo = trim($_POST['plate_no'] ?? '');
if ($truckType === '' || $loadCapacity === '' || $plateNo === '') {
$errors[] = 'Please complete truck details.';
} elseif (!is_numeric($loadCapacity) || (float)$loadCapacity <= 0) {
$errors[] = 'Load capacity must be numeric and greater than zero.';
}
$uploadDir = __DIR__ . '/uploads/profiles/' . $userId . '/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0775, true);
@ -150,25 +134,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
if ($path) $idCardPaths[] = $path;
}
$regPaths = [];
if (is_uploaded_file($_FILES['truck_reg_front']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['truck_reg_front']['tmp_name'], (int)$_FILES['truck_reg_front']['size'], 'reg_front_');
if ($path) $regPaths[] = $path;
}
if (is_uploaded_file($_FILES['truck_reg_back']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['truck_reg_back']['tmp_name'], (int)$_FILES['truck_reg_back']['size'], 'reg_back_');
if ($path) $regPaths[] = $path;
}
$truckPic = null;
$truckTmp = $_FILES['truck_picture']['tmp_name'] ?? '';
if (is_uploaded_file($truckTmp)) {
$truckSize = (int)($_FILES['truck_picture']['size'] ?? 0);
$truckPic = $saveImage($truckTmp, $truckSize, 'truck_');
}
if (count($idCardPaths) < 2 || count($regPaths) < 2 || !$truckPic) {
$errors[] = 'Please upload all required truck-owner images (ID front/back, registration front/back, truck photo).';
if (count($idCardPaths) < 2) {
$errors[] = 'Please upload ID front and back.';
}
if (!$errors) {
@ -188,19 +155,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
json_encode($idCardPaths, JSON_UNESCAPED_SLASHES),
$values['is_company']
]);
$truckStmt = $pdo->prepare(
"INSERT INTO trucks (user_id, truck_type, load_capacity, plate_no, truck_pic_path, registration_path)
VALUES (?, ?, ?, ?, ?, ?)"
);
$truckStmt->execute([
$userId,
$truckType,
$loadCapacity,
$plateNo,
$truckPic,
json_encode($regPaths, JSON_UNESCAPED_SLASHES)
]);
}
}
@ -319,7 +273,7 @@ render_header('Shipper & Truck Owner Registration');
</div>
<div id="truckFields" class="mt-4" style="display:none;">
<h2 class="h5 mb-3"><?= e(t('truck_details')) ?></h2>
<h2 class="h5 mb-3"><?= e(t('owner_details')) ?></h2>
<div class="row g-3">
<div class="col-md-12 mb-3">
<div class="form-check">
@ -327,28 +281,16 @@ render_header('Shipper & Truck Owner Registration');
<label class="form-check-label" for="is_company"><?= e(t('is_company_checkbox')) ?></label>
</div>
</div>
<div class="col-md-4">
<label class="form-label" for="truck_type"><?= e(t('truck_type')) ?></label>
<input type="text" name="truck_type" id="truck_type" class="form-control" value="<?= e($values['truck_type']) ?>">
</div>
<div class="col-md-4">
<label class="form-label" for="load_capacity"><?= e(t('load_capacity')) ?></label>
<input type="number" name="load_capacity" id="load_capacity" class="form-control" step="0.01" min="0.1" value="<?= e($values['load_capacity']) ?>">
</div>
<div class="col-md-4">
<label class="form-label" for="plate_no"><?= e(t('plate_no')) ?></label>
<input type="text" name="plate_no" id="plate_no" class="form-control" value="<?= e($values['plate_no']) ?>">
</div>
<div class="col-md-4 mt-3">
<div class="col-md-4">
<label class="form-label" for="bank_account"><?= e(t('bank_account')) ?></label>
<input type="text" name="bank_account" id="bank_account" class="form-control" value="<?= e($values['bank_account']) ?>">
</div>
<div class="col-md-4 mt-3">
<div class="col-md-4">
<label class="form-label" for="bank_name"><?= e(t('bank_name')) ?></label>
<input type="text" name="bank_name" id="bank_name" class="form-control" value="<?= e($values['bank_name']) ?>">
</div>
<div class="col-md-4 mt-3">
<div class="col-md-4">
<label class="form-label" for="bank_branch"><?= e(t('bank_branch')) ?></label>
<input type="text" name="bank_branch" id="bank_branch" class="form-control" value="<?= e($values['bank_branch']) ?>">
</div>
@ -361,18 +303,6 @@ render_header('Shipper & Truck Owner Registration');
<label class="form-label" for="id_card_back"><?= e(t('id_card_back')) ?></label>
<input type="file" name="id_card_back" id="id_card_back" class="form-control" accept="image/png,image/jpeg,image/webp">
</div>
<div class="col-md-6 mt-3">
<label class="form-label" for="truck_reg_front"><?= e(t('truck_reg_front')) ?></label>
<input type="file" name="truck_reg_front" id="truck_reg_front" class="form-control" accept="image/png,image/jpeg,image/webp">
</div>
<div class="col-md-6 mt-3">
<label class="form-label" for="truck_reg_back"><?= e(t('truck_reg_back')) ?></label>
<input type="file" name="truck_reg_back" id="truck_reg_back" class="form-control" accept="image/png,image/jpeg,image/webp">
</div>
<div class="col-md-12 mt-3">
<label class="form-label" for="truck_picture"><?= e(t('truck_picture')) ?></label>
<input type="file" name="truck_picture" id="truck_picture" class="form-control" accept="image/png,image/jpeg,image/webp">
</div>
</div>
</div>
@ -422,4 +352,4 @@ syncCities();
toggleFields();
</script>
<?php render_footer(); ?>
<?php render_footer(); ?>

View File

@ -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();
?>
<div class="page-intro mb-4">
<h1 class="section-title mb-1"><?= e(t('owner_dashboard')) ?></h1>
<p class="muted mb-0"><?= e(t('welcome_back_owner') ?? 'Find loads and submit your best rate.') ?></p>
<h1 class="section-title mb-1">Truck Owner Dashboard</h1>
<p class="muted mb-0">Manage your trucks and view their approval status.</p>
</div>
<!-- Stats Row -->
<div class="row g-3 mb-4">
<div class="col-md-4">
<div class="panel p-4 text-center h-100 shadow-sm border-0 rounded-4 position-relative overflow-hidden" style="background: linear-gradient(135deg, #ffffff, #f8f9fa);">
<div class="position-absolute opacity-10" style="inset-inline-end: 10px; top: 15px;"><i class="bi bi-search" style="font-size: 3.5rem;"></i></div>
<div class="text-primary mb-2 position-relative"><i class="bi bi-search fs-2"></i></div>
<h3 class="h2 mb-0 fw-bold position-relative"><?= $stats['available'] ?></h3>
<p class="text-muted small text-uppercase mb-0 fw-bold position-relative" style="letter-spacing: 0.5px;"><?= e(t('available_shipments')) ?></p>
<?php if ($flash): ?>
<div class="alert alert-<?= $flash['type'] ?>" data-auto-dismiss="true"><?= e($flash['message']) ?></div>
<?php endif; ?>
<div class="panel p-4 mb-4">
<h5 class="mb-3">Add New Truck</h5>
<form method="post" class="row g-3"> <?= csrf_field() ?>
<input type="hidden" name="action" value="add_truck">
<div class="col-md-2">
<input type="text" name="truck_type" class="form-control" placeholder="Truck Type" required>
</div>
</div>
<div class="col-md-4">
<div class="panel p-4 text-center h-100 shadow-sm border-0 rounded-4 position-relative overflow-hidden" style="background: linear-gradient(135deg, #ffffff, #f8f9fa);">
<div class="position-absolute opacity-10" style="inset-inline-end: 10px; top: 15px;"><i class="bi bi-tags" style="font-size: 3.5rem;"></i></div>
<div class="text-info mb-2 position-relative"><i class="bi bi-tags fs-2"></i></div>
<h3 class="h2 mb-0 fw-bold position-relative"><?= $stats['my_offers'] ?></h3>
<p class="text-muted small text-uppercase mb-0 fw-bold position-relative" style="letter-spacing: 0.5px;"><?= e(t('total_offers')) ?></p>
<div class="col-md-2">
<input type="number" name="load_capacity" class="form-control" placeholder="Capacity (T)" step="0.01" required>
</div>
</div>
<div class="col-md-4">
<div class="panel p-4 text-center h-100 shadow-sm border-0 rounded-4 position-relative overflow-hidden" style="background: linear-gradient(135deg, #ffffff, #f8f9fa);">
<div class="position-absolute opacity-10" style="inset-inline-end: 10px; top: 15px;"><i class="bi bi-trophy" style="font-size: 3.5rem;"></i></div>
<div class="text-success mb-2 position-relative"><i class="bi bi-trophy fs-2"></i></div>
<h3 class="h2 mb-0 fw-bold position-relative"><?= $stats['won'] ?></h3>
<p class="text-muted small text-uppercase mb-0 fw-bold position-relative" style="letter-spacing: 0.5px;"><?= e(t('won_shipments')) ?></p>
<div class="col-md-2">
<input type="text" name="plate_no" class="form-control" placeholder="Plate No" required>
</div>
</div>
<div class="col-md-2">
<input type="date" name="registration_expiry_date" class="form-control" required title="Registration Expiry Date">
</div>
<div class="col-md-2">
<input type="date" name="insurance_expiry_date" class="form-control" required title="Insurance Expiry Date">
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">Add Truck</button>
</div>
</form>
</div>
<div class="panel p-4 shadow-sm border-0 rounded-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="h5 mb-0 fw-bold"><i class="bi bi-truck text-muted me-2"></i><?= e(t('available_shipments')) ?></h2>
<span class="badge bg-light text-dark border"><?= e(count($shipments)) ?> <?= e(t('total_label') ?? 'total') ?></span>
</div>
<?php if ($flash): ?>
<div class="alert alert-success" data-auto-dismiss="true"><?= e($flash['message']) ?></div>
<?php endif; ?>
<?php if ($errors): ?>
<div class="alert alert-warning"><?= e(implode(' ', $errors)) ?></div>
<?php endif; ?>
<?php if (!$shipments): ?>
<div class="text-center p-5 text-muted flex-grow-1 d-flex flex-column justify-content-center">
<i class="bi bi-inbox fs-1 mb-3 d-block opacity-50"></i>
<p class="mb-0"><?= e(t('no_shipments')) ?></p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead>
<tr>
<th class="text-uppercase small text-muted border-top-0"><?= e(t('shipper_company')) ?></th>
<th class="text-uppercase small text-muted border-top-0"><?= e(t('route_label') ?? 'Route') ?></th>
<th class="text-uppercase small text-muted border-top-0"><?= e(t('cargo')) ?></th>
<th class="text-uppercase small text-muted border-top-0"><?= e(t('offer')) ?></th>
<th class="text-uppercase small text-muted border-top-0 text-end"><?= e(t('actions')) ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($shipments as $row): ?>
<tr>
<td>
<div class="fw-bold"><?= e($row['shipper_company']) ?></div>
<small class="text-muted"><?= e(date('M d', strtotime($row['pickup_date']))) ?></small>
</td>
<td>
<div class="d-flex align-items-center gap-2">
<span class="fw-medium"><?= e($row['origin_city']) ?></span>
<i class="bi bi-arrow-right text-muted small"></i>
<span class="fw-medium"><?= e($row['destination_city']) ?></span>
</div>
</td>
<td>
<div><?= e($row['weight_tons']) ?> Ton(s)</div>
<small class="text-muted text-truncate d-inline-block" style="max-width: 150px;"><?= e($row['cargo_description']) ?></small>
</td>
<td>
<?php if ($row['offer_price']): ?>
<div class="fw-bold text-success">$<?= e($row['offer_price']) ?></div>
<small class="text-muted"><?= e($row['offer_owner']) ?></small>
<?php else: ?>
<span class="badge bg-light text-dark border"><?= e(t('no_offers')) ?></span>
<?php endif; ?>
</td>
<td class="text-end">
<form class="d-flex align-items-center justify-content-end gap-2" method="post">
<input type="hidden" name="action" value="submit_offer">
<input type="hidden" name="shipment_id" value="<?= e($row['id']) ?>">
<input class="form-control form-control-sm border-secondary shadow-none" style="width: 120px;" name="offer_owner" placeholder="<?= e(t('offer_owner')) ?>" value="<?= e($ownerName) ?>" required>
<div class="input-group input-group-sm" style="width: 110px;">
<span class="input-group-text">$</span>
<input class="form-control border-secondary shadow-none" name="offer_price" type="number" step="0.01" min="0.1" placeholder="<?= e(t('offer_price')) ?>" required>
</div>
<button class="btn btn-sm p-1 border-0 bg-transparent text-primary" type="submit" title="Submit Offer"><i class="bi bi-send-fill"></i></button>
<a class="btn btn-sm p-1 border-0 bg-transparent text-primary ms-1" href="<?= e(url_with_lang('shipment_detail.php', ['id' => $row['id']])) ?>" title="<?= e(t('view')) ?>">
<i class="bi bi-eye"></i>
</a>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<div class="panel p-4">
<h5 class="mb-3">My Trucks</h5>
<table class="table table-bordered">
<thead>
<tr>
<th>Truck Type</th>
<th>Capacity (T)</th>
<th>Plate No</th>
<th>Reg Expiry</th>
<th>Ins Expiry</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($myTrucks as $truck): ?>
<?php
$isExpired = (strtotime($truck['registration_expiry_date']) < time()) || (strtotime($truck['insurance_expiry_date']) < time());
?>
<tr class="<?= $isExpired ? 'table-danger' : '' ?>">
<td><?= e($truck['truck_type']) ?></td>
<td><?= e($truck['load_capacity']) ?></td>
<td><?= e($truck['plate_no']) ?></td>
<td><?= e($truck['registration_expiry_date']) ?></td>
<td><?= e($truck['insurance_expiry_date']) ?></td>
<td>
<?php if ($isExpired): ?>
<span class="badge bg-danger">Expired</span>
<?php elseif ($truck['is_approved']): ?>
<span class="badge bg-success">Approved</span>
<?php else: ?>
<span class="badge bg-warning text-dark">Pending</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php render_footer(); ?>