MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/demo.imensosoftware.com/matrix/report_code.php
<?php
require_once 'config.php';

header('Content-Type: application/json');

// ================= INPUT =================
$start_date = $_POST['filter']['start_date'] ?? '';
$end_date   = $_POST['filter']['end_date'] ?? '';

// ================= DEFAULT =================
if(empty($start_date) || empty($end_date)) {
    $end_date = date('Y-m-d');
    $start_date = date('Y-m-d', strtotime('-7 days'));
}

// ================= QUERY (SECURE) =================
$stmt = $conn->prepare("
    SELECT 
        SUM(a.no_of_record) as total,
        a.submit_date,
        a.user_id,
        u.name as user_name
    FROM assignments a
    INNER JOIN users u ON u.id = a.user_id
    WHERE a.assignment_status_id = 2
    AND a.user_id = ?
    AND a.submit_date BETWEEN ? AND ?
    GROUP BY a.submit_date, a.user_id
    ORDER BY a.submit_date ASC
");

$stmt->bind_param("iss", $_SESSION['user_id'], $start_date, $end_date);
$stmt->execute();

$result = $stmt->get_result();

$chartData = [];

while($row = $result->fetch_assoc()) {
    $chartData[] = [
        "y" => (int)$row['total'],
        "label" => $row['submit_date'],
        "user_name" => $row['user_name'],
        "user_id" => $row['user_id']
    ];
}

// ================= RESPONSE =================
echo json_encode([
    "chartData" => $chartData
], JSON_NUMERIC_CHECK);