<?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';
    // var_dump($_GET);
    if($_GET["YearStatus"]==="true"){
        $sql1="SELECT * FROM curriculumEnrollment WHERE Status='true' AND curriculum_id='".$_GET['curriculum_id']."'";
        // echo $sql1;
        $result1 = mysqli_query($conn, $sql1); 
        if (mysqli_num_rows($result1) > 0) {
            while($row1 = mysqli_fetch_assoc($result1)) {
                $sql_C = "UPDATE curriculumEnrollment SET
                    Status='false'
                    WHERE curriculumEnrollment_id=".$row1["curriculumEnrollment_id"];
                    // echo $sql_C; 
                if (mysqli_query($conn, $sql_C)) {
                }
            }
        }
       
    }


    $sql = "INSERT INTO curriculumEnrollment VALUES (NULL,
        '".$_GET['curriculum_id']."',
        '".$_GET["YearName"]."',
        '".$_GET["StartYear"]."',
        '".$_GET["EndYear"]."',
        '".$_GET["YearStatus"]."',
        now())";
      
    if (mysqli_query($conn, $sql)) {
        $curriculumEnrollment_id = mysqli_insert_id($conn);
        if($_GET["YearStatus"]==="true"){
            $sql_C = "UPDATE curriculum SET
                curriculumEnrollment_id='".$curriculumEnrollment_id."'
                WHERE curriculum_id=".$_GET["curriculum_id"];
            if (mysqli_query($conn, $sql_C)) {
            }
        }
        $i=1;
    
         
        $curl_GET_data = array(
            'Success' => 'true',
            'curriculumEnrollment_id' => $curriculumEnrollment_id ,
        );
        echo json_encode($curl_GET_data);  
    } else {

        $curl_GET_data = array(
            'Success' => 'false',
            'curriculumEnrollment_id' => '', 
        );
        echo json_encode($curl_GET_data);              
    }
    
?>