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


    $sql="SELECT * FROM course_lesson_structure WHERE course_lesson_plan_id='".$_GET["course_lesson_plan_id"]."' ";
    $result = mysqli_query($conn, $sql);  
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $concepts=array();
            $courses=array();
            $sql_g10="SELECT * FROM course_lesson_plan WHERE course_lesson_plan_id='".$row["course_lesson_plan_id"]."'";
            $result_g10 = mysqli_query($conn, $sql_g10);  
            if (mysqli_num_rows($result_g10) > 0) {
                while($row_g10 = mysqli_fetch_assoc($result_g10)) {
                    $sql_g="SELECT * FROM courses WHERE course_id='".$row_g10["course_id"]."'";
                    $result_g = mysqli_query($conn, $sql_g);  
                    if (mysqli_num_rows($result_g) > 0) {
                        while($row_g = mysqli_fetch_assoc($result_g)) {
                            $curl_post_data = array(
                                'course_id' => $row_g["course_id"] ,
                                'course_name' => $row_g["course_name"] ,
                                'course_image' => $row_g["course_image"] ,
                                'course_description' => $row_g["course_description"] ,
                                'expected_outcome' => $row_g["expected_outcome"] ,
                                'delivery_mode' => $row_g["delivery_mode"] ,
                                'minimum_age' => $row_g["minimum_age"] ,
                                'required_sessions' => $row_g["required_sessions"] ,
                                'active' => $row_g["active"] ,
                                'lesson_session' => $row_g10["lesson_session"] ,
                                'lesson_topic' => $row_g10["lesson_topic"] ,
                                'lesson_sub_topic' => $row_g10["lesson_sub_topic"] ,
             
                            );
                            array_push($courses, $curl_post_data );
                        }
                    }
                }
            }

            $sql_g="SELECT * FROM course_lesson_structure_concepts WHERE course_lesson_structure_id='".$row["course_lesson_structure_id"]."'";
            $result_g = mysqli_query($conn, $sql_g);  
            if (mysqli_num_rows($result_g) > 0) {
                while($row_g = mysqli_fetch_assoc($result_g)) {
                    $concept="";
                    if(file_exists("/home/sendusco/lms.digifunzi.com/".$row_g['concept'])){
                        $concept =file_get_contents("/home/sendusco/lms.digifunzi.com/".$row_g["concept"]);
                    }
                    $curl_post_data = array(
                        'concept_name' => $row_g["concept_name"] ,
                        'concept_time' => $row_g["concept_time"] ,
                        'concept' => $concept,
                    );
                    array_push($concepts, $curl_post_data );
                }
            }

            $curl_post_data = array(
                'course_lesson_structure_id' => $row["course_lesson_structure_id"] ,
                'introduction' => $row["introduction"] ,
                'introduction_time' => $row["introduction_time"],
                'ice_breaker' => $row["ice_breaker"] ,
                'ice_breaker_time' => $row["ice_breaker_time"] ,
                'class_activity' => $row["class_activity"],
                'class_activity_time' => $row["class_activity_time"] ,
                'wrap_activity' => $row["wrap_activity"] ,
                'wrap_activity_time' => $row["wrap_activity_time"],
                'teachers_notes' => $row["teachers_notes"] ,
                'examples' => $row["examples"] ,
                'concepts' => $concepts ,
                'courses' => $courses ,
            );
            array_push($data, $curl_post_data );
        }
    }

    echo json_encode($data);
?>