<?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 learner_assignment WHERE course_lesson_plan_id='".$_GET["course_lesson_plan_id"]."' AND learner_id='".$_GET["learner_id"]."'";
    $result = mysqli_query($conn, $sql);  
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_assoc($result)) {
            $reason="";
            $mentor_comments="";
            $assignment="";
            $relevance="";
            $working_code="";
            $creativity="";
            $timely_completion="";
            $completion="";
            if($row["status"]=="Rejected"){
                if(file_exists("/home/sendusco/lms.digifunzi.com/".$row['reason'])){
                    $reason =file_get_contents("/home/sendusco/lms.digifunzi.com/".$row["reason"]);
                }
            }else{
                $sql_1="SELECT * FROM learner_assignment_rating WHERE learner_assignment_id='".$row["learner_assignment_id"]."'";
                $result_1 = mysqli_query($conn, $sql_1);  
                if (mysqli_num_rows($result_1) > 0) {
                    while($row_1 = mysqli_fetch_assoc($result_1)) {
                        $relevance=$row_1["relevance"];
                        $working_code=$row_1["working_code"];
                        $creativity=$row_1["creativity"];
                        $timely_completion=$row_1["timely_completion"];
                        $completion=$row_1["completion"];
                        $mentor_comments=$row_1["mentor_comments"];
                        // if(file_exists("/home/sendusco/lms.digifunzi.com/".$row['mentor_comments'])){
                        //     $mentor_comments =file_get_contents("/home/sendusco/lms.digifunzi.com/".$row["mentor_comments"]);
                        // }
                    }
                }
            }
            $courses=array();
            $sql_1="SELECT * FROM course_lesson_assignment WHERE course_lesson_plan_id='".$_GET["course_lesson_plan_id"]."'";
            $result_1 = mysqli_query($conn, $sql_1);  
            if (mysqli_num_rows($result_1) > 0) {
                while($row_1 = mysqli_fetch_assoc($result_1)) {
                    $assignment=$row_1["assignment"];
                    // if(file_exists("/home/sendusco/lms.digifunzi.com/".$row_1['assignment'])){
                    //     $assignment =file_get_contents("/home/sendusco/lms.digifunzi.com/".$row_1["assignment"]);
                    // }
                   
            
                }
            }

            $curl_post_data = array(
                'learner_assignment_id' => $row["learner_assignment_id"] ,
                'status' => $row["status"] ,
                'assignment' => $assignment ,
                'learner_assignment' => $row["assignment"] ,
                'mentor_comments' => $mentor_comments ,
                'reason' => $reason ,
                'relevance' => $relevance ,
                'working_code' => $working_code ,
                'creativity' => $creativity ,
                'timely_completion' => $timely_completion ,
                'completion' => $completion ,
                'courses' => $courses ,
            );
            array_push($data, $curl_post_data );



      
        }
    }else{
        $sql_b12 = "INSERT INTO learner_assignment VALUES (NULL,
            '".$_GET["learner_id"]."',
            '".$_GET["course_lesson_plan_id"]."',
            'none',
            'Pending',
            'false',
            now())";
        if (mysqli_query($conn, $sql_b12)) {
            $learner_assignment_id = mysqli_insert_id($conn);
        }
    }


    echo json_encode($data);


   
        
?>