<?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 centerCourse WHERE center_id='".$_GET["center_id"]."'";
    $result = mysqli_query($conn, $sql); 
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $course_name; $mentors = array(); $class_name; $SessionName;
            $sql1="SELECT * FROM courses WHERE course_id='".$row["course_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $course_name=  $row1["course_name"];
                }
            }
            $sql1="SELECT * FROM curriculumSession WHERE curriculumSession_id='".$row["curriculumSession_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $SessionName=  $row1["SessionName"];
                }
            }
            $sql1="SELECT * FROM centerClasses WHERE centerClasses_id='".$row["centerClasses_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $sql10="SELECT * FROM classes WHERE class_id='".$row1["class_id"]."' ";
                    $result10 = mysqli_query($conn, $sql10); 
                    if (mysqli_num_rows($result10) > 0) {
                        while($row10 = mysqli_fetch_assoc($result10)) {
                            $class_name=$row10["class_name"];
                        }
                    }
                }
            }
            $sql1="SELECT * FROM mentorCourse WHERE course_id='".$row["course_id"]."' AND center_id='".$row["center_id"]."' ";
            $result1 = mysqli_query($conn, $sql1); 
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    $sql10="SELECT * FROM mentors WHERE mentor_id='".$row1["mentor_id"]."' ";
                    $result10 = mysqli_query($conn, $sql10); 
                    if (mysqli_num_rows($result10) > 0) {
                        while($row10 = mysqli_fetch_assoc($result10)) {
                            $curl_post_data = array(
                                'mentor_id' => $row1["mentor_id"],
                                'mentor' => $row10["mentor_name"],
                                'mentorCourse_id' => $row1["mentorCourse_id"],
                            );
                          
                            array_push($mentors, $curl_post_data);
                        }
                    }
                }
            }
            $curl_post_data = array(
                'centerCourse_id' => $row["centerCourse_id"],
                'centerClasses_id' => $row["centerClasses_id"],
                'curriculumSession_id' => $row["curriculumSession_id"],
                'course_id' => $row["course_id"],
                'course_name' => $course_name,
                'class_name' => $class_name,
                'SessionName' => $SessionName,
                'mentors' => $mentors,
            );
          
            array_push($data, $curl_post_data);
        }
    }
    echo json_encode($data);
 


?>