diff --git a/admin_truck_owner_edit.php b/admin_truck_owner_edit.php index eb8c642..d24c173 100644 --- a/admin_truck_owner_edit.php +++ b/admin_truck_owner_edit.php @@ -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):
- ← Back to Truck Owners -

Edit Truck Owner

+ +

@@ -134,45 +137,57 @@ if (!$isAjax):
-
Personal Details
+
- +
- +
- +
- +
- +
-
- > - +
+
+
+ > + +
+
+
+ + +
+
+ + +
-
Location
+
- +
- +
- +
-
Bank Details
+
- +
- +
- +
- + -
Registered Trucks
+
- - - - - + + + + - + @@ -232,15 +246,14 @@ if (!$isAjax): - - + @@ -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 = ''; + citySelect.innerHTML = ''; allCities.forEach((city) => { if (String(city.country_id) !== String(countryId)) return; const option = document.createElement('option'); @@ -281,4 +294,4 @@ function syncCities() { } syncCities(); - + \ No newline at end of file diff --git a/db/migrations/add_company_details_to_profiles.php b/db/migrations/add_company_details_to_profiles.php new file mode 100644 index 0000000..0528d7d --- /dev/null +++ b/db/migrations/add_company_details_to_profiles.php @@ -0,0 +1,14 @@ +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(); +} \ No newline at end of file diff --git a/includes/app.php b/includes/app.php index 6a5ac5e..2407103 100644 --- a/includes/app.php +++ b/includes/app.php @@ -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) {} \ No newline at end of file diff --git a/register.php b/register.php index cd213b3..5a6df74 100644 --- a/register.php +++ b/register.php @@ -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');
- +
@@ -215,23 +224,17 @@ render_header('Shipper & Truck Owner Registration');
+
-
- - -
-
+
-
+
-
+
@@ -262,22 +265,23 @@ render_header('Shipper & Truck Owner Registration');
+

- +
- -
Truck TypeCapacity (T)Plate NoReg ExpiryIns ExpiryExpiry StatusActions
- Expired/Disabled + - Approved + - Pending + @@ -248,9 +261,9 @@ if (!$isAjax): - + - +