- 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
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
// Admin/v2/analytics/growth.php
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['error' => 'Unauthorized access.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// نمو الركاب لآخر 30 يوم
|
|
$stmt = $con->prepare("
|
|
SELECT DATE(created_at) as date, COUNT(*) as new_passengers
|
|
FROM passengers
|
|
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
|
GROUP BY DATE(created_at)
|
|
ORDER BY date ASC
|
|
");
|
|
$stmt->execute();
|
|
$passenger_growth = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// نمو السائقين لآخر 30 يوم
|
|
$stmt = $con->prepare("
|
|
SELECT DATE(created_at) as date, COUNT(*) as new_drivers
|
|
FROM driver
|
|
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
|
GROUP BY DATE(created_at)
|
|
ORDER BY date ASC
|
|
");
|
|
$stmt->execute();
|
|
$driver_growth = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// إجمالي الأعداد الحالية
|
|
$stmt = $con->prepare("SELECT COUNT(*) FROM passengers");
|
|
$stmt->execute();
|
|
$total_passengers = $stmt->fetchColumn();
|
|
|
|
$stmt = $con->prepare("SELECT COUNT(*) FROM driver");
|
|
$stmt->execute();
|
|
$total_drivers = $stmt->fetchColumn();
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => [
|
|
'passenger_daily' => $passenger_growth,
|
|
'driver_daily' => $driver_growth,
|
|
'totals' => [
|
|
'passengers' => (int)$total_passengers,
|
|
'drivers' => (int)$total_drivers
|
|
]
|
|
]
|
|
]);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
error_log("[growth.php] " . $e->getMessage());
|
|
echo json_encode(['status' => 'error', 'message' => 'An internal error occurred']);
|
|
}
|
|
?>
|