Initial commit with updated Auth and media ignored
This commit is contained in:
36
ride/notificationCaptain/add.php
Normal file
36
ride/notificationCaptain/add.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
$title = filterRequest("title");
|
||||
$body = filterRequest("body");
|
||||
$isPin = filterRequest("isPin");
|
||||
|
||||
$sql = "INSERT INTO `notificationCaptain` (
|
||||
`driverID`,
|
||||
`title`,
|
||||
`body`,
|
||||
`isPin`
|
||||
) VALUES (
|
||||
:driverID,
|
||||
:title,
|
||||
:body,
|
||||
:isPin
|
||||
)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([
|
||||
':driverID' => $driverID,
|
||||
':title' => $title,
|
||||
':body' => $body,
|
||||
':isPin' => $isPin
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data saved successfully");
|
||||
} else {
|
||||
jsonError("Failed to save notification data");
|
||||
}
|
||||
|
||||
?>
|
||||
72
ride/notificationCaptain/addWaitingRide.php
Executable file
72
ride/notificationCaptain/addWaitingRide.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
try {
|
||||
$requiredParams = [
|
||||
'id', 'start_location', 'end_location', 'price',
|
||||
'passenger_id', 'status', 'carType', 'price_for_passenger',
|
||||
'distance', 'passengerRate', 'duration'
|
||||
];
|
||||
|
||||
$params = [];
|
||||
foreach ($requiredParams as $param) {
|
||||
$value = filterRequest($param);
|
||||
if ($value === null) {
|
||||
throw new Exception("Missing required parameter: $param");
|
||||
}
|
||||
$params[$param] = $value;
|
||||
}
|
||||
|
||||
// استخراج lat/lng من start_location و end_location
|
||||
$startCoords = explode(',', $params['start_location']);
|
||||
$endCoords = explode(',', $params['end_location']);
|
||||
|
||||
$params['start_lat'] = trim($startCoords[0]);
|
||||
$params['start_lng'] = trim($startCoords[1]);
|
||||
$params['end_lat'] = trim($endCoords[0]);
|
||||
$params['end_lng'] = trim($endCoords[1]);
|
||||
|
||||
// استخدام INSERT ... ON DUPLICATE KEY UPDATE (أفضل من فحص منفصل)
|
||||
$sql = "INSERT INTO waitingRides (
|
||||
id, start_location, end_location, start_lat, start_lng,
|
||||
end_lat, end_lng, date, time, price, passenger_id,
|
||||
status, carType, passengerRate, created_at,
|
||||
price_for_passenger, distance, duration
|
||||
) VALUES (
|
||||
:id, :start_location, :end_location, :start_lat, :start_lng,
|
||||
:end_lat, :end_lng, CURDATE(), CURTIME(), :price, :passenger_id,
|
||||
:status, :carType, :passengerRate, NOW(),
|
||||
:price_for_passenger, :distance, :duration
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
start_location = VALUES(start_location),
|
||||
end_location = VALUES(end_location),
|
||||
start_lat = VALUES(start_lat),
|
||||
start_lng = VALUES(start_lng),
|
||||
end_lat = VALUES(end_lat),
|
||||
end_lng = VALUES(end_lng),
|
||||
date = CURDATE(),
|
||||
time = CURTIME(),
|
||||
price = VALUES(price),
|
||||
status = VALUES(status),
|
||||
carType = VALUES(carType),
|
||||
passengerRate = VALUES(passengerRate),
|
||||
price_for_passenger = VALUES(price_for_passenger),
|
||||
distance = VALUES(distance),
|
||||
duration = VALUES(duration)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Operation completed successfully");
|
||||
} else {
|
||||
jsonSuccess(null, "No changes made");
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database error in addWaitingRide: " . $e->getMessage());
|
||||
jsonError("Database error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
jsonError("Error: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
18
ride/notificationCaptain/delete.php
Normal file
18
ride/notificationCaptain/delete.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$notificationID = filterRequest("id");
|
||||
|
||||
$sql = "DELETE FROM `notificationCaptain` WHERE `id` = :id";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':id', $notificationID, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data deleted successfully");
|
||||
} else {
|
||||
jsonError("Failed to delete notification data");
|
||||
}
|
||||
|
||||
?>
|
||||
30
ride/notificationCaptain/deleteAvailableRide.php
Executable file
30
ride/notificationCaptain/deleteAvailableRide.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
try {
|
||||
// Retrieve and validate the 'id' parameter
|
||||
$id = filterRequest('id');
|
||||
if ($id === null || $id === '') {
|
||||
throw new Exception("Missing required parameter: id");
|
||||
}
|
||||
|
||||
// Prepare the SQL query to delete the record
|
||||
$sql = "DELETE FROM `waitingRides` WHERE `id` = :id";
|
||||
|
||||
// Prepare and execute the statement
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
// Check the result and print the appropriate message
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Record with ID $id deleted successfully.");
|
||||
} else {
|
||||
jsonError("No record found with ID $id.");
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
jsonError("Database error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
jsonError("Error: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
0
ride/notificationCaptain/error_log
Normal file
0
ride/notificationCaptain/error_log
Normal file
23
ride/notificationCaptain/get.php
Executable file
23
ride/notificationCaptain/get.php
Executable file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT * FROM `notificationCaptain`
|
||||
WHERE `driverID` = :driverID
|
||||
AND `dateCreated` > DATE_SUB(NOW(), INTERVAL 2 DAY)
|
||||
ORDER BY `dateCreated` DESC
|
||||
LIMIT 10";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':driverID', $driverID, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
|
||||
$notifications = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($notifications) {
|
||||
jsonSuccess($notifications);
|
||||
} else {
|
||||
jsonError("No notification data found");
|
||||
}
|
||||
?>
|
||||
159
ride/notificationCaptain/getRideWaiting.php
Executable file
159
ride/notificationCaptain/getRideWaiting.php
Executable file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
// getRideWaiting.php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$lat = filterRequest("lat");
|
||||
$lng = filterRequest("lng");
|
||||
$radius = filterRequest("radius");
|
||||
|
||||
if (empty($lat) || empty($lng)) {
|
||||
jsonSuccess([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($radius)) {
|
||||
$radius = 50;
|
||||
}
|
||||
|
||||
$finalRides = [];
|
||||
$rideIds = [];
|
||||
$redisResultsMap = [];
|
||||
|
||||
// 1. محاولة البحث عبر Redis
|
||||
try {
|
||||
$locationServerUrl = "http://location.intaleq.xyz:2021";
|
||||
$INTERNAL_KEY = trim(@file_get_contents('/home/intaleq-api/.internal_socket_key'));
|
||||
|
||||
$postData = [
|
||||
'action' => 'get_nearby_ride_ids',
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'radius' => $radius
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $locationServerUrl);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 500);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-internal-key: $INTERNAL_KEY"]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode == 200 && $response) {
|
||||
$jsonResults = json_decode($response, true);
|
||||
if (is_array($jsonResults) && !empty($jsonResults)) {
|
||||
foreach ($jsonResults as $res) {
|
||||
$rideIds[] = $res[0];
|
||||
$redisResultsMap[$res[0]] = $res[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// نتابع للخطة ب
|
||||
}
|
||||
|
||||
// 2. جلب البيانات (إما عبر IDs أو بحث مباشر)
|
||||
try {
|
||||
if (!empty($rideIds)) {
|
||||
// --- الحالة أ: الريدز وجد رحلات ---
|
||||
$placeholders = implode(',', array_fill(0, count($rideIds), '?'));
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
wr.id, wr.start_location AS startName, wr.end_location AS endName,
|
||||
wr.date, wr.time, wr.price, wr.passenger_id, wr.status, wr.carType,
|
||||
wr.passengerRate, wr.created_at, wr.price_for_passenger,
|
||||
wr.distance, wr.duration, wr.start_lat, wr.start_lng,
|
||||
wr.end_lat, wr.end_lng, wr.payment_method, wr.passenger_wallet,
|
||||
p.email, p.first_name, p.phone, p.id AS passengerId, t.token AS passengerToken
|
||||
FROM waitingRides wr
|
||||
INNER JOIN passengers p ON p.id = wr.passenger_id
|
||||
LEFT JOIN tokens t ON t.passengerID = wr.passenger_id
|
||||
LEFT JOIN passengerWallet pw ON pw.passenger_id = wr.passenger_id
|
||||
WHERE wr.id IN ($placeholders) AND wr.status IN ('wait', 'waiting')
|
||||
";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($rideIds);
|
||||
$waitingRides = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
} else {
|
||||
// --- الحالة ب: بحث مباشر MySQL (Fallback) ---
|
||||
// 🔥 التصحيح هنا: استخدام أسماء فريدة (:lat1, :lat2) لتجنب خطأ التكرار
|
||||
|
||||
$haversine = "( 6371 * acos( cos( radians(:lat1) ) * cos( radians( wr.start_lat ) ) * cos( radians( wr.start_lng ) - radians(:lng) ) + sin( radians(:lat2) ) * sin( radians( wr.start_lat ) ) ) )";
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
wr.id, wr.start_location AS startName, wr.end_location AS endName,
|
||||
wr.date, wr.time, wr.price, wr.passenger_id, wr.status, wr.carType,
|
||||
wr.passengerRate, wr.created_at, wr.price_for_passenger,
|
||||
wr.distance, wr.duration, wr.start_lat, wr.start_lng,
|
||||
wr.end_lat, wr.end_lng, wr.payment_method, wr.passenger_wallet,
|
||||
p.email, p.first_name, p.phone, p.id AS passengerId, t.token AS passengerToken,
|
||||
{$haversine} AS driver_distance_km
|
||||
FROM waitingRides wr
|
||||
INNER JOIN passengers p ON p.id = wr.passenger_id
|
||||
LEFT JOIN tokens t ON t.passengerID = wr.passenger_id
|
||||
LEFT JOIN passengerWallet pw ON pw.passenger_id = wr.passenger_id
|
||||
WHERE
|
||||
wr.status IN ('wait', 'waiting')
|
||||
AND wr.created_at >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
|
||||
AND wr.start_lat IS NOT NULL
|
||||
HAVING driver_distance_km <= :radius
|
||||
ORDER BY driver_distance_km ASC
|
||||
LIMIT 50
|
||||
";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
|
||||
// نمرر القيمة مرتين للمفتاحين المختلفين
|
||||
$stmt->execute([
|
||||
':lat1' => $lat,
|
||||
':lng' => $lng,
|
||||
':lat2' => $lat, // تكرار القيمة للمتغير الثاني
|
||||
':radius' => $radius
|
||||
]);
|
||||
|
||||
$waitingRides = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// 3. التنسيق
|
||||
foreach ($waitingRides as $ride) {
|
||||
$ride['phone'] = $encryptionHelper->decryptData($ride['phone'] ?? '');
|
||||
$ride['first_name'] = $encryptionHelper->decryptData($ride['first_name'] ?? '');
|
||||
$ride['email'] = $encryptionHelper->decryptData($ride['email'] ?? '');
|
||||
|
||||
$ride['start_location'] = $ride['start_lat'] . ',' . $ride['start_lng'];
|
||||
$ride['end_location'] = (!empty($ride['end_lat']))
|
||||
? $ride['end_lat'] . ',' . $ride['end_lng']
|
||||
: $ride['endName'];
|
||||
|
||||
$ride['id'] = (string)$ride['id'];
|
||||
|
||||
if (isset($ride['driver_distance_km'])) {
|
||||
$ride['driver_distance_km'] = number_format((float)$ride['driver_distance_km'], 1);
|
||||
} elseif (isset($redisResultsMap[$ride['id']])) {
|
||||
$ride['driver_distance_km'] = number_format((float)$redisResultsMap[$ride['id']], 1);
|
||||
} else {
|
||||
$ride['driver_distance_km'] = "0.0";
|
||||
}
|
||||
|
||||
$finalRides[] = $ride;
|
||||
}
|
||||
|
||||
usort($finalRides, function($a, $b) {
|
||||
return $a['driver_distance_km'] <=> $b['driver_distance_km'];
|
||||
});
|
||||
|
||||
jsonSuccess($finalRides);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("DB Error getRideWaiting: " . $e->getMessage());
|
||||
jsonError("Database error");
|
||||
}
|
||||
?>
|
||||
52
ride/notificationCaptain/update.php
Normal file
52
ride/notificationCaptain/update.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
// Array to hold the SET parts and parameters
|
||||
$columnValues = [];
|
||||
$params = [':id' => $id];
|
||||
|
||||
if (isset($_POST["driverID"])) {
|
||||
$columnValues[] = "`driverID` = :driverID";
|
||||
$params[':driverID'] = filterRequest("driverID");
|
||||
}
|
||||
|
||||
if (isset($_POST["title"])) {
|
||||
$columnValues[] = "`title` = :title";
|
||||
$params[':title'] = filterRequest("title");
|
||||
}
|
||||
|
||||
if (isset($_POST["body"])) {
|
||||
$columnValues[] = "`body` = :body";
|
||||
$params[':body'] = filterRequest("body");
|
||||
}
|
||||
|
||||
if (isset($_POST["isShown"])) {
|
||||
$columnValues[] = "`isShown` = :isShown";
|
||||
$params[':isShown'] = filterRequest("isShown");
|
||||
}
|
||||
|
||||
if (isset($_POST["dateCreated"])) {
|
||||
$columnValues[] = "`dateCreated` = :dateCreated";
|
||||
$params[':dateCreated'] = filterRequest("dateCreated");
|
||||
}
|
||||
|
||||
// Check if there are fields to update
|
||||
if (empty($columnValues)) {
|
||||
jsonError("No fields to update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$setClause = implode(", ", $columnValues);
|
||||
$sql = "UPDATE `notificationCaptain` SET $setClause WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Notification data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update notification data");
|
||||
}
|
||||
?>
|
||||
39
ride/notificationCaptain/updateWaitingTrip.php
Normal file
39
ride/notificationCaptain/updateWaitingTrip.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
$fields = [];
|
||||
$params = [':id' => $id];
|
||||
|
||||
$possibleFields = [
|
||||
'start_location', 'end_location', 'date', 'time', 'price',
|
||||
'passenger_id', 'status', 'carType', 'passengerRate',
|
||||
'price_for_passenger', 'distance', 'duration'
|
||||
];
|
||||
|
||||
foreach ($possibleFields as $field) {
|
||||
if (isset($_POST[$field])) {
|
||||
$value = filterRequest($field);
|
||||
$fields[] = "`$field` = :$field";
|
||||
$params[":$field"] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($fields)) {
|
||||
jsonError("No fields provided for update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$setClause = implode(", ", $fields);
|
||||
$sql = "UPDATE `waitingRides` SET $setClause WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Waiting ride data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update waiting ride data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user