first commit

This commit is contained in:
Hamza-Ayed
2026-06-09 08:40:31 +03:00
commit d8901e1a87
3161 changed files with 536187 additions and 0 deletions

187
backend/ride/mishwari/add.php Executable file
View File

@@ -0,0 +1,187 @@
<?php
require_once __DIR__ . '/../../connect.php';
// استقبال البيانات
$driverId = filterRequest("id");
$phone = filterRequest("phone");
$gender = filterRequest("gender");
$name = filterRequest("name");
$name_english = filterRequest("name_english");
$address = filterRequest("address");
$religion = filterRequest("religion");
$age = filterRequest("age");
$startNameAddress = filterRequest("startNameAddress");
$locationCoordinate = filterRequest("locationCoordinate");
$education = filterRequest("education");
$license_type = filterRequest("license_type");
$national_number = filterRequest("national_number");
$car_plate = filterRequest("car_plate");
$make = filterRequest("make");
$model = filterRequest("model");
$year = filterRequest("year");
$color = filterRequest("color");
$color_hex = filterRequest("color_hex");
$token = filterRequest("token");
$rating = filterRequest("rating");
$countRide = filterRequest("countRide");
$passengerId = filterRequest("passengerId");
$timeSelected = filterRequest("timeSelected");
$status = filterRequest("status");
// 🔐 تشفير الحقول الحساسة
$phone = $encryptionHelper->encryptData($phone);
$gender = $encryptionHelper->encryptData($gender);
$name = $encryptionHelper->encryptData($name);
$name_english = $encryptionHelper->encryptData($name_english);
$car_plate = $encryptionHelper->encryptData($car_plate);
$token = $encryptionHelper->encryptData($token);
$education = $encryptionHelper->encryptData($education);
$national_number = $encryptionHelper->encryptData($national_number);
$age = $encryptionHelper->encryptData($age);
// ⏰ تحويل الوقت للفحص
$selectedTime = new DateTime($timeSelected);
$startTime = $selectedTime->format('Y-m-d H:i:s');
$endTime = $selectedTime->add(new DateInterval('PT6H'))->format('Y-m-d H:i:s');
// ✅ فحص هل السائق لديه أكثر من رحلتين خلال 6 ساعات
$sqlCheck = "SELECT COUNT(*) as trip_count
FROM `mishwaritrips`
WHERE `driverId` = :driverId
AND `timeSelected` BETWEEN :startTime AND :endTime";
$stmtCheck = $con->prepare($sqlCheck);
$stmtCheck->bindParam(':driverId', $driverId);
$stmtCheck->bindParam(':startTime', $startTime);
$stmtCheck->bindParam(':endTime', $endTime);
$stmtCheck->execute();
$result = $stmtCheck->fetch(PDO::FETCH_ASSOC);
if ($result['trip_count'] >= 2) {
jsonError("Driver already has 2 trips within the specified period.");
exit;
}
// ✅ فحص إن الراكب لا يملك رحلة فعالة بنفس اليوم
$sqlCheckPassenger = "
SELECT *
FROM `mishwaritrips`
WHERE `passengerId` = :passengerId
AND `status` != 'Finished'
AND DATE(`timeSelected`) = CURDATE()
";
$stmtCheckPassenger = $con->prepare($sqlCheckPassenger);
$stmtCheckPassenger->bindParam(':passengerId', $passengerId);
$stmtCheckPassenger->execute();
$existingTrip = $stmtCheckPassenger->fetch(PDO::FETCH_ASSOC);
// إذا كانت موجودة يتم التحديث
if ($existingTrip) {
$sqlUpdate = "UPDATE `mishwaritrips` SET
`driverId` = :driverId,
`phone` = :phone,
`gender` = :gender,
`name` = :name,
`name_english` = :name_english,
`address` = :address,
`religion` = :religion,
`age` = :age,
`startNameAddress` = :startNameAddress,
`locationCoordinate` = :locationCoordinate,
`education` = :education,
`license_type` = :license_type,
`national_number` = :national_number,
`car_plate` = :car_plate,
`make` = :make,
`model` = :model,
`color` = :color,
`color_hex` = :color_hex,
`token` = :token,
`rating` = :rating,
`countRide` = :countRide,
`timeSelected` = :timeSelected,
`status` = :status
WHERE `passengerId` = :passengerId";
$stmtUpdate = $con->prepare($sqlUpdate);
$stmtUpdate->execute([
':driverId' => $driverId,
':phone' => $phone,
':gender' => $gender,
':name' => $name,
':name_english' => $name_english,
':address' => $address,
':religion' => $religion,
':age' => $age,
':startNameAddress' => $startNameAddress,
':locationCoordinate' => $locationCoordinate,
':education' => $education,
':license_type' => $license_type,
':national_number' => $national_number,
':car_plate' => $car_plate,
':make' => $make,
':model' => $model,
':color' => $color,
':color_hex' => $color_hex,
':token' => $token,
':rating' => $rating,
':countRide' => $countRide,
':timeSelected' => $timeSelected,
':status' => $status,
':passengerId' => $passengerId
]);
if ($stmtUpdate->rowCount() > 0) {
jsonSuccess(null, "Trip updated successfully");
} else {
jsonError("Failed to update trip data");
}
} else {
// إدخال رحلة جديدة
$sqlInsert = "INSERT INTO `mishwaritrips` (
`driverId`, `phone`, `gender`, `name`, `name_english`, `address`, `religion`,
`age`, `startNameAddress`, `locationCoordinate`, `education`, `license_type`,
`national_number`, `car_plate`, `make`, `model`, `color`, `color_hex`, `token`,
`rating`, `countRide`, `passengerId`, `timeSelected`, `createdAt`, `status`
) VALUES (
:driverId, :phone, :gender, :name, :name_english, :address, :religion,
:age, :startNameAddress, :locationCoordinate, :education, :license_type,
:national_number, :car_plate, :make, :model, :color, :color_hex, :token,
:rating, :countRide, :passengerId, :timeSelected, NOW(), :status
)";
$stmtInsert = $con->prepare($sqlInsert);
$stmtInsert->execute([
':driverId' => $driverId,
':phone' => $phone,
':gender' => $gender,
':name' => $name,
':name_english' => $name_english,
':address' => $address,
':religion' => $religion,
':age' => $age,
':startNameAddress' => $startNameAddress,
':locationCoordinate' => $locationCoordinate,
':education' => $education,
':license_type' => $license_type,
':national_number' => $national_number,
':car_plate' => $car_plate,
':make' => $make,
':model' => $model,
':color' => $color,
':color_hex' => $color_hex,
':token' => $token,
':rating' => $rating,
':countRide' => $countRide,
':passengerId' => $passengerId,
':timeSelected' => $timeSelected,
':status' => $status
]);
if ($stmtInsert->rowCount() > 0) {
jsonSuccess(null, "New trip inserted successfully");
} else {
jsonError("Failed to insert new trip data");
}
}
?>

View File

@@ -0,0 +1,41 @@
<?php
require_once __DIR__ . '/../../connect.php';
// Fetch the input data
$id = filterRequest("id"); // Trip ID to identify the trip
$status = "cancelled"; // New status
// Check if the trip ID is provided
if (empty($id)) {
jsonError("Trip ID is missing.");
exit;
}
// Update the status of the trip to "cancelled"
$sql = "
UPDATE `mishwaritrips`
SET `status` = :status
WHERE `id` = :id AND `status` != 'cancelled'
";
$stmt = $con->prepare($sql);
$stmt->bindParam(':status', $status, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // Bind the ID parameter
// Execute the update
if ($stmt->execute()) {
// Check if the update was successful
if ($stmt->rowCount() > 0) {
// Trip status updated successfully
jsonSuccess(null, "Trip cancelled successfully.");
} else {
// No rows updated, meaning the trip might not have been found or was already cancelled
jsonError("No trip found to cancel.");
}
} else {
// Print failure if the update query failed
$errorInfo = $stmt->errorInfo();
error_log('SQL Error: ' . implode(", ", $errorInfo));
jsonError("Failed to cancel the trip.");
}
?>

View File

70
backend/ride/mishwari/get.php Executable file
View File

@@ -0,0 +1,70 @@
<?php
require_once __DIR__ . '/../../connect.php';
$driverId = filterRequest("driverId");
$sql = "
SELECT
mi.`id`,
mi.`driverId`,
mi.`phone`,
mi.`gender`,
mi.`name`,
mi.`name_english`,
mi.`address`,
mi.`religion`,
mi.`age`,
mi.`education`,
mi.`license_type`,
mi.`national_number`,
mi.`car_plate`,
mi.`make`,
mi.`model`,
mi.`color`,
mi.`color_hex`,
mi.`token`,
mi.`rating`,
mi.`countRide`,
mi.`passengerId`,
mi.`timeSelected`,
mi.`createdAt`,
mi.`status`,
p.phone AS passengerPhone,
p.first_name AS passengerName,
p.last_name AS passengerLastName,
p.gender AS passengergender,
d.name_arabic,
tkp.token AS passengerToken
FROM
`mishwaritrips` mi
LEFT JOIN driver d ON
d.id = mi.driverId
LEFT JOIN passengers p ON
p.id = mi.passengerId
LEFT JOIN tokens tkp ON
tkp.passengerID = mi.passengerId
WHERE
mi. passengerId = :driverId
AND mi.createdAt >= CURDATE() - INTERVAL 4 DAY
AND mi.timeSelected > NOW()
ORDER BY
mi. `createdAt`
DESC
LIMIT 1
";
$stmt = $con->prepare($sql);
$stmt->bindParam(':driverId', $driverId, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() > 0) {
// Fetch the record
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
jsonSuccess($row);
}
else{
// Print a failure message
jsonError($message = "No wallet record found");
}
?>

View File

@@ -0,0 +1,70 @@
<?php
require_once __DIR__ . '/../../connect.php';
$driverId = filterRequest("driverId");
$sql = "
SELECT
mi.`id`,
mi.`driverId`,
mi.`phone`,
mi.`gender`,
mi.`name`,
mi.`name_english`,
mi.`address`,
mi.`religion`,
mi.`age`,
mi.`education`,
mi.`license_type`,
mi.`national_number`,
mi.`car_plate`,
mi.`make`,
mi.`model`,
mi.`color`,
mi.`color_hex`,
mi.`token`,
mi.`rating`,
mi.`countRide`,
mi.`passengerId`,
mi.`timeSelected`,
mi.`createdAt`,
mi.`status`,
p.phone AS passengerPhone,
p.first_name AS passengerName,
p.last_name AS passengerLastName,
p.gender AS passengergender,
d.name_arabic,
tkp.token AS passengerToken
FROM
`mishwaritrips` mi
LEFT JOIN driver d ON
d.id = mi.driverId
LEFT JOIN passengers p ON
p.id = mi.passengerId
LEFT JOIN tokens tkp ON
tkp.passengerID = mi.passengerId
WHERE
mi. driverId = :driverId
AND mi.createdAt >= CURDATE() - INTERVAL 4 DAY
AND mi.timeSelected > NOW()
ORDER BY
mi. `createdAt`
DESC
LIMIT 1
";
$stmt = $con->prepare($sql);
$stmt->bindParam(':driverId', $driverId, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() > 0) {
// Fetch the record
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
jsonSuccess($row);
}
else{
// Print a failure message
jsonError($message = "No wallet record found");
}
?>

View File

@@ -0,0 +1,30 @@
<?php
require_once __DIR__ . '/../../connect.php';
$sql = "SELECT * FROM `passengers` ORDER BY `created_at` DESC LIMIT 5";
$stmt = $con->prepare($sql);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// فك التشفير للحقول الحساسة
foreach ($rows as &$row) {
$row['phone'] = $encryptionHelper->decryptData($row['phone']);
$row['email'] = $encryptionHelper->decryptData($row['email']);
$row['gender'] = $encryptionHelper->decryptData($row['gender']);
$row['birthdate'] = $encryptionHelper->decryptData($row['birthdate']);
$row['site'] = $encryptionHelper->decryptData($row['site']);
$row['first_name'] = $encryptionHelper->decryptData($row['first_name']);
$row['last_name'] = $encryptionHelper->decryptData($row['last_name']);
$row['sosPhone'] = $encryptionHelper->decryptData($row['sosPhone']);
$row['education'] = $encryptionHelper->decryptData($row['education']);
$row['employmentType'] = $encryptionHelper->decryptData($row['employmentType']);
$row['maritalStatus'] = $encryptionHelper->decryptData($row['maritalStatus']);
}
jsonSuccess($rows);
} else {
jsonError("No passengers found");
}
?>