Files
Siro/backend/ride/driver_behavior/get_driver_behavior.php
Hamza-Ayed 72eeb24cd7 Fix #18: Exception leak remediation across 87 PHP files
- Replaced all client-facing $e->getMessage() with generic error messages
- Added error_log() with filename prefix to all catch blocks
- Covered jsonError(), echo, and json_encode() response patterns
- Also fixed 2 remaining display_errors=1 and add_invoice.php leak
- Script-assisted fix for 75 files, manual fix for 12 remaining edge cases
2026-06-17 07:48:31 +03:00

41 lines
1.4 KiB
PHP

<?php
require_once __DIR__ . '/../../connect.php';
try {
$driver_id = filterRequest("driver_id");
// ✅ أولاً: حساب متوسط السلوك لجميع الرحلات
$sql_average = "SELECT COALESCE(AVG(behavior_score), 100) AS overall_behavior_score
FROM driver_behavior
WHERE driver_id = :driver_id";
$stmt_avg = $con->prepare($sql_average);
$stmt_avg->bindParam(':driver_id', $driver_id);
$stmt_avg->execute();
$average = $stmt_avg->fetch(PDO::FETCH_ASSOC);
// ✅ ثانياً: جلب آخر 10 رحلات
$sql_last10 = "SELECT id, trip_id, max_speed, avg_speed, hard_brakes, total_distance, behavior_score, created_at
FROM driver_behavior
WHERE driver_id = :driver_id
ORDER BY id DESC
LIMIT 10";
$stmt_last10 = $con->prepare($sql_last10);
$stmt_last10->bindParam(':driver_id', $driver_id);
$stmt_last10->execute();
$last10 = $stmt_last10->fetchAll(PDO::FETCH_ASSOC);
// ✅ تجهيز الاستجابة النهائية
$response = [
'overall_behavior_score' => $average['overall_behavior_score'],
'last_10_trips' => $last10
];
jsonSuccess($response);
} catch (PDOException $e) {
error_log("[get_driver_behavior.php] " . $e->getMessage());
jsonError("An internal error occurred. Please try again later.");
}
?>