<?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= file_get_contents('php://input');
   
    // $obj = json_decode($data, true);

    
    $sql_we = 'INSERT INTO self_paced_teachers VALUES (NULL,
            "'.$_GET["teacher_id"].'",
            "'.$_GET["Supervisor"].'",
            "'.$_GET["Course"].'",
            "'.$_GET["Serialized"].'",
            "'.$_GET["AccessResource"].'",
            "'.$_GET["PassCriteria"].'",
            "'.$_GET["StartDate"].'",
            "'.$_GET["EndDate"].'",
            "false",
            "false",
            now())';
        if (mysqli_query($conn, $sql_we)) {
            $self_paced_teachers_id = mysqli_insert_id($conn);
            $i=0;
            $sql1="SELECT * FROM course_lesson_plan WHERE course_id='".$_GET["Course"]."'";
            $result1 = mysqli_query($conn, $sql1);  
            if (mysqli_num_rows($result1) > 0) {
                while($row1 = mysqli_fetch_assoc($result1)) {
                    if($i==0){
                        $assignment_status="Issued";
                    }else{
                        $assignment_status="Not Issued";
                    }
                    $sql_i = 'INSERT INTO self_paced_teacher_assignment VALUES (NULL,
                        "'.$self_paced_teachers_id.'",
                        "'.$_GET["teacher_id"].'",
                        "'.$_GET["Course"].'",
                        "'.$row1["course_lesson_plan_id"].'",
                        "false",
                        "'.$assignment_status.'",
                        "",
                        now(),
                        now())';
            
                    if (mysqli_query($conn, $sql_i)) {
                    }else{
                        
                    }
                    $i=$i+1;
                }
            }
            $curl_post_data = array(
                'Success' => 'true',
                'self_paced_teachers_id' => $self_paced_teachers_id,
            );
            echo json_encode($curl_post_data);
        }else{
            $curl_post_data = array(
                'Success' => 'false',
                'self_paced_teachers_id' => '',
            );
            echo json_encode($curl_post_data);
        }
    


?>