38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
// ride/scheduled/list.php — حجوزات الراكب
|
|
//
|
|
// القادمة أولاً ثم الأحدث تاريخاً: الراكب يفتح الشاشة ليرى ما ينتظره،
|
|
// لا ليتصفّح أرشيفه.
|
|
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
$passengerId = $user_id ?? '';
|
|
if (empty($passengerId)) {
|
|
jsonError('Unauthorized', 401);
|
|
}
|
|
|
|
$scope = filterRequest('scope') ?: 'upcoming';
|
|
|
|
try {
|
|
if ($scope === 'upcoming_driver') {
|
|
$sql = "SELECT * FROM scheduled_rides WHERE driver_id = ? AND scheduled_at >= NOW() ORDER BY scheduled_at ASC LIMIT 50";
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([$passengerId]); // $passengerId here is actually the user_id (driver's ID)
|
|
} else {
|
|
$sql = "SELECT * FROM scheduled_rides WHERE passenger_id = ?";
|
|
if ($scope === 'upcoming') {
|
|
$sql .= " AND status = 'scheduled' AND scheduled_at >= NOW()";
|
|
}
|
|
$sql .= " ORDER BY scheduled_at ASC LIMIT 50";
|
|
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([$passengerId]);
|
|
}
|
|
|
|
jsonSuccess(['bookings' => $stmt->fetchAll(PDO::FETCH_ASSOC)], 'ok');
|
|
|
|
} catch (PDOException $e) {
|
|
error_log('[scheduled/list] ' . $e->getMessage());
|
|
jsonError('DB Error', 500);
|
|
}
|