first commit
This commit is contained in:
87
backend/serviceapp/web/getDrivers.php
Executable file
87
backend/serviceapp/web/getDrivers.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// إعدادات الإنتاج (إخفاء الأخطاء عن المستخدم)
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// ضبط الترويسة والترميز UTF-8 هام جداً للنصوص العربية
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
require_once __DIR__ . '/../../get_connect.php';
|
||||
|
||||
// ضمان خروج النصوص العربية من قاعدة البيانات بشكل سليم
|
||||
if (isset($con)) {
|
||||
$con->exec("set names utf8mb4");
|
||||
}
|
||||
|
||||
$phone = "";
|
||||
if (isset($_GET['phone_number'])) {
|
||||
$phone = htmlspecialchars(strip_tags($_GET['phone_number']));
|
||||
} elseif (isset($_POST['phone_number'])) {
|
||||
$phone = htmlspecialchars(strip_tags($_POST['phone_number']));
|
||||
} else {
|
||||
$phone = filterRequest("phone_number");
|
||||
}
|
||||
|
||||
if (empty($phone)) {
|
||||
jsonError("Phone number is required");
|
||||
exit;
|
||||
}
|
||||
|
||||
// تشفير الرقم للبحث
|
||||
$phoneEncrypted = $encryptionHelper->encryptData($phone);
|
||||
|
||||
// الاستعلام: نختار الحقول بدقة لتجنب التضارب
|
||||
$sql = "SELECT
|
||||
d.id as driver_id,
|
||||
d.name_arabic as driver_name_encrypted, -- الاسم من جدول السائق
|
||||
d.phone as phone_encrypted,
|
||||
d.gender as gender_encrypted
|
||||
|
||||
FROM
|
||||
`driver` d
|
||||
|
||||
WHERE
|
||||
d.phone = ?
|
||||
LIMIT 1";
|
||||
|
||||
try {
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([$phoneEncrypted]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($rows as &$item) {
|
||||
// ============================================
|
||||
// 1. فك تشفير الحقول المشفرة فقط (حسب ملف CSV)
|
||||
// ============================================
|
||||
|
||||
// بيانات السائق
|
||||
if (!empty($item['driver_name_encrypted'])) {
|
||||
$item['driverName'] = $encryptionHelper->decryptData($item['driver_name_encrypted']);
|
||||
}
|
||||
if (!empty($item['phone_encrypted'])) {
|
||||
$item['phone'] = $encryptionHelper->decryptData($item['phone_encrypted']);
|
||||
}
|
||||
if (!empty($item['gender_encrypted'])) {
|
||||
$item['gender'] = $encryptionHelper->decryptData($item['gender_encrypted']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
jsonSuccess($rows);
|
||||
|
||||
} else {
|
||||
jsonError("No driver found with this phone number");
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("SQL Error: " . $e->getMessage());
|
||||
jsonError("Database error");
|
||||
} catch (Exception $e) {
|
||||
error_log("General Error: " . $e->getMessage());
|
||||
jsonError("System error");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user