نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../connect.php';
|
|
|
|
// Retrieve driverID (allow 'id' or 'driverID')
|
|
$driverID = filterRequest("id") ?? filterRequest("driverID");
|
|
if (!$driverID) {
|
|
jsonError("Driver ID is required");
|
|
exit;
|
|
}
|
|
|
|
// التحقق من أن المستخدم يملك هذا الحساب أو هو أدمن
|
|
$canUpdate = ($role === 'admin' || $role === 'super_admin' || (string)$user_id === (string)$driverID);
|
|
if (!$canUpdate) {
|
|
jsonError("Unauthorized: You can only update your own account");
|
|
exit;
|
|
}
|
|
|
|
/* ---------------------------------------------------------
|
|
DRIVER TABLE
|
|
--------------------------------------------------------- */
|
|
$driverFieldsAllowed = [
|
|
"idn", "phone", "email", "password", "gender", "license_type",
|
|
"national_number", "name_arabic", "issue_date", "expiry_date",
|
|
"license_categories", "address", "licenseIssueDate", "status",
|
|
"birthdate", "site", "first_name", "last_name", "accountBank",
|
|
"bankCode", "employmentType", "maritalStatus", "fullNameMaritial",
|
|
"expirationDate", "created_at", "updated_at"
|
|
];
|
|
|
|
// إزالة الحقول الحساسة من التحديث إذا كان المستخدم ليس أدمن
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
$driverFieldsAllowed = array_diff($driverFieldsAllowed, ['password', 'status', 'email', 'phone']);
|
|
}
|
|
|
|
$encryptedDriverFields = [
|
|
"phone", "email", "password", "national_number","gender", "name_arabic", "first_name",
|
|
"last_name", "birthdate", "site", "maritalStatus", "employmentType", "accountBank", "bankCode"
|
|
];
|
|
|
|
$driverSet = [];
|
|
$driverParams = [":id" => $driverID];
|
|
|
|
foreach ($driverFieldsAllowed as $field) {
|
|
if (isset($_POST[$field]) && $_POST[$field] !== "") {
|
|
$value = filterRequest($field);
|
|
|
|
if (in_array($field, $encryptedDriverFields)) {
|
|
$value = $encryptionHelper->encryptData($value);
|
|
}
|
|
|
|
$driverSet[] = "`$field` = :$field";
|
|
$driverParams[":$field"] = $value;
|
|
}
|
|
}
|
|
|
|
$driverUpdated = false;
|
|
if (!empty($driverSet)) {
|
|
$driverSql = "UPDATE `driver` SET " . implode(", ", $driverSet) . " WHERE `id` = :id";
|
|
$stmt = $con->prepare($driverSql);
|
|
$stmt->execute($driverParams);
|
|
$driverUpdated = $stmt->rowCount() > 0;
|
|
}
|
|
|
|
/* ---------------------------------------------------------
|
|
CAR REGISTRATION TABLE
|
|
--------------------------------------------------------- */
|
|
$carFieldsAllowed = [
|
|
"id", "vin", "car_plate", "make", "model", "year",
|
|
"expiration_date", "color", "owner", "color_hex", "fuel",
|
|
"isDefault", "created_at", "status"
|
|
];
|
|
|
|
$carSet = [];
|
|
$carParams = [":driverID" => $driverID];
|
|
|
|
foreach ($carFieldsAllowed as $field) {
|
|
if ($field === "id") continue;
|
|
if (isset($_POST[$field]) && $_POST[$field] !== "") {
|
|
$value = filterRequest($field);
|
|
$carSet[] = "`$field` = :$field";
|
|
$carParams[":$field"] = $value;
|
|
}
|
|
}
|
|
|
|
$carUpdated = false;
|
|
if (!empty($carSet)) {
|
|
$carSql = "UPDATE `CarRegistration` SET " . implode(", ", $carSet) . " WHERE `driverID` = :driverID";
|
|
$stmtCar = $con->prepare($carSql);
|
|
$stmtCar->execute($carParams);
|
|
$carUpdated = $stmtCar->rowCount() > 0;
|
|
}
|
|
|
|
if ($driverUpdated || $carUpdated) {
|
|
jsonSuccess(null, "Driver & Car updated successfully");
|
|
} else {
|
|
jsonError("No changes were applied");
|
|
}
|