first commit
This commit is contained in:
53
backend/auth/captin/updateAccountBank.php
Normal file
53
backend/auth/captin/updateAccountBank.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user