<?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();

$CourseTime = 0;
$EnrolledCourses = 0;
$SubmittedAssignments = 0;
$GradedAssignments = 0;
$AllAssignments = 0;
$HoursBooked = 0;

$sql_tlsn10 = "SELECT * FROM selfPacedLearners WHERE student_id='" . $_GET['student_id'] . "' ";
$result_tlsn10 = mysqli_query($conn, $sql_tlsn10);
$EnrolledCourses = mysqli_num_rows($result_tlsn10);

if (mysqli_num_rows($result_tlsn10) > 0) {
    while ($row_tlsn10 = mysqli_fetch_assoc($result_tlsn10)) {
        $CourseTime = (int)$row_tlsn10["CourseTime"] + (int)$row_tlsn10["CourseTime"];

        $sql_spc = "SELECT * FROM selfPacedLearnerAssignment WHERE selfPacedLearners_id='" . $row_tlsn10["selfPacedLearners_id"] . "' AND Status='Submitted'";
        $result_spc = mysqli_query($conn, $sql_spc);
        $SubmittedAssignments = mysqli_num_rows($result_spc);

        $sql_spc = "SELECT * FROM selfPacedLearnerAssignment WHERE selfPacedLearners_id='" . $row_tlsn10["selfPacedLearners_id"] . "' AND Status='Graded'";
        $result_spc = mysqli_query($conn, $sql_spc);
        $GradedAssignments = mysqli_num_rows($result_spc);

        $sql_spc = "SELECT * FROM selfPacedLearnerAssignment WHERE selfPacedLearners_id='" . $row_tlsn10["selfPacedLearners_id"] . "'";
        $result_spc = mysqli_query($conn, $sql_spc);
        $AllAssignments = mysqli_num_rows($result_spc);

        $sql_spc = "SELECT * FROM MentorLearnerSession WHERE  student_id='" . $_GET['student_id'] . "' ";
        $result_spc = mysqli_query($conn, $sql_spc);
        if (mysqli_num_rows($result_spc) > 0) {
            while ($row_spc = mysqli_fetch_assoc($result_spc)) {
                $HoursBooked = $row_spc["HoursBooked"] + (int)$row_spc["Duration"];
            }
        }
    }
}
$Percentage = ($GradedAssignments / $AllAssignments) * 100;
$curl_post_data = array(
    'CourseTime' => $CourseTime,
    'EnrolledCourses' => $EnrolledCourses,
    'SubmittedAssignments' => $SubmittedAssignments,
    'GradedAssignments' => $GradedAssignments,
    'AllAssignments' => $AllAssignments,
    'Percentage' => $Percentage,
    'HoursBooked' => $HoursBooked,

);
// array_push($data, $curl_post_data);
echo json_encode($curl_post_data);
