<?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 center_id='".$_GET["center_id"]."'";

    $result_d12 = mysqli_query($conn, $sql_d12);  
    if (mysqli_num_rows($result_d12) > 0) {
        while($row_d12 = mysqli_fetch_assoc($result_d12)) { 
            $course_name; $class_name; $SessionName;
            $course_image;
            $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;    $currdate= date("Y-m-d");  
            $sql_clp="SELECT * FROM teacherLesson WHERE  centerCourse_id='".$row_d12['centerCourse_id']."' AND date_of_lesson='".$currdate."'";
            $result_clp = mysqli_query($conn, $sql_clp);  
            if (mysqli_num_rows($result_clp) > 0) {
                while($row_clp = mysqli_fetch_assoc($result_clp)) {
                    $lesson_session;
                    $lesson_topic;
                    $TeacherFirstName; $TeacherLastName;
                    $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"];
                            $lesson_topic=$row_10["lesson_topic"];
                        }
                    }
                    $sql_10="SELECT * FROM teachers WHERE  teacher_id='".$row_clp['teacher_id']."'";
                    $result_10 = mysqli_query($conn, $sql_10);  
                    if (mysqli_num_rows($result_10) > 0) {
                        while($row_10 = mysqli_fetch_assoc($result_10)) {
                            $TeacherFirstName=$row_10["TeacherFirstName"];
                            $TeacherLastName=$row_10["TeacherLastName"];
                        }
                    }
                    $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_name' => $course_name,
                        'course_image' => $course_image,
                        'class_name' => $class_name,
                        'SessionName' => $SessionName,
                        'TeacherFirstName' => $TeacherFirstName,
                        'TeacherLastName' => $TeacherLastName,
                        'lesson_session' => $lesson_session,
                        'lesson_topic' => $lesson_topic,
                        'course_lesson_plan_id' => $row_clp["course_lesson_plan_id"],
                        'date_of_lesson' => $row_clp["date_of_lesson"],
                        'Period' => $Period,
                        'StartTime' => $StartTime,
                        'EndTime' => $EndTime,
                    );
                    array_push($data, $curl_post_data );
                }
            }
        }
    }
    echo json_encode($data);
?>