<?php
include "../../../src/config.php";

if (!auth::user()) {
    endrequest("You dont have access to this api");
}

if (!isset($_GET["userid"])) {
    endrequest("Invalid request");
}

$query  = "select year(received) as y, month(received) as m, MONTHNAME(received) as m_name, count(*) as c from mis_letters group by year(received), month(received) order by y, m";

$response = database::query($query);

/*
$query  = "select year(received) as y, month(received) as m, MONTHNAME(received) as m_name, count(*) as c from mis_letters where assigned = :user group by year(received), month(received) order by y, m";

$response = database::query($query, ["user" => $_GET["userid"]]);
*/
echo json_encode($response);
