553 lines
30 KiB
PHP
553 lines
30 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/layout.php'; require_role('admin');
|
|
|
|
$userId = (int)($_GET['id'] ?? 0);
|
|
$isAjax = isset($_GET['ajax']) && $_GET['ajax'] === '1';
|
|
|
|
if ($userId <= 0) {
|
|
if ($isAjax) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => false, 'message' => 'Invalid ID']);
|
|
exit;
|
|
}
|
|
header('Location: admin_truck_owners.php');
|
|
exit;
|
|
}
|
|
|
|
$errors = [];
|
|
$flash = null;
|
|
|
|
// Fetch Truck Owner Profile
|
|
$stmt = db()->prepare("
|
|
SELECT u.id, u.email, u.full_name, u.status, u.role,
|
|
p.phone, p.address_line, p.country_id, p.city_id,
|
|
p.bank_account, p.bank_name, p.bank_branch,
|
|
p.id_card_path, p.truck_pic_path, p.registration_path,
|
|
p.is_company, p.ctr_number, p.notes
|
|
FROM users u
|
|
LEFT JOIN truck_owner_profiles p ON u.id = p.user_id
|
|
WHERE u.id = ? AND u.role = 'truck_owner'
|
|
");
|
|
$stmt->execute([$userId]);
|
|
$owner = $stmt->fetch();
|
|
|
|
$trucks = db()->prepare("SELECT * FROM trucks WHERE user_id = ?");
|
|
$trucks->execute([$userId]);
|
|
$ownerTrucks = $trucks->fetchAll();
|
|
|
|
if (!$owner) {
|
|
if ($isAjax) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['success' => false, 'message' => 'Owner not found']);
|
|
exit;
|
|
}
|
|
header('Location: admin_truck_owners.php');
|
|
exit;
|
|
}
|
|
|
|
$countries = db()->query("SELECT id, name_en, name_ar FROM countries ORDER BY name_en ASC")->fetchAll();
|
|
$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();
|
|
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.';
|
|
if ($isAjax) { echo json_encode(['success' => true, 'message' => $flash]); exit; }
|
|
} 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.';
|
|
if ($isAjax) { echo json_encode(['success' => true, 'message' => $flash]); exit; }
|
|
} elseif (isset($_POST['add_truck'])) {
|
|
$truckType = trim($_POST['truck_type'] ?? '');
|
|
$loadCapacity = (float)($_POST['load_capacity'] ?? 0);
|
|
$plateNo = trim($_POST['plate_no'] ?? '');
|
|
$regExpiry = $_POST['registration_expiry_date'] ?? null;
|
|
$insExpiry = $_POST['insurance_expiry_date'] ?? null;
|
|
|
|
if ($truckType === '') $errors[] = 'Truck type is required.';
|
|
if ($loadCapacity <= 0) $errors[] = 'Valid load capacity is required.';
|
|
if ($plateNo === '') $errors[] = 'Plate number is required.';
|
|
|
|
$truckPicPath = null;
|
|
$regPath = null;
|
|
|
|
if (empty($errors)) {
|
|
// Handle File Uploads
|
|
$uploadDir = 'uploads/trucks/';
|
|
if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
|
|
|
|
if (isset($_FILES['truck_pic']) && $_FILES['truck_pic']['error'] === UPLOAD_ERR_OK) {
|
|
$ext = pathinfo($_FILES['truck_pic']['name'], PATHINFO_EXTENSION);
|
|
$filename = 'truck_' . uniqid() . '.' . $ext;
|
|
if (move_uploaded_file($_FILES['truck_pic']['tmp_name'], $uploadDir . $filename)) {
|
|
$truckPicPath = $uploadDir . $filename;
|
|
}
|
|
}
|
|
if (isset($_FILES['registration_doc']) && $_FILES['registration_doc']['error'] === UPLOAD_ERR_OK) {
|
|
$ext = pathinfo($_FILES['registration_doc']['name'], PATHINFO_EXTENSION);
|
|
$filename = 'reg_' . uniqid() . '.' . $ext;
|
|
if (move_uploaded_file($_FILES['registration_doc']['tmp_name'], $uploadDir . $filename)) {
|
|
$regPath = $uploadDir . $filename;
|
|
}
|
|
}
|
|
|
|
try {
|
|
$stmt = db()->prepare("
|
|
INSERT INTO trucks (user_id, truck_type, load_capacity, plate_no, truck_pic_path, registration_path, registration_expiry_date, insurance_expiry_date, is_approved)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)
|
|
");
|
|
$stmt->execute([
|
|
$userId, $truckType, $loadCapacity, $plateNo, $truckPicPath, $regPath,
|
|
$regExpiry ?: null, $insExpiry ?: null
|
|
]);
|
|
$flash = 'Truck added successfully.';
|
|
if ($isAjax) { echo json_encode(['success' => true, 'message' => $flash]); exit; }
|
|
} catch (Throwable $e) {
|
|
$errors[] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
if (!empty($errors) && $isAjax) {
|
|
echo json_encode(['success' => false, 'message' => implode('. ', $errors)]); exit;
|
|
}
|
|
|
|
} 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;
|
|
$ctrNumber = trim($_POST['ctr_number'] ?? '');
|
|
$notes = trim($_POST['notes'] ?? '');
|
|
|
|
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();
|
|
|
|
$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 = ?,
|
|
ctr_number = ?, notes = ?
|
|
WHERE user_id = ?
|
|
");
|
|
$stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $ctrNumber, $notes, $userId]);
|
|
|
|
db()->commit();
|
|
$flash = 'Truck Owner profile updated successfully.';
|
|
|
|
if ($isAjax) {
|
|
echo json_encode(['success' => true, 'message' => $flash]);
|
|
exit;
|
|
}
|
|
} catch (Throwable $e) {
|
|
db()->rollBack();
|
|
$errors[] = 'Failed to update truck owner profile. Please try again.';
|
|
if ($isAjax) {
|
|
echo json_encode(['success' => false, 'message' => implode('. ', $errors)]);
|
|
exit;
|
|
}
|
|
}
|
|
} else {
|
|
if ($isAjax) {
|
|
echo json_encode(['success' => false, 'message' => implode('. ', $errors)]);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// -- OUTPUT START --
|
|
if (!$isAjax) {
|
|
render_header('Edit Truck Owner', 'admin', true);
|
|
echo '<div class="row g-0">
|
|
<div class="col-md-2 bg-white border-end min-vh-100">';
|
|
render_admin_sidebar('truck_owners');
|
|
echo ' </div>
|
|
<div class="col-md-10 p-4">';
|
|
}
|
|
?>
|
|
|
|
<?php if (!$isAjax): ?>
|
|
<div class="page-intro mb-4">
|
|
<a href="admin_truck_owners.php" class="text-decoration-none small text-muted mb-2 d-inline-block">← <?= e(t('back')) ?></a>
|
|
<h1 class="section-title mb-1"><?= e(t('edit_owner')) ?></h1>
|
|
</div>
|
|
<div class="panel p-4">
|
|
<?php else: ?>
|
|
<div class="modal-header">
|
|
<h5 class="modal-title"><?= e(t('edit_owner')) ?></h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<?php endif; ?>
|
|
|
|
<?php if ($flash): ?>
|
|
<div class="alert alert-success" data-auto-dismiss="true"><?= e($flash) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($errors): ?>
|
|
<div class="alert alert-warning"><?= e(implode('<br>', $errors)) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Hidden error container for JS -->
|
|
<div id="form-errors" class="alert alert-danger d-none"></div>
|
|
|
|
<ul class="nav nav-tabs mb-4" id="ownerEditTabs" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active" id="profile-tab" data-bs-toggle="tab" data-bs-target="#tab-profile" type="button" role="tab" aria-controls="tab-profile" aria-selected="true">
|
|
<?= e(t('profile') ?: 'Profile') ?>
|
|
</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="trucks-tab" data-bs-toggle="tab" data-bs-target="#tab-trucks" type="button" role="tab" aria-controls="tab-trucks" aria-selected="false">
|
|
<?= e(t('trucks') ?: 'Trucks') ?> <span class="badge bg-secondary rounded-pill ms-1"><?= count($ownerTrucks) ?></span>
|
|
</button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="docs-tab" data-bs-toggle="tab" data-bs-target="#tab-docs" type="button" role="tab" aria-controls="tab-docs" aria-selected="false">
|
|
<?= e(t('documents') ?: 'Documents') ?>
|
|
</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content" id="ownerEditTabsContent">
|
|
<!-- Tab 1: Profile -->
|
|
<div class="tab-pane fade show active" id="tab-profile" role="tabpanel" aria-labelledby="profile-tab">
|
|
<form method="post" action="admin_truck_owner_edit.php?id=<?= $userId ?><?= $isAjax ? '&ajax=1' : '' ?>" class="mb-3"> <?= csrf_field() ?>
|
|
<h5 class="mb-3"><?= e(t('full_name')) ?></h5>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="full_name"><?= e(t('full_name')) ?></label>
|
|
<input type="text" name="full_name" id="full_name" class="form-control" value="<?= e((string)$owner['full_name']) ?>" required>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="email"><?= e(t('email')) ?></label>
|
|
<input type="email" name="email" id="email" class="form-control" value="<?= e((string)$owner['email']) ?>" required>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="phone"><?= e(t('phone')) ?></label>
|
|
<input type="text" name="phone" id="phone" class="form-control" value="<?= e((string)$owner['phone']) ?>" required>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="password"><?= e(t('password')) ?> <small class="text-muted">(leave blank)</small></label>
|
|
<input type="password" name="password" id="password" class="form-control" autocomplete="new-password">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="status"><?= e(t('status')) ?></label>
|
|
<select name="status" id="status" class="form-select" required>
|
|
<option value="pending" <?= $owner['status'] === 'pending' ? 'selected' : '' ?>><?= e(t('pending')) ?></option>
|
|
<option value="active" <?= $owner['status'] === 'active' ? 'selected' : '' ?>><?= e(t('active')) ?></option>
|
|
<option value="rejected" <?= $owner['status'] === 'rejected' ? 'selected' : '' ?>><?= e(t('rejected')) ?></option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-6">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="is_company" id="is_company" value="1" <?= $owner['is_company'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="is_company"><?= e(t('is_company_checkbox')) ?></label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label" for="ctr_number"><?= e(t('ctr_number')) ?></label>
|
|
<input type="text" name="ctr_number" id="ctr_number" class="form-control" value="<?= e((string)($owner['ctr_number'] ?? '')) ?>">
|
|
</div>
|
|
<div class="col-md-12">
|
|
<label class="form-label" for="notes"><?= e(t('notes')) ?></label>
|
|
<textarea name="notes" id="notes" class="form-control"><?= e((string)($owner['notes'] ?? '')) ?></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<h5 class="mb-3"><?= e(t('location')) ?></h5>
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="country_id"><?= e(t('country')) ?></label>
|
|
<select name="country_id" id="country_id" class="form-select" onchange="syncCities()" required>
|
|
<option value=""><?= e(t('select_country')) ?></option>
|
|
<?php foreach ($countries as $country): ?>
|
|
<option value="<?= e((string)$country['id']) ?>" <?= (string)$owner['country_id'] === (string)$country['id'] ? 'selected' : '' ?>>
|
|
<?= e($lang === 'ar' && !empty($country['name_ar']) ? $country['name_ar'] : $country['name_en']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="city_id"><?= e(t('city')) ?></label>
|
|
<select name="city_id" id="city_id" class="form-select" required data-selected="<?= e((string)$owner['city_id']) ?>">
|
|
<option value=""><?= e(t('select_city')) ?></option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="address_line"><?= e(t('address')) ?></label>
|
|
<input type="text" name="address_line" id="address_line" class="form-control" value="<?= e((string)$owner['address_line']) ?>" required>
|
|
</div>
|
|
</div>
|
|
|
|
<h5 class="mb-3 border-top pt-3"><?= e(t('bank_account')) ?></h5>
|
|
<div class="row g-3 mb-4">
|
|
<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((string)($owner['bank_account'] ?? '')) ?>">
|
|
</div>
|
|
<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((string)($owner['bank_name'] ?? '')) ?>">
|
|
</div>
|
|
<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((string)($owner['bank_branch'] ?? '')) ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-end">
|
|
<button type="submit" class="btn btn-primary"><?= e(t('save_changes')) ?></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Tab 2: Trucks -->
|
|
<div class="tab-pane fade" id="tab-trucks" role="tabpanel" aria-labelledby="trucks-tab">
|
|
|
|
<div class="mb-3">
|
|
<button class="btn btn-outline-primary btn-sm" type="button" data-bs-toggle="collapse" data-bs-target="#addTruckForm" aria-expanded="false" aria-controls="addTruckForm">
|
|
<i class="bi bi-plus-lg"></i> <?= e(t('add_truck') ?: 'Add New Truck') ?>
|
|
</button>
|
|
</div>
|
|
<div class="collapse mb-4" id="addTruckForm">
|
|
<div class="card card-body bg-light border-0">
|
|
<h6 class="mb-3"><?= e(t('new_truck_details') ?: 'New Truck Details') ?></h6>
|
|
<form method="post" action="admin_truck_owner_edit.php?id=<?= $userId ?><?= $isAjax ? '&ajax=1' : '' ?>" enctype="multipart/form-data">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="add_truck" value="1">
|
|
<div class="row g-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label small"><?= e(t('truck_type') ?: 'Truck Type') ?></label>
|
|
<input type="text" name="truck_type" class="form-control form-control-sm" required placeholder="e.g. Flatbed">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label small"><?= e(t('load_capacity') ?: 'Capacity (Tons)') ?></label>
|
|
<input type="number" step="0.01" name="load_capacity" class="form-control form-control-sm" required>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label small"><?= e(t('plate_no') ?: 'Plate No') ?></label>
|
|
<input type="text" name="plate_no" class="form-control form-control-sm" required>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small"><?= e(t('reg_expiry') ?: 'Reg. Expiry') ?></label>
|
|
<input type="date" name="registration_expiry_date" class="form-control form-control-sm">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small"><?= e(t('ins_expiry') ?: 'Ins. Expiry') ?></label>
|
|
<input type="date" name="insurance_expiry_date" class="form-control form-control-sm">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small"><?= e(t('truck_picture') ?: 'Truck Picture') ?></label>
|
|
<input type="file" name="truck_pic" class="form-control form-control-sm" accept="image/*">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small"><?= e(t('registration_doc') ?: 'Registration Doc') ?></label>
|
|
<input type="file" name="registration_doc" class="form-control form-control-sm" accept="image/*,application/pdf">
|
|
</div>
|
|
<div class="col-12 text-end">
|
|
<button type="submit" class="btn btn-sm btn-primary"><?= e(t('add_truck') ?: 'Add Truck') ?></button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th><?= e(t('truck_type')) ?></th>
|
|
<th><?= e(t('cap')) ?></th>
|
|
<th><?= e(t('plate_no')) ?></th>
|
|
<th>Docs</th>
|
|
<th>Expiry</th>
|
|
<th>Status</th>
|
|
<th><?= e(t('actions')) ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($ownerTrucks)): ?>
|
|
<tr><td colspan="7" class="text-center text-muted"><?= e(t('no_trucks_found') ?: 'No trucks found') ?></td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($ownerTrucks as $truck): ?>
|
|
<?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>
|
|
<div class="d-flex gap-1">
|
|
<?php if (!empty($truck['truck_pic_path'])): ?>
|
|
<a href="<?= e('/' . $truck['truck_pic_path']) ?>" target="_blank" class="btn btn-xs btn-outline-secondary" title="<?= e(t('truck_picture')) ?>">
|
|
<i class="bi bi-truck"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if (!empty($truck['registration_path'])): ?>
|
|
<a href="<?= e('/' . $truck['registration_path']) ?>" target="_blank" class="btn btn-xs btn-outline-secondary" title="<?= e(t('truck_reg')) ?>">
|
|
<i class="bi bi-file-earmark-text"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
<td><?= e(($truck['registration_expiry_date'] ?? 'N/A') . ' / ' . ($truck['insurance_expiry_date'] ?? 'N/A')) ?></td>
|
|
<td>
|
|
<?php if ($isExpired): ?>
|
|
<span class="badge bg-danger"><?= e(t('rejected')) ?></span>
|
|
<?php elseif ($truck['is_approved']): ?>
|
|
<span class="badge bg-success"><?= e(t('active')) ?></span>
|
|
<?php else: ?>
|
|
<span class="badge bg-warning text-dark"><?= e(t('pending')) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<form method="post" action="admin_truck_owner_edit.php?id=<?= $userId ?><?= $isAjax ? '&ajax=1' : '' ?>">
|
|
<?= 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"><?= e(t('reject')) ?></button>
|
|
<?php elseif (!$isExpired): ?>
|
|
<button type="submit" name="approve_truck" class="btn btn-sm btn-outline-success"><?= e(t('approve')) ?></button>
|
|
<?php endif; ?>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 3: Documents -->
|
|
<div class="tab-pane fade" id="tab-docs" role="tabpanel" aria-labelledby="docs-tab">
|
|
<h5 class="mb-3"><?= e(t('id_card_front') ?: 'ID Card Documents') ?></h5>
|
|
<div class="d-flex flex-wrap gap-3 mb-4">
|
|
<?php
|
|
$idCards = json_decode($owner['id_card_path'] ?? '[]', true) ?: [];
|
|
if (empty($idCards) && !empty($owner['id_card_path']) && !is_array(json_decode($owner['id_card_path'] ?? ''))) {
|
|
$idCards = [$owner['id_card_path']];
|
|
}
|
|
?>
|
|
|
|
<?php foreach ($idCards as $path): ?>
|
|
<div class="card">
|
|
<a href="<?= e('/' . $path) ?>" target="_blank">
|
|
<img src="<?= e('/' . $path) ?>" class="card-img-top" alt="ID Card" style="height: 150px; width: auto; object-fit: cover;">
|
|
</a>
|
|
<div class="card-body p-2 text-center">
|
|
<a href="<?= e('/' . $path) ?>" target="_blank" class="btn btn-sm btn-outline-secondary"><?= e(t('view_full_size') ?: 'View') ?></a>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if (empty($idCards)): ?>
|
|
<p class="text-muted"><?= e(t('no_documents') ?: 'No documents uploaded') ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (!empty($owner['registration_path']) || !empty($owner['truck_pic_path'])): ?>
|
|
<h5 class="mb-3 border-top pt-3"><?= e(t('other_documents') ?: 'Other Profile Documents') ?></h5>
|
|
<div class="d-flex flex-wrap gap-3">
|
|
<?php if (!empty($owner['registration_path'])): ?>
|
|
<div class="card">
|
|
<a href="<?= e('/' . $owner['registration_path']) ?>" target="_blank">
|
|
<img src="<?= e('/' . $owner['registration_path']) ?>" class="card-img-top" alt="Registration" style="height: 150px; width: auto; object-fit: cover;">
|
|
</a>
|
|
<div class="card-body p-2 text-center">
|
|
<h6 class="card-title small mb-2"><?= e(t('truck_reg') ?: 'Registration') ?></h6>
|
|
<a href="<?= e('/' . $owner['registration_path']) ?>" target="_blank" class="btn btn-sm btn-outline-secondary"><?= e(t('view_full_size') ?: 'View') ?></a>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (!empty($owner['truck_pic_path'])): ?>
|
|
<div class="card">
|
|
<a href="<?= e('/' . $owner['truck_pic_path']) ?>" target="_blank">
|
|
<img src="<?= e('/' . $owner['truck_pic_path']) ?>" class="card-img-top" alt="Truck Pic" style="height: 150px; width: auto; object-fit: cover;">
|
|
</a>
|
|
<div class="card-body p-2 text-center">
|
|
<h6 class="card-title small mb-2"><?= e(t('truck_picture') ?: 'Truck Picture') ?></h6>
|
|
<a href="<?= e('/' . $owner['truck_pic_path']) ?>" target="_blank" class="btn btn-sm btn-outline-secondary"><?= e(t('view_full_size') ?: 'View') ?></a>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($isAjax): ?>
|
|
</div> <!-- end modal-body -->
|
|
<?php else: ?>
|
|
</div> <!-- end panel -->
|
|
<?php endif; ?>
|
|
|
|
<script>
|
|
var allCities = <?= json_encode($cities, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
|
|
function syncCities() {
|
|
const countryId = document.getElementById('country_id').value;
|
|
const citySelect = document.getElementById('city_id');
|
|
const selectedValue = citySelect.dataset.selected || '';
|
|
citySelect.innerHTML = '<option value=""><?= e(t('select_city')) ?></option>';
|
|
allCities.forEach((city) => {
|
|
if (String(city.country_id) !== String(countryId)) return;
|
|
const option = document.createElement('option');
|
|
option.value = city.id;
|
|
option.textContent = '<?= $lang ?>' === 'ar' && city.name_ar ? city.name_ar : (city.name_en || city.name_ar);
|
|
if (String(city.id) === String(selectedValue)) option.selected = true;
|
|
citySelect.appendChild(option);
|
|
});
|
|
citySelect.dataset.selected = '';
|
|
}
|
|
setTimeout(syncCities, 100);
|
|
|
|
// Ensure tabs are initialized if opened via AJAX
|
|
if (typeof bootstrap !== 'undefined') {
|
|
var triggerTabList = [].slice.call(document.querySelectorAll('#ownerEditTabs button'))
|
|
triggerTabList.forEach(function (triggerEl) {
|
|
new bootstrap.Tab(triggerEl)
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
if (!$isAjax) {
|
|
echo '</div></div>';
|
|
render_footer();
|
|
}
|
|
?>
|