= NOW() - INTERVAL :freshSeconds SECOND -- ⛓️ اختيار فقط الدراجات AND (cr.make LIKE '%دراج%' OR cr.model LIKE '%دراج%') ORDER BY ratingDriver DESC, -- ⭐ أولاً الأعلى تقييماً ratingCount DESC, -- ثم الأكثر حصولاً على تقييمات cl.updated_at DESC -- ثم الأحدث تحديثاً كفاصل LIMIT 10 "; $stmt = $con->prepare($sql); $stmt->bindValue(':southwestLat', $southwestLat); $stmt->bindValue(':southwestLon', $southwestLon); $stmt->bindValue(':northeastLat', $northeastLat); $stmt->bindValue(':northeastLon', $northeastLon); $stmt->bindValue(':freshSeconds', $freshSeconds, PDO::PARAM_INT); $stmt->execute(); $car_locations = $stmt->fetchAll(PDO::FETCH_ASSOC); if (!$car_locations) { printFailure("No car locations found"); exit; } // ✅ فك التشفير (مع حماية الأخطاء) $fieldsToDecrypt = [ 'phone','email','gender','birthdate', 'first_name','last_name','maritalStatus', 'token','make','car_plate','vin' ]; foreach ($car_locations as &$row) { foreach ($fieldsToDecrypt as $field) { if (isset($row[$field]) && $row[$field] !== null && $row[$field] !== '') { try { $row[$field] = $encryptionHelper->decryptData($row[$field]); } catch (Exception $e) { $row[$field] = null; // تجاهل فشل فك التشفير } } } // ✅ حساب العمر بعد فك التشفير if (!empty($row['birthdate'])) { try { $birthDate = new DateTime($row['birthdate']); $today = new DateTime(); $row['age'] = $today->diff($birthDate)->y; } catch (Exception $e) { $row['age'] = null; } } else { $row['age'] = null; } } unset($row); printSuccess($car_locations); } catch (PDOException $e) { printFailure("Database error: " . $e->getMessage()); } catch (Throwable $e) { printFailure("Internal error: " . $e->getMessage()); }