updating registration forms

This commit is contained in:
Flatlogic Bot 2026-03-24 04:15:22 +00:00
parent e67be138ad
commit e163ce11cd
4 changed files with 189 additions and 103 deletions

View File

@ -23,7 +23,7 @@ $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.is_company
p.id_card_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'
@ -70,6 +70,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
$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.';
@ -95,10 +97,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
$stmtProfile = db()->prepare("
UPDATE truck_owner_profiles
SET phone = ?, address_line = ?, country_id = ?, city_id = ?,
bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ?
bank_account = ?, bank_name = ?, bank_branch = ?, is_company = ?,
ctr_number = ?, notes = ?
WHERE user_id = ?
");
$stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $userId]);
$stmtProfile->execute([$phone, $addressLine, $countryId, $cityId, $bankAccount, $bankName, $bankBranch, $isCompany, $ctrNumber, $notes, $userId]);
db()->commit();
$flash = 'Truck Owner profile updated successfully.';
@ -121,8 +124,8 @@ if (!$isAjax):
</div>
<div class="col-md-10 p-4">
<div class="page-intro mb-4">
<a href="admin_truck_owners.php" class="text-decoration-none small text-muted mb-2 d-inline-block">&larr; Back to Truck Owners</a>
<h1 class="section-title mb-1">Edit Truck Owner</h1>
<a href="admin_truck_owners.php" class="text-decoration-none small text-muted mb-2 d-inline-block">&larr; <?= e(t('back')) ?></a>
<h1 class="section-title mb-1"><?= e(t('edit_owner')) ?></h1>
</div>
<?php if ($flash): ?>
@ -134,45 +137,57 @@ if (!$isAjax):
<div class="panel p-4">
<form method="post" action="admin_truck_owner_edit.php?id=<?= $userId ?>" class="mb-5"> <?= csrf_field() ?>
<h5 class="mb-3">Personal Details</h5>
<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">Full Name</label>
<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">Email</label>
<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">Phone</label>
<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">Password <small class="text-muted">(leave blank)</small></label>
<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">Account Status</label>
<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' : '' ?>>Pending</option>
<option value="active" <?= $owner['status'] === 'active' ? 'selected' : '' ?>>Active</option>
<option value="rejected" <?= $owner['status'] === 'rejected' ? 'selected' : '' ?>>Rejected</option>
<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="form-check mb-4">
<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">Register as a company</label>
<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">Location</h5>
<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">Country</label>
<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="">Select country</option>
<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']) ?>
@ -181,46 +196,45 @@ if (!$isAjax):
</select>
</div>
<div class="col-md-4">
<label class="form-label" for="city_id">City</label>
<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="">Select city</option>
<option value=""><?= e(t('select_city')) ?></option>
</select>
</div>
<div class="col-md-4">
<label class="form-label" for="address_line">Address Line</label>
<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">Bank Details</h5>
<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">Bank Account / IBAN</label>
<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">Bank Name</label>
<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">Bank Branch</label>
<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>
<button type="submit" class="btn btn-primary">Save Changes</button>
<button type="submit" class="btn btn-primary"><?= e(t('save_changes')) ?></button>
</form>
<h5 class="mb-3 border-top pt-3">Registered Trucks</h5>
<h5 class="mb-3 border-top pt-3"><?= e(t('truck_info')) ?></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><?= e(t('truck_type')) ?></th>
<th><?= e(t('cap')) ?></th>
<th><?= e(t('plate_no')) ?></th>
<th>Expiry</th>
<th>Status</th>
<th>Actions</th>
<th><?= e(t('actions')) ?></th>
</tr>
</thead>
<tbody>
@ -232,15 +246,14 @@ if (!$isAjax):
<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><?= e(($truck['registration_expiry_date'] ?? 'N/A') . ' / ' . ($truck['insurance_expiry_date'] ?? 'N/A')) ?></td>
<td>
<?php if ($isExpired): ?>
<span class="badge bg-danger">Expired/Disabled</span>
<span class="badge bg-danger"><?= e(t('rejected')) ?></span>
<?php elseif ($truck['is_approved']): ?>
<span class="badge bg-success">Approved</span>
<span class="badge bg-success"><?= e(t('active')) ?></span>
<?php else: ?>
<span class="badge bg-warning text-dark">Pending</span>
<span class="badge bg-warning text-dark"><?= e(t('pending')) ?></span>
<?php endif; ?>
</td>
<td>
@ -248,9 +261,9 @@ if (!$isAjax):
<?= 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>
<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">Approve</button>
<button type="submit" name="approve_truck" class="btn btn-sm btn-outline-success"><?= e(t('approve')) ?></button>
<?php endif; ?>
</form>
</td>
@ -268,7 +281,7 @@ function syncCities() {
const countryId = document.getElementById('country_id').value;
const citySelect = document.getElementById('city_id');
const selectedValue = citySelect.dataset.selected || '';
citySelect.innerHTML = '<option value="">Select city</option>';
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');
@ -281,4 +294,4 @@ function syncCities() {
}
syncCities();
</script>
<?php render_footer(); endif; ?>
<?php render_footer(); endif; ?>

View File

@ -0,0 +1,14 @@
<?php
require_once __DIR__ . '/../config.php';
$pdo = db();
try {
$pdo->exec("
ALTER TABLE truck_owner_profiles
ADD COLUMN IF NOT EXISTS ctr_number VARCHAR(100) DEFAULT NULL,
ADD COLUMN IF NOT EXISTS notes TEXT DEFAULT NULL;
");
echo "Schema updated successfully.";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}

View File

@ -313,6 +313,9 @@ $translations = [
'subject_en' => 'Subject (EN)',
'subject_ar' => 'Subject (AR)',
'is_company_checkbox' => 'Register as a company?',
'ctr_number' => 'CTR Number',
'ctr_document' => 'CTR Document',
'notes' => 'Notes',
),
"ar" => array (
'app_name' => 'CargoLink',
@ -614,7 +617,9 @@ $translations = [
'subject_en' => 'الموضوع (إنجليزي)',
'subject_ar' => 'الموضوع (عربي)',
'is_company_checkbox' => 'هل التسجيل كشركة؟',
'ctr_number' => 'رقم السجل التجاري (CTR)',
'ctr_document' => 'وثيقة السجل التجاري',
'notes' => 'ملاحظات',
)
];
@ -877,4 +882,4 @@ try {
if ($tz && in_array($tz, DateTimeZone::listIdentifiers())) {
date_default_timezone_set($tz);
}
} catch (Throwable $e) {}
} catch (Throwable $e) {}

View File

@ -6,9 +6,12 @@ ensure_schema();
$errors = [];
$saved = false;
$saved_role = '';
$role = $_GET['role'] ?? 'shipper';
if (!in_array($role, ['shipper', 'truck_owner'], true)) {
$role = 'shipper';
}
$values = [
'role' => $_GET['role'] ?? 'shipper',
'full_name' => '',
'email' => '',
'phone' => '',
@ -20,13 +23,14 @@ $values = [
'bank_name' => '',
'bank_branch' => '',
'is_company' => '0',
'ctr_number' => '',
'notes' => '',
];
$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();
$role = $_POST['role'] ?? 'shipper';
$fullName = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
@ -37,7 +41,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
$passwordRaw = (string)($_POST['password'] ?? '');
$values = [
'role' => $role,
'full_name' => $fullName,
'email' => $email,
'phone' => $phone,
@ -49,11 +52,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
'bank_name' => trim($_POST['bank_name'] ?? ''),
'bank_branch' => trim($_POST['bank_branch'] ?? ''),
'is_company' => isset($_POST['is_company']) ? '1' : '0',
'ctr_number' => trim($_POST['ctr_number'] ?? ''),
'notes' => trim($_POST['notes'] ?? ''),
];
if (!in_array($role, ['shipper', 'truck_owner'], true)) {
$errors[] = 'Invalid role selected.';
}
if ($fullName === '') {
$errors[] = 'Full name is required.';
}
@ -125,23 +127,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
};
$idCardPaths = [];
if (is_uploaded_file($_FILES['id_card_front']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['id_card_front']['tmp_name'], (int)$_FILES['id_card_front']['size'], 'id_front_');
if ($path) $idCardPaths[] = $path;
}
if (is_uploaded_file($_FILES['id_card_back']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['id_card_back']['tmp_name'], (int)$_FILES['id_card_back']['size'], 'id_back_');
if ($path) $idCardPaths[] = $path;
}
if (count($idCardPaths) < 2) {
$errors[] = 'Please upload ID front and back.';
$ctrPath = null;
if ($values['is_company'] === '1') {
if (is_uploaded_file($_FILES['ctr_document']['tmp_name'] ?? '')) {
$ctrPath = $saveImage($_FILES['ctr_document']['tmp_name'], (int)$_FILES['ctr_document']['size'], 'ctr_');
}
if (!$ctrPath) $errors[] = 'CTR document is required for companies.';
} else {
if (is_uploaded_file($_FILES['id_card_front']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['id_card_front']['tmp_name'], (int)$_FILES['id_card_front']['size'], 'id_front_');
if ($path) $idCardPaths[] = $path;
}
if (is_uploaded_file($_FILES['id_card_back']['tmp_name'] ?? '')) {
$path = $saveImage($_FILES['id_card_back']['tmp_name'], (int)$_FILES['id_card_back']['size'], 'id_back_');
if ($path) $idCardPaths[] = $path;
}
if (count($idCardPaths) < 2) $errors[] = 'Please upload ID front and back.';
}
if (!$errors) {
$ownerStmt = $pdo->prepare(
"INSERT INTO truck_owner_profiles (user_id, phone, country_id, city_id, address_line, bank_account, bank_name, bank_branch, id_card_path, is_company)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
"INSERT INTO truck_owner_profiles (user_id, phone, country_id, city_id, address_line, bank_account, bank_name, bank_branch, id_card_path, is_company, ctr_number, notes)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
$ownerStmt->execute([
$userId,
@ -152,8 +160,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
$values['bank_account'],
$values['bank_name'],
$values['bank_branch'],
json_encode($idCardPaths, JSON_UNESCAPED_SLASHES),
$values['is_company']
$values['is_company'] === '1' ? $ctrPath : json_encode($idCardPaths, JSON_UNESCAPED_SLASHES),
$values['is_company'],
$values['ctr_number'],
$values['notes']
]);
}
}
@ -179,7 +189,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
}
$saved = true;
$saved_role = $role;
}
} catch (Throwable $e) {
if ($pdo->inTransaction()) {
@ -204,7 +213,7 @@ render_header('Shipper & Truck Owner Registration');
<div class="panel p-4">
<?php if ($saved): ?>
<?php if ($saved_role === 'truck_owner'): ?>
<?php if ($role === 'truck_owner'): ?>
<div class="alert alert-success"><?= e(t('reg_success_pending')) ?></div>
<?php else: ?>
<div class="alert alert-success"><?= e(t('reg_success')) ?></div>
@ -215,23 +224,17 @@ render_header('Shipper & Truck Owner Registration');
<?php endif; ?>
<form method="post" enctype="multipart/form-data" id="regForm" novalidate> <?= csrf_field() ?>
<input type="hidden" name="role" value="<?= e($role) ?>">
<div class="row g-3">
<div class="col-md-3">
<label class="form-label" for="role"><?= e(t('role')) ?></label>
<select name="role" id="role" class="form-select" onchange="toggleFields()" required>
<option value="shipper" <?= $values['role'] === 'shipper' ? 'selected' : '' ?>><?= e(t('shipper')) ?></option>
<option value="truck_owner" <?= $values['role'] === 'truck_owner' ? 'selected' : '' ?>><?= e(t('truck_owner')) ?></option>
</select>
</div>
<div class="col-md-3">
<div class="col-md-4">
<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($values['full_name']) ?>" required>
</div>
<div class="col-md-3">
<div class="col-md-4">
<label class="form-label" for="email"><?= e(t('email')) ?></label>
<input type="email" name="email" id="email" class="form-control" value="<?= e($values['email']) ?>" required>
</div>
<div class="col-md-3">
<div class="col-md-4">
<label class="form-label" for="password"><?= e(t('password')) ?></label>
<input type="password" name="password" id="password" class="form-control" minlength="6" required>
</div>
@ -262,22 +265,23 @@ render_header('Shipper & Truck Owner Registration');
</div>
</div>
<?php if ($role === 'shipper'): ?>
<div id="shipperFields" class="mt-4">
<h2 class="h5 mb-3"><?= e(t('shipper_details')) ?></h2>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label" for="company_name"><?= e(t('company_name')) ?></label>
<input type="text" name="company_name" id="company_name" class="form-control" value="<?= e($values['company_name']) ?>">
<input type="text" name="company_name" id="company_name" class="form-control" value="<?= e($values['company_name']) ?>" required>
</div>
</div>
</div>
<div id="truckFields" class="mt-4" style="display:none;">
<h2 class="h5 mb-3"><?= e(t('owner_details')) ?></h2>
<?php else: ?>
<div id="truckFields" class="mt-4">
<h2 class="h5 mb-3"><?= e(t('truck_details')) ?></h2>
<div class="row g-3">
<div class="col-md-12 mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="is_company" id="is_company" value="1" <?= $values['is_company'] === '1' ? 'checked' : '' ?>>
<input class="form-check-input" type="checkbox" name="is_company" id="is_company" value="1" <?= $values['is_company'] === '1' ? 'checked' : '' ?> onchange="toggleCompanyFields()">
<label class="form-check-label" for="is_company"><?= e(t('is_company_checkbox')) ?></label>
</div>
</div>
@ -295,16 +299,34 @@ render_header('Shipper & Truck Owner Registration');
<input type="text" name="bank_branch" id="bank_branch" class="form-control" value="<?= e($values['bank_branch']) ?>">
</div>
<div class="col-md-6 mt-3">
<label class="form-label" for="id_card_front"><?= e(t('id_card_front')) ?></label>
<input type="file" name="id_card_front" id="id_card_front" class="form-control" accept="image/png,image/jpeg,image/webp">
<div id="individualDocs" class="row g-3 mt-0">
<div class="col-md-6">
<label class="form-label" for="id_card_front"><?= e(t('id_card_front')) ?></label>
<input type="file" name="id_card_front" id="id_card_front" class="form-control" accept="image/png,image/jpeg,image/webp">
</div>
<div class="col-md-6">
<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>
<div class="col-md-6 mt-3">
<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 id="companyDocs" class="row g-3 mt-0" style="display:none;">
<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($values['ctr_number']) ?>">
</div>
<div class="col-md-6">
<label class="form-label" for="ctr_document"><?= e(t('ctr_document')) ?></label>
<input type="file" name="ctr_document" id="ctr_document" class="form-control" accept="image/png,image/jpeg,image/webp">
</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($values['notes']) ?></textarea>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="mt-4 d-flex gap-2">
<button type="submit" class="btn btn-primary"><?= e(t('create_account')) ?></button>
@ -313,8 +335,34 @@ render_header('Shipper & Truck Owner Registration');
</form>
</div>
<style>
<?php if ($lang === 'ar'): ?>
/* Override default browser file input text */
input[type="file"]::file-selector-button {
margin-left: 10px;
margin-right: 0;
}
input[type="file"] {
text-align: right;
}
<?php endif; ?>
</style>
<script>
const allCities = <?= json_encode($cities, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
const lang = '<?= e($lang) ?>';
// Force browser-specific file input text override
function updateFileInputPlaceholder() {
if (lang === 'ar') {
const fileInputs = document.querySelectorAll('input[type="file"]');
fileInputs.forEach(input => {
// Standard browser "No file chosen" isn't directly settable via CSS
// but we can wrap it or use custom UI if needed.
// For now, we apply basic directionality for better UI.
});
}
}
function syncCities() {
const countryId = document.getElementById('country_id').value;
@ -337,19 +385,25 @@ function syncCities() {
citySelect.dataset.selected = '';
}
function toggleFields() {
const role = document.getElementById('role').value;
const truckFields = document.getElementById('truckFields');
const shipperFields = document.getElementById('shipperFields');
const companyInput = document.getElementById('company_name');
const isOwner = role === 'truck_owner';
shipperFields.style.display = isOwner ? 'none' : 'block';
truckFields.style.display = isOwner ? 'block' : 'none';
companyInput.required = !isOwner;
function toggleCompanyFields() {
const isCompany = document.getElementById('is_company').checked;
const front = document.getElementById('id_card_front');
const back = document.getElementById('id_card_back');
const ctr = document.getElementById('ctr_document');
if (front) front.required = !isCompany;
if (back) back.required = !isCompany;
if (ctr) ctr.required = isCompany;
document.getElementById('individualDocs').style.display = isCompany ? 'none' : 'flex';
document.getElementById('companyDocs').style.display = isCompany ? 'flex' : 'none';
}
syncCities();
toggleFields();
updateFileInputPlaceholder();
<?php if ($role === 'truck_owner'): ?>
toggleCompanyFields();
<?php endif; ?>
</script>
<?php render_footer(); ?>
<?php render_footer();