<?php 
				

$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$course_id = $request->getParsedBody()['course_id'];
$season_id=$request->getParsedBody()['season_id'];
$exams_id=$request->getParsedBody()['exams_id'];
$dept_id=$request->getParsedBody()['dept_id'];
$level_id=$request->getParsedBody()['level_id'];
$year=$request->getParsedBody()['year'];
$term=$request->getParsedBody()['term'];
	$type=$request->getParsedBody()['type'];
	$papers_id=$request->getParsedBody()['papers_id'];
			


$resultEncoded = json_encode($papers_id);



$response=array();
$sqll="(SELECT * FROM assign_papers WHERE exams_id='$exams_id'AND course_id='$course_id' AND season_id='$season_id' AND year = '$year' AND term = '$term' AND type = '$type')";
$res= $con->query($sqll);
if ($res->num_rows > 0)
//if ($res->num_rows > 0)
{
$response1=array('status' => "true",'Message' => "data already exist");
echo json_encode($response1);
}

else{

$sql="INSERT INTO assign_papers(course_id,season_id,exams_id,dept_id,level_id,year,term,type,papers_id) VALUES 
('$course_id','$season_id','$exams_id','$dept_id',
'$level_id','$year','$term','$type','$resultEncoded')";

$res= $con->query($sql);
	
if($res==true)
{     
		$data=array(
	"course_id"=>$course_id,
	"season_id"=>$season_id,
	"exams_id"=>$exams_id,	
	"dept_id"=>$dept_id,
	"level_id"=>$level_id,
	"year"=>$year,
	"term"=>$term,
	"type"=>$type,
	"papers_id"=>$papers_id,
	
	
	
	);
	    $message=$data;

	$response=array('status' => "true",'Message' => "Data inserted successfully",'assign_papers' => $message);
echo json_encode($response);
        
}
        else{
          $response=array('status' => "false",'Message' => " insert data failed");
         echo json_encode($response);
        }   
		
}

?>