= NOW() - INTERVAL :freshSeconds SECOND AND COALESCE(cr.year, 0) < 2000 AND (cr.make NOT LIKE '%دراج%' AND cr.model NOT LIKE '%دراج%') ORDER BY ratingDriver DESC, -- ⭐ الأولوية للتقييم ratingCount DESC, -- ثم الأكثر حصولاً على تقييمات cl.updated_at DESC -- ثم الأحدث تحديثًا كفاصل LIMIT 5 "; $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(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); if (!$rows) { printFailure("No car locations found"); exit; } // تفكيك التشفير + حساب العمر $fieldsToDecrypt = [ 'phone','email','gender','birthdate', 'first_name','last_name','maritalStatus', 'token','make','car_plate','vin' ]; foreach ($rows 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($rows); } catch (PDOException $e) { printFailure("Database error: " . $e->getMessage()); } catch (Throwable $e) { printFailure("Internal error: " . $e->getMessage()); }