Initial commit with updated Auth and media ignored
This commit is contained in:
55
ride/carDrivers/add.php
Executable file
55
ride/carDrivers/add.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// استقبال القيم
|
||||
$driverID = filterRequest("driverID");
|
||||
$vin = $encryptionHelper->encryptData(filterRequest("vin"));
|
||||
$car_plate = $encryptionHelper->encryptData(filterRequest("car_plate"));
|
||||
$make = filterRequest("make");
|
||||
$model = filterRequest("model");
|
||||
$year = filterRequest("year");
|
||||
$expiration_date = filterRequest("expiration_date");
|
||||
$color = filterRequest("color");
|
||||
$owner = $encryptionHelper->encryptData(filterRequest("owner"));
|
||||
$color_hex = filterRequest("color_hex");
|
||||
$address = $encryptionHelper->encryptData(filterRequest("address"));
|
||||
$displacement = filterRequest("displacement");
|
||||
$fuel = filterRequest("fuel");
|
||||
$registration_date = filterRequest("registration_date");
|
||||
|
||||
// SQL statement
|
||||
$sql = "INSERT INTO `captains_car` (
|
||||
`driverID`, `vin`, `car_plate`, `make`, `model`, `year`, `expiration_date`,
|
||||
`color`, `owner`, `color_hex`, `address`, `displacement`, `fuel`, `registration_date`
|
||||
) VALUES (
|
||||
:driverID, :vin, :car_plate, :make, :model, :year, :expiration_date,
|
||||
:color, :owner, :color_hex, :address, :displacement, :fuel, :registration_date
|
||||
)";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
|
||||
// Bind parameters
|
||||
$stmt->bindParam(':driverID', $driverID);
|
||||
$stmt->bindParam(':vin', $vin);
|
||||
$stmt->bindParam(':car_plate', $car_plate);
|
||||
$stmt->bindParam(':make', $make);
|
||||
$stmt->bindParam(':model', $model);
|
||||
$stmt->bindParam(':year', $year, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':expiration_date', $expiration_date);
|
||||
$stmt->bindParam(':color', $color);
|
||||
$stmt->bindParam(':owner', $owner);
|
||||
$stmt->bindParam(':color_hex', $color_hex);
|
||||
$stmt->bindParam(':address', $address);
|
||||
$stmt->bindParam(':displacement', $displacement);
|
||||
$stmt->bindParam(':fuel', $fuel);
|
||||
$stmt->bindParam(':registration_date', $registration_date);
|
||||
|
||||
$stmt->execute();
|
||||
$insertedId = $con->lastInsertId();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(["id" => $insertedId]);
|
||||
} else {
|
||||
jsonError("Failed to save car registration information");
|
||||
}
|
||||
?>
|
||||
19
ride/carDrivers/delete.php
Executable file
19
ride/carDrivers/delete.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// استقبال ID السجل
|
||||
$id = filterRequest("id");
|
||||
|
||||
// حذف السجل من جدول captains_car (أو CarRegistration لو هو الصحيح فعلاً)
|
||||
$sql = "DELETE FROM captains_car WHERE id = :id";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
// التحقق من نجاح الحذف
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Car registration deleted successfully");
|
||||
} else {
|
||||
jsonError("Failed to delete car registration");
|
||||
}
|
||||
?>
|
||||
0
ride/carDrivers/error_log
Normal file
0
ride/carDrivers/error_log
Normal file
89
ride/carDrivers/get.php
Executable file
89
ride/carDrivers/get.php
Executable file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// get_driver_cars.php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// استقبال driverID (نصي لأنه غالباً محفوظ كنص)
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
try {
|
||||
if (empty($driverID)) {
|
||||
jsonError("driverID is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
// هنعرّف دالة لتوحيد الصف من أي جدول لنفس المخطط
|
||||
function normalize_car_row(array $row, string $source, $encryptionHelper): array {
|
||||
// بعض الحقول قد لا تكون موجودة في كلا الجدولين
|
||||
$get = function($k, $default = null) use ($row) {
|
||||
return array_key_exists($k, $row) ? $row[$k] : $default;
|
||||
};
|
||||
|
||||
// فك التشفير عند الحاجة وبشكل آمن
|
||||
$dec = function($v) use ($encryptionHelper) {
|
||||
if ($v === null || $v === '') return $v;
|
||||
try { return $encryptionHelper->decryptData($v); } catch (\Throwable $e) { return $v; }
|
||||
};
|
||||
|
||||
// أعمدة مشتركة/موحّدة للإخراج
|
||||
return [
|
||||
'id' => $get('id'),
|
||||
'driverID' => $get('driverID'),
|
||||
'vin' => $dec($get('vin')), // إن كان مُشفراً
|
||||
'car_plate' => $dec($get('car_plate')), // إن كان مُشفراً
|
||||
'make' => $get('make'),
|
||||
'model' => $get('model'),
|
||||
'year' => $get('year'),
|
||||
'expiration_date' => $get('expiration_date'),
|
||||
'color' => $get('color'),
|
||||
'color_hex' => $get('color_hex'),
|
||||
'owner' => $dec($get('owner')), // إن كان مُشفراً
|
||||
'address' => $dec($get('address')), // قد لا يوجد في CarRegistration
|
||||
'type' => $get('type'), // إن وُجد
|
||||
'isDefault' => (int)($get('isDefault', 0)),
|
||||
'status' => $get('status'),
|
||||
'created_at' => $get('created_at'),
|
||||
'source' => $source, // لمعرفة مصدر السجل
|
||||
];
|
||||
}
|
||||
|
||||
// 1) جلب من captains_car
|
||||
$sql1 = "SELECT * FROM captains_car WHERE driverID = :driverID";
|
||||
$st1 = $con->prepare($sql1);
|
||||
$st1->execute([':driverID' => $driverID]);
|
||||
$rows1 = $st1->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// 2) جلب من CarRegistration
|
||||
$sql2 = "SELECT * FROM CarRegistration WHERE driverID = :driverID";
|
||||
$st2 = $con->prepare($sql2);
|
||||
$st2->execute([':driverID' => $driverID]);
|
||||
$rows2 = $st2->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// 3) توحيد النتائج مع فك التشفير
|
||||
$result = [];
|
||||
foreach ($rows1 as $r) { $result[] = normalize_car_row($r, 'captains_car', $encryptionHelper); }
|
||||
foreach ($rows2 as $r) { $result[] = normalize_car_row($r, 'CarRegistration', $encryptionHelper); }
|
||||
|
||||
if (empty($result)) {
|
||||
jsonError("No driver car data found");
|
||||
exit;
|
||||
}
|
||||
|
||||
// 4) ترتيب النتيجة: السيارات الافتراضية أولاً ثم الأحدث إنشاءً
|
||||
usort($result, function($a, $b) {
|
||||
// isDefault desc
|
||||
if ((int)$a['isDefault'] !== (int)$b['isDefault']) {
|
||||
return (int)$b['isDefault'] <=> (int)$a['isDefault'];
|
||||
}
|
||||
// created_at desc (لو أحدهم null لن يؤثر)
|
||||
return strcmp((string)$b['created_at'], (string)$a['created_at']);
|
||||
});
|
||||
|
||||
jsonSuccess($result);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database error (get_driver_cars): " . $e->getMessage());
|
||||
jsonError("Database error occurred");
|
||||
} catch (Throwable $e) {
|
||||
error_log("App error (get_driver_cars): " . $e->getMessage());
|
||||
jsonError("Unexpected error occurred");
|
||||
}
|
||||
Reference in New Issue
Block a user