Files
intaleq_v3_pure_php/ride/firebase/getTokenParent.php
2026-04-28 13:04:27 +03:00

45 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../../connect.php';
$phone = filterRequest("phone");
// 🔐 تشفير رقم الهاتف قبل البحث (لأنه مشفّر في قاعدة البيانات)
$phoneEncrypted = $encryptionHelper->encryptData($phone);
// 1⃣ جلب passengerID بناءً على رقم الهاتف
$sql = "SELECT `id` FROM `passengers` WHERE `phone` = :phone";
$stmt = $con->prepare($sql);
$stmt->bindParam(':phone', $phoneEncrypted);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
if ($data) {
$passengerID = $data['id'];
} else {
jsonError("No passenger found for the given phone number");
exit;
}
// 2⃣ جلب التوكنات المرتبطة بـ passengerID
$sql1 = "SELECT * FROM `tokens` WHERE `passengerID` = :passengerID";
$stmt = $con->prepare($sql1);
$stmt->bindParam(':passengerID', $passengerID);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($data) {
// فك تشفير التوكن فقط
foreach ($data as &$row) {
$row['token'] = $encryptionHelper->decryptData($row['token']);
// fingerPrint يبقى كما هو
}
echo json_encode([
'status' => 'success',
'count' => count($data),
'data' => $data
]);
} else {
jsonError("No tokens found for the passenger");
}
?>