70 lines
2.4 KiB
PHP
Executable File
70 lines
2.4 KiB
PHP
Executable File
<?php
|
|
// 1. إعدادات التصحيح (Debug) - ضرورية جداً الآن
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With, Access-Control-Allow-Origin");
|
|
header("Access-Control-Allow-Methods: POST, OPTIONS , GET");
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
// 2. تضمين ملف الاتصال
|
|
if (file_exists("../../connect.php")) {
|
|
include "../../connect.php";
|
|
} else {
|
|
// في حال عدم وجود الملف، ننهي التنفيذ ونطبع السبب
|
|
die(json_encode(array("status" => "failure", "message" => "Connect file not found")));
|
|
}
|
|
|
|
// 3. التقاط البيانات بذكاء (لحل مشكلة Flutter JSON)
|
|
// هذا الجزء يفحص: هل البيانات في POST؟ أم في JSON Body؟
|
|
$driver_id = null;
|
|
|
|
if (isset($_POST['driver_id'])) {
|
|
$driver_id = filterRequest("driver_id");
|
|
} else {
|
|
// محاولة قراءة JSON Body (لأن فلاتر يرسل البيانات هكذا غالباً)
|
|
$jsonInput = json_decode(file_get_contents("php://input"), true);
|
|
if (isset($jsonInput['driver_id'])) {
|
|
$driver_id = htmlspecialchars(strip_tags($jsonInput['driver_id']));
|
|
}
|
|
}
|
|
|
|
// التحقق النهائي
|
|
if (!$driver_id) {
|
|
// طباعة الخطأ بوضوح
|
|
echo json_encode(array("status" => "failure", "message" => "driver_id is missing or empty"));
|
|
exit;
|
|
}
|
|
|
|
// 4. التنفيذ
|
|
try {
|
|
$date = date('Y-m-d');
|
|
|
|
$sql = "SELECT total_seconds FROM driver_daily_summary
|
|
WHERE driver_id = ? AND date = ?";
|
|
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([$driver_id, $date]);
|
|
$data = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$duration = "00:00:00";
|
|
if ($data) {
|
|
$seconds = $data['total_seconds'];
|
|
$duration = gmdate("H:i:s", $seconds);
|
|
}
|
|
|
|
// 5. بناء الاستجابة يدوياً لتطابق كود Flutter 100%
|
|
// الهيكل المطلوب: data['message'][0]['total_duration']
|
|
$response = array(
|
|
"status" => "success",
|
|
"message" => array(
|
|
array("total_duration" => $duration)
|
|
)
|
|
);
|
|
|
|
echo json_encode($response);
|
|
|
|
} catch (PDOException $e) {
|
|
echo json_encode(array("status" => "failure", "message" => "DB Error: " . $e->getMessage()));
|
|
}
|
|
?>
|