<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
include '../../../config/index.php';

$data = array();


$weekCount = 1;


$sql_clp = "SELECT YEARWEEK(StartTime, 1) AS week_number, SUM(Duration) / 60 AS hours FROM ( SELECT StartTime, Duration FROM MentorTeacherSession UNION ALL SELECT StartTime, Duration FROM MentorLearnerOnlineSession) AS combined WHERE StartTime >= DATE_SUB(CURDATE(), INTERVAL 6 WEEK) GROUP BY YEARWEEK(StartTime, 1) ORDER BY week_number DESC ";
// echo $sql_clp;
$result_clp = mysqli_query($conn, $sql_clp);
if (mysqli_num_rows($result_clp) > 0) {
    while ($row_clp = mysqli_fetch_assoc($result_clp)) {


        $curl_post_data = array(
            'week' => "Week " . $weekCount,
            'hours' => (float)$row_clp["hours"]

        );
        array_push($data, $curl_post_data);
        $weekCount++;
    }
}


echo json_encode($data);
