<?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 centerCourse WHERE centerClasses_id='".$_GET["centerClasses_id"]."'";
    // 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)) { 
            $course_name; $course_image; $class_name; $SessionName;
           
            $sql_clp="SELECT * FROM courses WHERE  course_id='".$row_d12['course_id']."'";
            $result_clp = mysqli_query($conn, $sql_clp);  
            if (mysqli_num_rows($result_clp) > 0) {
                while($row_clp = mysqli_fetch_assoc($result_clp)) {
                    $course_name=$row_clp["course_name"];
                    $course_image=$row_clp["course_image"];
                }
            }
            $sql_clp="SELECT * FROM curriculumSession WHERE  curriculumSession_id='".$row_d12['curriculumSession_id']."'";
            $result_clp = mysqli_query($conn, $sql_clp);  
            if (mysqli_num_rows($result_clp) > 0) {
                while($row_clp = mysqli_fetch_assoc($result_clp)) {
                    $SessionName=$row_clp["SessionName"];
                }
            }
            $sql_clp="SELECT * FROM centerClasses WHERE  centerClasses_id='".$row_d12['centerClasses_id']."'";
            $result_clp = mysqli_query($conn, $sql_clp);  
            if (mysqli_num_rows($result_clp) > 0) {
                while($row_clp = mysqli_fetch_assoc($result_clp)) {

                    $sql_10="SELECT * FROM classes WHERE  class_id='".$row_clp['class_id']."'";
                    $result_10 = mysqli_query($conn, $sql_10);  
                    if (mysqli_num_rows($result_10) > 0) {
                        while($row_10 = mysqli_fetch_assoc($result_10)) {
                            $class_name=$row_10["class_name"];
                        }
                    }
                }
            }
          
            $course_lesson_plan_id; $date_of_lesson;    
            $sql_clp="SELECT * FROM mentorLesson WHERE  centerCourse_id='".$row_d12['centerCourse_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;
                    $mentor_name; $mentor_email;
                    $Period; $StartTime;  $EndTime;
                    $sql_10="SELECT * FROM course_lesson_plan WHERE  course_lesson_plan_id='".$row_clp['course_lesson_plan_id']."'";
                    $result_10 = mysqli_query($conn, $sql_10);  
                    if (mysqli_num_rows($result_10) > 0) {
                        while($row_10 = mysqli_fetch_assoc($result_10)) {
                            $lesson_session=$row_10["lesson_session"];
                        }
                    }
                    $sql_10="SELECT * FROM mentors WHERE  mentor_id='".$row_clp['mentor_id']."'";
                    $result_10 = mysqli_query($conn, $sql_10);  
                    if (mysqli_num_rows($result_10) > 0) {
                        while($row_10 = mysqli_fetch_assoc($result_10)) {
                            $mentor_name=$row_10["mentor_name"];
                            $mentor_email=$row_10["mentor_email"];
                        }
                    }
                    $sql_10="SELECT * FROM timeSlots WHERE  timeSlots_id='".$row_clp['timeSlots_id']."'";
                    $result_10 = mysqli_query($conn, $sql_10);  
                    if (mysqli_num_rows($result_10) > 0) {
                        while($row_10 = mysqli_fetch_assoc($result_10)) {
                            $Period=$row_10["Period"];
                            $StartTime=$row_10["StartTime"];
                            $EndTime=$row_10["EndTime"];
                        }
                    }
                    $curl_post_data = array(
                        'course_id' => $row_d12["course_id"],
                        'course_name' => $course_name,
                        'course_image' => $course_image,
                        'class_name' => $class_name,
                        'SessionName' => $SessionName,
                        'mentor_name' => $mentor_name,
                        'mentor_email' => $mentor_email,
                        'lesson_session' => $lesson_session,
                        'course_lesson_plan_id' => $row_clp["course_lesson_plan_id"],
                        'date_of_lesson' => $row_clp["date_of_lesson"],
                        'mentorLesson_id' => $row_clp["mentorLesson_id"],
                        'centerCourse_id' => $row_d12["centerCourse_id"],
                        'centerClasses_id' => $row_d12["centerClasses_id"], 
                        'Period' => $Period,
                        'StartTime' => $StartTime,
                        'EndTime' => $EndTime,
                    );
                    array_push($data, $curl_post_data );
                }
            }
        }
    }
    echo json_encode($data);
?>