Files
intaleq_v3_pure_php/ride/rides/update.php
2026-04-28 13:04:27 +03:00

89 lines
3.3 KiB
PHP
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../../connect.php';
// 🚀 تسجيل بداية العملية
error_log("🚀 [update.php] Request Started to update Ride Dynamic Data.");
$id = filterRequest("id");
if (!$id) {
error_log("❌ [update.php] Missing ID.");
jsonError("Missing ID");
exit;
}
$columnValues = [];
$params = [':id' => $id];
// قائمة الحقول القابلة للتحديث
$fields = [
"start_location", "end_location", "date", "time", "endtime", "price",
"passenger_id", "driver_id", "status", "created_at", "updated_at",
"rideTimeStart", "rideTimeFinish", "price_for_driver", "driverGoToPassengerTime",
"price_for_passenger", "distance"
];
// بناء الاستعلام ديناميكياً باستخدام filterRequest
foreach ($fields as $field) {
// نتحقق من وجود المفتاح في الـ POST
if (isset($_POST[$field])) {
// نستخدم دالة الفلترة الخاصة بك
$value = filterRequest($field);
$columnValues[] = "`$field` = :$field";
$params[":$field"] = $value;
}
}
// إذا لم يتم إرسال أي حقول للتحديث
if (empty($columnValues)) {
error_log("⚠️ [update.php] No data provided in request to update.");
jsonError("No data provided for update.");
exit;
}
// تجميع جملة SQL
$setClause = implode(", ", $columnValues);
$sql = "UPDATE `ride` SET $setClause WHERE `id` = :id";
try {
// ---------------------------------------------------------
// 1. التحديث على سيرفر التتبع (Remote DB) - هو الأساس
// ---------------------------------------------------------
error_log("🔄 [update.php] Attempting to update REMOTE Tracking DB for Ride ID: $id");
$stmtRemote = $con_ride->prepare($sql);
$stmtRemote->execute($params);
$count = $stmtRemote->rowCount();
error_log(" [update.php] Remote DB Rows Affected: $count");
// التحقق: هل نجح التحديث هناك؟
if ($count > 0) {
// ---------------------------------------------------------
// 2. التحديث على السيرفر المحلي (Local DB) للمطابقة
// ---------------------------------------------------------
error_log("🔄 [update.php] Remote success. Updating LOCAL Main DB...");
$stmtLocal = $con->prepare($sql);
$stmtLocal->execute($params);
error_log("✅ [update.php] Update successful on both servers.");
// استخدام دالة النجاح الخاصة بك
jsonSuccess(null, "Ride data updated successfully");
} else {
// لم يتم التحديث (إما البيانات نفسها لم تتغير، أو المعرف غير موجود في السيرفر البعيد)
error_log("⚠️ [update.php] Remote Update returned 0 rows (Data same or ID not found).");
// استخدام دالة الفشل (يمكنك تغيير الرسالة لتكون success إذا كنت لا تعتبر عدم تغيير البيانات خطأ)
jsonError("No changes made (Remote DB affected 0 rows). Check ID or Data.");
}
} catch (PDOException $e) {
error_log("❌ [update.php] Database Error: " . $e->getMessage());
jsonError("Database Error: " . $e->getMessage());
}
?>