- 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
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../connect.php';
|
|
|
|
error_reporting(0);
|
|
header('Content-Type: application/json');
|
|
|
|
// 1. استقبال التواريخ
|
|
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
|
|
$start_date = $_POST['start_date'];
|
|
$end_date = $_POST['end_date'];
|
|
} else {
|
|
// Fallback: الافتراضي هو الشهر الحالي
|
|
$current_month = isset($_POST['month']) ? str_pad($_POST['month'], 2, "0", STR_PAD_LEFT) : date('m');
|
|
$current_year = isset($_POST['year']) ? $_POST['year'] : date('Y');
|
|
|
|
$start_date = date('Y-m-d', strtotime($current_year . '-' . $current_month . '-01'));
|
|
$end_date = date('Y-m-t', strtotime($start_date));
|
|
}
|
|
|
|
// 2. الاستعلام: تجميع عدد الملاحظات لكل موظف في كل يوم
|
|
$sql = "
|
|
SELECT
|
|
DATE(createdAt) as date,
|
|
editor as NAME,
|
|
COUNT(*) as count
|
|
FROM
|
|
notesForDriverService
|
|
WHERE
|
|
createdAt BETWEEN :start_date AND :end_date
|
|
GROUP BY
|
|
DATE(createdAt), editor
|
|
ORDER BY
|
|
date ASC
|
|
";
|
|
|
|
try {
|
|
$end_date_full = $end_date . ' 23:59:59';
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([':start_date' => $start_date, ':end_date' => $end_date_full]);
|
|
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($data) {
|
|
echo json_encode(array("status" => "success", "message" => $data));
|
|
} else {
|
|
echo json_encode(array("status" => "success", "message" => []));
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo json_encode(array("status" => "failure", "message" => "An internal error occurred"));
|
|
}
|
|
?>
|