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

    $GradedAssignments = array();
    $IssuedAssignments = array();
    $SubmittedAssignments = array();
    $course_lesson_plan_ids=array();
    $sql_tlsn10 = "SELECT * FROM students WHERE student_id='".$_GET[ 'student_id' ]."' AND centerClasses_id='".$_GET[ 'centerClasses_id' ]."'";
    $result_tlsn10 = mysqli_query( $conn, $sql_tlsn10 );
    if ( mysqli_num_rows( $result_tlsn10 ) > 0 ) {
        while( $row_tlsn10 = mysqli_fetch_assoc( $result_tlsn10 ) ) {

         
            $sql_d12="SELECT * FROM centerCourse WHERE centerClasses_id='".$row_tlsn10["centerClasses_id"]."'";
            $result_d12 = mysqli_query($conn, $sql_d12);  
            if (mysqli_num_rows($result_d12) > 0) {
                while($row_d12 = mysqli_fetch_assoc($result_d12)) { 
             
                    $courseName; $courseImage;  $courseReg;
  
                    $courseRatings = array();
                    $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)) {
                            $courseName=$row_clp["course_name"];
                            $courseImage=$row_clp["course_image"];
                            $courseReg=$row_clp["course_id"];
                        }
                    }
             
                  
                    $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)) {

                           
                            $sql_10 = "select * from MentorStudentAssignment WHERE   student_id='".$_GET[ 'student_id' ]."'  AND  course_lesson_plan_id='".$row_clp[ 'course_lesson_plan_id' ]."' AND  mentorLesson_id='".$row_clp[ 'mentorLesson_id' ]."'  ";
                            $result_10 = mysqli_query( $conn, $sql_10 );

                            if ( mysqli_num_rows( $result_10 ) > 0 ) {
                                while( $row_10 = mysqli_fetch_assoc( $result_10 ) ) {
                                
                                    $lesson_sub_topic;
                                    $lesson_topic;
                                    $lesson_session;
                                 
                                    $sql_20 = "SELECT * FROM course_lesson_plan WHERE  course_lesson_plan_id='".$row_10[ 'course_lesson_plan_id' ]."'";
                                    $result_20 = mysqli_query( $conn, $sql_20 );

                                    if ( mysqli_num_rows( $result_20 ) > 0 ) {
                                        while( $row_20 = mysqli_fetch_assoc( $result_20 ) ) {

                                            $lesson_session = $row_20[ 'lesson_session' ];
                                            $lesson_topic = $row_20[ 'lesson_topic' ];
                                            $lesson_sub_topic = $row_20[ 'lesson_sub_topic' ];
                                           
                                        }
                                    }
                                    if($row_10["Status"]==="Issued"){

                                        $lesson_topic = array( 
                                            'lesson_topic' => $lesson_topic, 
                              
                                        );
                                        $curl_post_data = array(
                                            'id' => $row_10[ 'MentorStudentAssignment_id' ],
                                            'lesson_session' => $lesson_session,
                                            'course_image' =>  $courseImage,
                                            'course_name' =>$courseName,
                                            'lessonPlan' => $lesson_topic,
                                            'course_lesson_plan_id' => $row_10[ 'course_lesson_plan_id' ],
                                            'issueDate' => $row_10[ 'dated' ],
                              
                                        );
                                        array_push( $IssuedAssignments, $curl_post_data );
                                    }
                                    if($row_10["Status"]==="Graded"){

                                        $lesson_topic = array( 
                                            'lesson_topic' => $lesson_topic, 
                              
                                        );
                                        $curl_post_data = array(
                                            'id' => $row_10[ 'MentorStudentAssignment_id' ],
                                            'lesson_session' => $lesson_session,
                                            'course_image' =>  $courseImage,
                                            'course_name' =>$courseName,
                                            'lessonPlan' => $lesson_topic,
                                            'course_lesson_plan_id' => $row_10[ 'course_lesson_plan_id' ],
                                            'issueDate' => $row_10[ 'dated' ],
                              
                                        );
                                        array_push( $GradedAssignments, $curl_post_data );
                                    }
                                    if($row_10["Status"]==="Submitted"){

                                        $lesson_topic = array( 
                                            'lesson_topic' => $lesson_topic, 
                              
                                        );
                                        $curl_post_data = array(
                                            'id' => $row_10[ 'MentorStudentAssignment_id' ],
                                            'lesson_session' => $lesson_session,
                                            'course_image' =>  $courseImage,
                                            'course_name' =>$courseName,
                                            'lessonPlan' => $lesson_topic,
                                            'course_lesson_plan_id' => $row_10[ 'course_lesson_plan_id' ],
                                            'issueDate' => $row_10[ 'dated' ],
                              
                                        );
                                        array_push( $SubmittedAssignments, $curl_post_data );
                                    }
                                    $MentorStudentAssignmentRating_id = '';

                                    $Relevance = '';

                                    $WorkingCode = '';
                                    $Creativity = '';

                                    $TimelyCompletion = '';

                                    $Completion = '';
                                    $MentorComments = '';
                                }
                            }

                        }
                       
                        $courseName; $courseImage;  $courseReg;
   
                    }
                 
             

                }
            }
            $curl_post_data_graded = array( 
                'Status' =>  "Graded",
                'Assignments' =>$GradedAssignments,
  
            );
            $curl_post_data_issued = array( 
                'Status' =>  "Issued",
                'Assignments' =>$IssuedAssignments,
  
            );
            $curl_post_data_submitted = array( 
                'Status' =>  "Submitted",
                'Assignments' =>$SubmittedAssignments,
  
            ); 
           
           
        }
    }
    $curl_post_data = array( 
        $curl_post_data_graded = array( 
            'Status' =>  "Graded",
            'Assignments' =>$GradedAssignments,

        ),
        $curl_post_data_issued = array( 
            'Status' =>  "Issued",
            'Assignments' =>$IssuedAssignments,

        ),
        $curl_post_data_submitted = array( 
            'Status' =>  "Submitted",
            'Assignments' =>$SubmittedAssignments,

        )
    );
    // array_push( $data, $curl_post_data );
    echo json_encode($curl_post_data);
?>