Initial commit with updated Auth and media ignored
This commit is contained in:
58
ride/location/save_behavior.php
Normal file
58
ride/location/save_behavior.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// تأكد من أن ملف connect.php يقوم بتهيئة اتصالين:
|
||||
// $con -> يتصل بقاعدة البيانات الأساسية
|
||||
// $con_tracking -> يتصل بقاعدة بيانات التتبع (driver_behavior, car_locations)
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
try {
|
||||
// استلام البيانات من Flutter
|
||||
$driver_id = filterRequest("driver_id");
|
||||
$trip_id = filterRequest("trip_id");
|
||||
$max_speed = filterRequest("max_speed");
|
||||
$avg_speed = filterRequest("avg_speed");
|
||||
$hard_brakes = filterRequest("hard_brakes");
|
||||
$total_distance = filterRequest("total_distance");
|
||||
$behavior_score = filterRequest("behavior_score");
|
||||
|
||||
// تحقق من القيم الأساسية
|
||||
if (empty($driver_id) || empty($trip_id)) {
|
||||
jsonError("Missing driver_id or trip_id");
|
||||
exit();
|
||||
}
|
||||
|
||||
// إدخال البيانات في جدول driver_behavior باستخدام اتصال التتبع
|
||||
// تم تغيير $con إلى $con_tracking
|
||||
$stmt = $con_tracking->prepare("
|
||||
INSERT INTO driver_behavior (
|
||||
driver_id, trip_id, max_speed, avg_speed,
|
||||
hard_brakes, total_distance, behavior_score
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
$driver_id,
|
||||
$trip_id,
|
||||
$max_speed,
|
||||
$avg_speed,
|
||||
$hard_brakes,
|
||||
$total_distance,
|
||||
$behavior_score
|
||||
]);
|
||||
|
||||
// التحقق من نجاح العملية
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Behavior data saved");
|
||||
} else {
|
||||
// في حالة عدم حدوث خطأ، ولكن لم يتم إدخال صف (قد يحدث)،
|
||||
// من الأفضل إرجاع رسالة فشل عامة.
|
||||
jsonError("Failed to save data (No rows affected)");
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
jsonError("Database error: " . $e->getMessage());
|
||||
} catch (Throwable $e) {
|
||||
jsonError("Internal error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// تم حذف exit() من هنا ليتم التعامل معها داخل try/catch
|
||||
?>
|
||||
Reference in New Issue
Block a user