Initial commit with updated Auth and media ignored
This commit is contained in:
80
ride/RegisrationCar/add.php
Executable file
80
ride/RegisrationCar/add.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
/* ───── 1) جلب الحقول من طلب POST ───── */
|
||||
$driverID = filterRequest("driverID");
|
||||
$vin = filterRequest("vin");
|
||||
$carPlate = filterRequest("car_plate");
|
||||
$make = filterRequest("make");
|
||||
$model = filterRequest("model");
|
||||
$year = filterRequest("year");
|
||||
$expirationDate = filterRequest("expiration_date");
|
||||
$color = filterRequest("color");
|
||||
$owner = filterRequest("owner");
|
||||
$colorHex = filterRequest("color_hex");
|
||||
$fuel = filterRequest("fuel");
|
||||
|
||||
/* ───── 2) التحقق من الحقول الأساسية ───── */
|
||||
$required = [
|
||||
'driverID' => $driverID,
|
||||
'vin' => $vin,
|
||||
'car_plate' => $carPlate,
|
||||
'make' => $make,
|
||||
'model' => $model,
|
||||
'year' => $year,
|
||||
'expirationDate' => $expirationDate,
|
||||
'color' => $color,
|
||||
'owner' => $owner,
|
||||
'colorHex' => $colorHex,
|
||||
'fuel' => $fuel,
|
||||
];
|
||||
|
||||
foreach ($required as $field => $val) {
|
||||
if ($val === null || $val === '') {
|
||||
jsonError("Missing required field: $field");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* ───── 3) تشفير الحقول الحساسة ───── */
|
||||
$vin = $encryptionHelper->encryptData($vin);
|
||||
$carPlate = $encryptionHelper->encryptData($carPlate);
|
||||
$owner = $encryptionHelper->encryptData($owner);
|
||||
|
||||
/* ───── 4) هل لدى السائق مركبة مُسجلة سابقًا؟ ───── */
|
||||
$hasCar = $con->prepare("SELECT 1 FROM CarRegistration WHERE driverID = :d LIMIT 1");
|
||||
$hasCar->execute([':d' => $driverID]);
|
||||
$isDefault = $hasCar->rowCount() === 0 ? 1 : 0;
|
||||
|
||||
/* ───── 5) إدراج السجل ───── */
|
||||
$sql = "
|
||||
INSERT INTO CarRegistration (
|
||||
driverID, vin, car_plate, make, model, year, expiration_date,
|
||||
color, owner, color_hex, fuel, isDefault, created_at, status
|
||||
) VALUES (
|
||||
:driverID, :vin, :carPlate, :make, :model, :year, :expirationDate,
|
||||
:color, :owner, :colorHex, :fuel, :isDefault, NOW(), 'yet'
|
||||
)
|
||||
";
|
||||
|
||||
$ins = $con->prepare($sql);
|
||||
$ins->execute([
|
||||
':driverID' => $driverID,
|
||||
':vin' => $vin,
|
||||
':carPlate' => $carPlate,
|
||||
':make' => $make,
|
||||
':model' => $model,
|
||||
':year' => $year,
|
||||
':expirationDate' => $expirationDate,
|
||||
':color' => $color,
|
||||
':owner' => $owner,
|
||||
':colorHex' => $colorHex,
|
||||
':fuel' => $fuel,
|
||||
':isDefault' => $isDefault,
|
||||
]);
|
||||
|
||||
if ($ins->rowCount() > 0) {
|
||||
jsonSuccess(null, "Car registration saved.");
|
||||
} else {
|
||||
jsonError("Failed to save car registration.");
|
||||
}
|
||||
0
ride/RegisrationCar/delete.php
Normal file
0
ride/RegisrationCar/delete.php
Normal file
0
ride/RegisrationCar/get.php
Normal file
0
ride/RegisrationCar/get.php
Normal file
29
ride/RegisrationCar/makeDefaultCar.php
Executable file
29
ride/RegisrationCar/makeDefaultCar.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
try {
|
||||
// أولاً: إعادة تعيين isDefault = 0 لكل سيارات السائق
|
||||
$sql1 = "UPDATE `CarRegistration` SET `isDefault` = 0 WHERE `driverID` = :driverID";
|
||||
$stmt1 = $con->prepare($sql1);
|
||||
$stmt1->bindParam(':driverID', $driverID);
|
||||
$stmt1->execute();
|
||||
|
||||
// ثانياً: تعيين السيارة المحددة كافتراضية
|
||||
$sql2 = "UPDATE `CarRegistration` SET `isDefault` = 1 WHERE `id` = :id";
|
||||
$stmt2 = $con->prepare($sql2);
|
||||
$stmt2->bindParam(':id', $id);
|
||||
$stmt2->execute();
|
||||
|
||||
if ($stmt2->rowCount() > 0) {
|
||||
jsonSuccess(null, "Default car updated successfully.");
|
||||
} else {
|
||||
jsonError("Failed to update default car.");
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
error_log("DB Error: " . $e->getMessage());
|
||||
jsonError("Database error occurred.");
|
||||
}
|
||||
?>
|
||||
125
ride/RegisrationCar/selectDriverAndCarForMishwariTrip.php
Executable file
125
ride/RegisrationCar/selectDriverAndCarForMishwariTrip.php
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
try {
|
||||
$swLat = floatval(filterRequest("southwestLat"));
|
||||
$neLat = floatval(filterRequest("northeastLat"));
|
||||
$swLon = floatval(filterRequest("southwestLon"));
|
||||
$neLon = floatval(filterRequest("northeastLon"));
|
||||
$yearMin = 2022;
|
||||
$yearMax = 2025;
|
||||
|
||||
if (!is_numeric($swLat) || !is_numeric($neLat) || !is_numeric($swLon) || !is_numeric($neLon)) {
|
||||
throw new Exception("Invalid coordinate values provided");
|
||||
}
|
||||
|
||||
$sql = "
|
||||
WITH LatestLocations AS (
|
||||
SELECT
|
||||
cl.driver_id,
|
||||
cl.latitude,
|
||||
cl.longitude,
|
||||
cl.heading,
|
||||
cl.speed,
|
||||
cl.status,
|
||||
cl.created_at,
|
||||
d.phone,
|
||||
d.email,
|
||||
d.first_name,
|
||||
d.last_name,
|
||||
d.gender,
|
||||
d.maritalStatus,
|
||||
d.education,
|
||||
cr.make,
|
||||
cr.car_plate,
|
||||
cr.model,
|
||||
cr.color,
|
||||
cr.color_hex,
|
||||
cr.year,
|
||||
dt.token,
|
||||
ROW_NUMBER() OVER(
|
||||
PARTITION BY cl.driver_id
|
||||
ORDER BY cl.created_at DESC
|
||||
) AS row_num
|
||||
FROM car_locations cl
|
||||
JOIN driver d ON d.id = cl.driver_id
|
||||
LEFT JOIN CarRegistration cr ON cr.driverID = cl.driver_id
|
||||
LEFT JOIN driverToken dt ON dt.captain_id = cl.driver_id
|
||||
WHERE cl.latitude BETWEEN ? AND ?
|
||||
AND cl.longitude BETWEEN ? AND ?
|
||||
AND cr.year BETWEEN ? AND ?
|
||||
AND cl.created_at >= NOW() - INTERVAL 1 DAY
|
||||
AND cr.make NOT LIKE '%دراج%'
|
||||
AND cr.model NOT LIKE '%دراج%'
|
||||
)
|
||||
SELECT
|
||||
d.id AS driver_id,
|
||||
d.phone,
|
||||
d.gender,
|
||||
d.name_arabic AS name_arabic,
|
||||
d.name_english,
|
||||
d.address,
|
||||
ll.latitude,
|
||||
ll.longitude,
|
||||
FLOOR(DATEDIFF(CURDATE(), STR_TO_DATE(CONCAT(d.birthdate, '-01-01'), '%Y-%m-%d')) / 365.25) AS age,
|
||||
c.car_plate,
|
||||
c.make,
|
||||
c.model,
|
||||
c.year,
|
||||
c.color,
|
||||
c.fuel,
|
||||
c.displacement,
|
||||
c.color_hex,
|
||||
dt.token,
|
||||
COALESCE(avg_rating.rating, 5) AS rating,
|
||||
COALESCE(ride_count.count, 0) AS ride_count
|
||||
FROM driver d
|
||||
JOIN CarRegistration c ON c.driverID = d.id
|
||||
JOIN LatestLocations ll ON ll.driver_id = d.id AND ll.row_num = 1
|
||||
LEFT JOIN driverToken dt ON dt.captain_id = d.id
|
||||
LEFT JOIN (
|
||||
SELECT driver_id, AVG(rating) AS rating
|
||||
FROM ratingDriver
|
||||
GROUP BY driver_id
|
||||
) avg_rating ON avg_rating.driver_id = d.id
|
||||
LEFT JOIN (
|
||||
SELECT driver_id, COUNT(*) AS count
|
||||
FROM ride
|
||||
WHERE status = 'Finished'
|
||||
GROUP BY driver_id
|
||||
) ride_count ON ride_count.driver_id = d.id
|
||||
WHERE c.year BETWEEN ? AND ?
|
||||
ORDER BY rating DESC, c.year DESC, ride_count DESC
|
||||
LIMIT 10";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([
|
||||
$swLat, $neLat, $swLon, $neLon,
|
||||
$yearMin, $yearMax,
|
||||
$yearMin, $yearMax
|
||||
]);
|
||||
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// فك التشفير عن الحقول الحساسة
|
||||
foreach ($rows as &$row) {
|
||||
$row['phone'] = $encryptionHelper->decryptData($row['phone']);
|
||||
$row['gender'] = $encryptionHelper->decryptData($row['gender']);
|
||||
$row['name_arabic'] = $encryptionHelper->decryptData($row['name_arabic']);
|
||||
$row['name_english'] = $encryptionHelper->decryptData($row['name_english']);
|
||||
$row['address'] = $encryptionHelper->decryptData($row['address']);
|
||||
$row['car_plate'] = $encryptionHelper->decryptData($row['car_plate']);
|
||||
$row['token'] = $encryptionHelper->decryptData($row['token']);
|
||||
}
|
||||
|
||||
if (count($rows) > 0) {
|
||||
jsonSuccess($rows);
|
||||
} else {
|
||||
jsonError("No drivers found in the specified area");
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
jsonError("Database error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
jsonError("Error: " . $e->getMessage());
|
||||
}
|
||||
61
ride/RegisrationCar/update.php
Executable file
61
ride/RegisrationCar/update.php
Executable file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
// الحقول التي تحتاج لتشفير
|
||||
$encryptedFields = ['vin', 'car_plate', 'owner'];
|
||||
|
||||
// جميع الحقول المسموح بتحديثها
|
||||
$columns = ['vin', 'car_plate', 'make', 'model', 'year', 'expiration_date', 'color', 'owner', 'isDefault', 'registration_date'];
|
||||
|
||||
$columnValues = [];
|
||||
|
||||
// تحقق من القيم وأضفها إلى التحديث
|
||||
foreach ($columns as $column) {
|
||||
if (isset($_POST[$column])) {
|
||||
$value = filterRequest($column);
|
||||
if (!empty($value)) {
|
||||
// تشفير الحقول الحساسة
|
||||
if (in_array($column, $encryptedFields)) {
|
||||
$value = $encryptionHelper->encryptData($value);
|
||||
}
|
||||
$columnValues[$column] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// بناء جملة SET للتحديث
|
||||
$setClause = [];
|
||||
foreach ($columnValues as $column => $value) {
|
||||
$setClause[] = "`$column` = :$column";
|
||||
}
|
||||
$setClause = implode(", ", $setClause);
|
||||
|
||||
// التحقق من وجود بيانات للتحديث
|
||||
if (empty($setClause)) {
|
||||
jsonError("No data provided to update.");
|
||||
exit();
|
||||
}
|
||||
|
||||
// ✅ تأكد من اسم الجدول الصحيح
|
||||
$sql = "UPDATE `CarRegistration` SET $setClause WHERE `driverID` = :driverID AND `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
|
||||
// ربط القيم بالاستعلام
|
||||
foreach ($columnValues as $column => $value) {
|
||||
$stmt->bindValue(":$column", $value);
|
||||
}
|
||||
$stmt->bindValue(':driverID', $driverID);
|
||||
$stmt->bindValue(':id', $id);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Car registration data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update car registration data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user