<?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();
$allData = array();


$course_lesson_plan_ids = array();
$sql_d12 = "SELECT * FROM MentorAdultOnlineSession WHERE AdultStudent_id='" . $_GET["AdultStudent_id"] . "'   ORDER BY dated DESC";
// echo $sql_d12;
$result_d12 = mysqli_query($conn, $sql_d12);
if (mysqli_num_rows($result_d12) > 0) {
    while ($row_d12 = mysqli_fetch_assoc($result_d12)) {
        $mentor_name = "";
        $mentor_email = "";
        $mentor_image = "";
        $mentor_phone = "";

        $sql_clp = "SELECT * FROM mentors WHERE  mentor_id='" . $row_d12['mentor_id'] . "'";
        $result_clp = mysqli_query($conn, $sql_clp);
        if (mysqli_num_rows($result_clp) > 0) {
            while ($row_clp = mysqli_fetch_assoc($result_clp)) {
                $mentor_name = $row_clp["mentor_name"];
                $mentor_phone = $row_clp["mentor_phone"];
                $mentor_email = $row_clp["mentor_email"];
                $mentor_image = $row_clp["mentor_image"];
            }
        }
        $course_name = "";
        $course_image = "";
        $lesson_session = "";
        $lesson_topic = "";
        $lesson_sub_topic = "";
        $SessionTime = "";
        $Status = "";
        $Updated = "";
        $SelfPacedCourses_id = "";
        $sql_clp = "SELECT * FROM selfPacedAdultStudentSession WHERE  selfPacedAdultStudentSession_id='" . $row_d12['selfPacedAdultStudentSession_id'] . "'";
        $result_clp = mysqli_query($conn, $sql_clp);
        if (mysqli_num_rows($result_clp) > 0) {
            while ($row_clp = mysqli_fetch_assoc($result_clp)) {
                $SelfPacedCourses_id = $row_clp["SelfPacedCourses_id"];

                $sql_spc = "SELECT * FROM SelfPacedCourses WHERE  SelfPacedCourses_id='" . $row_clp['SelfPacedCourses_id'] . "'";
                $result_spc = mysqli_query($conn, $sql_spc);
                if (mysqli_num_rows($result_spc) > 0) {
                    while ($row_spc = mysqli_fetch_assoc($result_spc)) {
                        $sql_crs = "SELECT * FROM courses WHERE  course_id='" . $row_spc['courses_id'] . "'";
                        $result_crs = mysqli_query($conn, $sql_crs);
                        if (mysqli_num_rows($result_crs) > 0) {
                            while ($row_crs = mysqli_fetch_assoc($result_crs)) {
                                $course_name = $row_crs["course_name"];
                                $course_image = $row_crs["course_image"];
                            }
                        }
                    }
                }
                $sql_clp = "SELECT * FROM course_lesson_plan WHERE  course_lesson_plan_id='" . $row_clp['course_lesson_plan_id'] . "'";
                $result_clp = mysqli_query($conn, $sql_clp);
                if (mysqli_num_rows($result_clp) > 0) {
                    while ($row_clp = mysqli_fetch_assoc($result_clp)) {
                        $lesson_session = $row_clp["lesson_session"];
                        $lesson_topic = $row_clp["lesson_topic"];
                        $lesson_sub_topic = $row_clp["lesson_sub_topic"];
                    }
                }
                $SessionTime = $row_clp["SessionTime"];
                $Status = $row_clp["Status"];
                $Updated = $row_clp["Updated"];
            }
        }

        $curl_post_data = array(
            'MentorAdultOnlineSession_id' => $row_d12["MentorAdultOnlineSession_id"],
            'course_name' => $course_name,
            'course_image' => $course_image,
            'mentor_phone' => $mentor_phone,
            'mentor_name' => $mentor_name,
            'mentor_email' => $mentor_email,
            'mentor_image' => $mentor_image,
            'mentor_id' => $row_d12["mentor_id"],
            'AdultStudent_id' => $row_d12["AdultStudent_id"],
            'course_id' => $row_d12["course_id"],
            'LearnerComment' => $row_d12["LearnerComment"],
            'MentorComment' => $row_d12["MentorComment"],
            'SessionDate' => $row_d12["SessionDate"],
            'LearnerUpdateTime' => $row_d12["LearnerUpdateTime"],
            'TeacherUpdateTime' => $row_d12["TeacherUpdateTime"],
            'SessionDate' => $row_d12["SessionDate"],
            'StartTime' => $row_d12["StartTime"],
            'EndTime' => $row_d12["EndTime"],
            'Price' => $row_d12["Price"],
            'Duration' => $row_d12["Duration"],
            'Status' => $row_d12["Status"],
            'Location' => $row_d12["Location"],
            'MeetingLink' => $row_d12["MeetingLink"],
            'SelfPacedCourses_id' => $SelfPacedCourses_id,
            'lesson_session' => $lesson_session,
            'lesson_topic' => $lesson_topic,
            'lesson_sub_topic' => $lesson_sub_topic,
            'SessionTime' => $SessionTime,
            'Status' => $Status,
            'Updated' => $Updated,
        );
        array_push($data, $curl_post_data);
    }
}
echo json_encode($data);
