<?php
if(isset($_POST['state'])){
require_once('../../assets/config/config.php');
$obj=new Database();

	if($_POST['state']=='exam'){
		$batch_no=$_POST['batch_no'];
		$s_id=$_POST['s_id'];
		$s_name=$_POST['s_name'];
		$c_name=$_POST['c_name'];
		$e_type=$_POST['e_type'];
		$ht_no=$_POST['ht_no'];
		$e_center=$_POST['e_center'];
		$e_date=date("d-M-Y",strtotime($_POST['e_date']));
		$e_time=date("h:i A",strtotime($_POST['e_time']));
		$desc=$_POST['desc'];
		$file_name=$_FILES['file']['name'];
		if (isset($_FILES['file']['name']))
		{
		// If the ‘pdf_file’ field has an attachment
			$file_name = $_FILES['file']['name'];
			$file_tmp = $_FILES['file']['tmp_name'];
			
			// Move the uploaded pdf file into the pdf folder
			move_uploaded_file($file_tmp,"../ac/".$file_name);                 
			$status=$obj->insert('student_exam',['batch_no'=>$batch_no,'student_id'=>$s_id,'student_name'=>$s_name,'exam_name'=>$c_name,'exam_type'=>$e_type,'exam_type'=>$e_type,'ht_no'=>$ht_no,'exam_center'=>$e_center,'exam_date'=>$e_date,'exam_time'=>$e_time,'ac_path'=>$file_name]);
			if($status==1)
			{
				echo "<script>
				window.location.href ='../student-exam.php?msg=1';</script>";
			}
		}
	}
	if($_POST['state']=='result'){
		$id="id=".$_POST['_type'];
		$er_date=date("d-M-Y",strtotime($_POST['er_date']));
		$status=$_POST['status'];
		$file_name=$_FILES['file']['name'];
		if (isset($_FILES['file']['name']))
		{
		// If the ‘pdf_file’ field has an attachment
			$file_name = $_FILES['file']['name'];
			$file_tmp = $_FILES['file']['tmp_name'];
			
			// Move the uploaded pdf file into the pdf folder
			move_uploaded_file($file_tmp,"../result/".$file_name);                 
			$status=$obj->update('student_exam',['er_date'=>$er_date,'result_status'=>$status,'r_path'=>$file_name],$id);
			if($status==1)
			{
				echo "<script>
				window.location.href ='../results.php?msg=1';</script>";
			}
		}
	}
}
?>