61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
$id = filterRequest("id");
|
|
$driverID = filterRequest("driverID");
|
|
|
|
// الحقول التي تحتاج لتشفير
|
|
$encryptedFields = ['vin', 'car_plate', 'owner'];
|
|
|
|
// جميع الحقول المسموح بتحديثها
|
|
$columns = ['vin', 'car_plate', 'make', 'model', 'year', 'expiration_date', 'color', 'owner', 'isDefault', 'registration_date'];
|
|
|
|
$columnValues = [];
|
|
|
|
// تحقق من القيم وأضفها إلى التحديث
|
|
foreach ($columns as $column) {
|
|
if (isset($_POST[$column])) {
|
|
$value = filterRequest($column);
|
|
if (!empty($value)) {
|
|
// تشفير الحقول الحساسة
|
|
if (in_array($column, $encryptedFields)) {
|
|
$value = $encryptionHelper->encryptData($value);
|
|
}
|
|
$columnValues[$column] = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
// بناء جملة SET للتحديث
|
|
$setClause = [];
|
|
foreach ($columnValues as $column => $value) {
|
|
$setClause[] = "`$column` = :$column";
|
|
}
|
|
$setClause = implode(", ", $setClause);
|
|
|
|
// التحقق من وجود بيانات للتحديث
|
|
if (empty($setClause)) {
|
|
jsonError("No data provided to update.");
|
|
exit();
|
|
}
|
|
|
|
// ✅ تأكد من اسم الجدول الصحيح
|
|
$sql = "UPDATE `CarRegistration` SET $setClause WHERE `driverID` = :driverID AND `id` = :id";
|
|
|
|
$stmt = $con->prepare($sql);
|
|
|
|
// ربط القيم بالاستعلام
|
|
foreach ($columnValues as $column => $value) {
|
|
$stmt->bindValue(":$column", $value);
|
|
}
|
|
$stmt->bindValue(':driverID', $driverID);
|
|
$stmt->bindValue(':id', $id);
|
|
|
|
$stmt->execute();
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
jsonSuccess(null, "Car registration data updated successfully");
|
|
} else {
|
|
jsonError("Failed to update car registration data");
|
|
}
|
|
?>
|