Files
Siro/backend/Admin/v2/smart_alerts.php
Hamza-Ayed 72eeb24cd7 Fix #18: Exception leak remediation across 87 PHP files
- Replaced all client-facing $e->getMessage() with generic error messages
- Added error_log() with filename prefix to all catch blocks
- Covered jsonError(), echo, and json_encode() response patterns
- Also fixed 2 remaining display_errors=1 and add_invoice.php leak
- Script-assisted fix for 75 files, manual fix for 12 remaining edge cases
2026-06-17 07:48:31 +03:00

79 lines
3.2 KiB
PHP

<?php
// Admin/v2/smart_alerts.php
require_once __DIR__ . '/../../connect.php';
// التحقق من الصلاحيات
if ($role !== 'admin' && $role !== 'super_admin') {
http_response_code(403);
echo json_encode(['error' => 'Unauthorized access. Admin role required.']);
exit;
}
$alerts = [];
try {
// 1. شكاوى جديدة غير محلولة (مفتوحة)
$stmt = $con->prepare("SELECT id, ride_id, complaint_type, date_filed FROM complaint WHERE statusComplaint = 'Open' ORDER BY date_filed DESC LIMIT 10");
$stmt->execute();
$open_complaints = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($open_complaints as $c) {
$alerts[] = [
'type' => 'complaint',
'severity' => 'high',
'title' => 'شكوى جديدة (' . $c['complaint_type'] . ')',
'description' => "يوجد شكوى جديدة للرحلة رقم " . $c['ride_id'] . " تحتاج للمراجعة.",
'date' => $c['date_filed'],
'action_id' => $c['id']
];
}
// 2. رحلات عالقة (في الانتظار لأكثر من 15 دقيقة)
$stmt = $con->prepare("SELECT id, created_at FROM ride WHERE status = 'wait' AND created_at < DATE_SUB(NOW(), INTERVAL 15 MINUTE) LIMIT 10");
$stmt->execute();
$stuck_rides = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($stuck_rides as $r) {
$alerts[] = [
'type' => 'ride',
'severity' => 'medium',
'title' => 'رحلة عالقة قيد الانتظار',
'description' => "الرحلة رقم " . $r['id'] . " عالقة في حالة انتظار لأكثر من 15 دقيقة.",
'date' => $r['created_at'],
'action_id' => $r['id']
];
}
// 3. رخص قيادة شارفت على الانتهاء (خلال 15 يوم القادمة)
$stmt = $con->prepare("SELECT id, first_name, last_name, phone, expiry_date FROM driver WHERE expiry_date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) LIMIT 10");
$stmt->execute();
$expiring_drivers = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($expiring_drivers as $d) {
// فك تشفير البيانات الحساسة
$firstName = $encryptionHelper->decryptData($d['first_name']);
$lastName = $encryptionHelper->decryptData($d['last_name']);
$alerts[] = [
'type' => 'license',
'severity' => 'warning',
'title' => 'رخصة كابتن قاربت على الانتهاء',
'description' => "رخصة الكابتن " . $firstName . " " . $lastName . " ستنتهي بتاريخ " . $d['expiry_date'] . ".",
'date' => date('Y-m-d H:i:s'),
'action_id' => $d['id']
];
}
// ترتيب التنبيهات حسب الأحدث
usort($alerts, function($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});
echo json_encode([
'status' => 'success',
'message' => $alerts
]);
} catch (Exception $e) {
http_response_code(500);
error_log("[smart_alerts.php] " . $e->getMessage());
echo json_encode(['status' => 'error', 'message' => 'An internal error occurred']);
}
?>