Files
Siro/backend/auth/captin/updateAccountBank.php
2026-06-09 08:40:31 +03:00

53 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/../../connect.php';
$id = filterRequest("id");
$columnValues = [];
$params = [':id' => $id];
// الحقول التي تحتاج تشفير
$fieldsToEncrypt = [
"phone", "email", "gender", "birthdate", "site",
"first_name", "last_name", "accountBank", "education",
"employmentType", "maritalStatus"
];
// الحقول غير المشفرة
$plainFields = ["status", "bankCode", "updated_at"];
foreach ($_POST as $key => $value) {
$filtered = filterRequest($key);
if ($key === "password") {
// هاش لكلمة المرور
$hashed = password_hash($filtered, PASSWORD_DEFAULT);
$columnValues[] = "`password` = :password";
$params[':password'] = $hashed;
} elseif (in_array($key, $fieldsToEncrypt)) {
$encrypted = $encryptionHelper->encryptData($filtered);
$columnValues[] = "`$key` = :$key";
$params[":$key"] = $encrypted;
} elseif (in_array($key, $plainFields)) {
$columnValues[] = "`$key` = :$key";
$params[":$key"] = $filtered;
}
}
// بناء جملة التحديث
if (empty($columnValues)) {
jsonError("No data provided to update.");
exit;
}
$setClause = implode(", ", $columnValues);
$sql = "UPDATE `driver` SET $setClause WHERE `id` = :id";
$stmt = $con->prepare($sql);
$stmt->execute($params);
if ($stmt->rowCount() > 0) {
jsonSuccess(null, "Driver data updated successfully");
} else {
jsonError("Failed to update driver data");
}
?>