<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{
		/* start new code */
		
		$objSchedule = new ExamscheduleMgmt();
		$branch_id 		= $_POST['branch_hidden'];	
		$semester_id 	= $_POST['semester_hidden'];
		$exam_id 		= $_POST['exam_hidden'];	
		$subject_id 	= explode(",",$_POST['subject_id']);
		$daydate		= explode(",",$_POST['daydate']);
		$daytime 		= explode(",",$_POST['daytime']);
		$test_type 		= $_POST['test'];

		$sql_select = "SELECT * FROM cms_examschedule WHERE 
						branch_id = '".$branch_id."' AND 
		               	semester_id = '".$semester_id."' AND 
						exam_id = '".$exam_id."' AND 
						test_type = '".$test_type."' AND 
						year_id = ".$_SESSION["VedantnrYearId"];
		$res_select = dbQuery($sql_select);
		
		if(dbRows($res_select) > 0){
			$sql_delete = "DELETE FROM cms_examschedule WHERE 
							branch_id = '".$branch_id."' AND 
		                   	semester_id = '".$semester_id."' AND 
							exam_id = '".$exam_id."' AND
							test_type = '".$test_type."' AND
							year_id = ".$_SESSION["VedantnrYearId"];
			$res_delete = dbQuery($sql_delete);
		}
		
		$objSchedule->branch_id	= $branch_id;
		$objSchedule->semester_id	= $semester_id;
		$objSchedule->exam_id		= $exam_id;
		$objSchedule->test_type	= $test_type;
		
		for($i = 0; $i < count($subject_id); $i++){
			$objSchedule->subject_id	= $subject_id[$i];
			$objSchedule->daydate	 	= $daydate[$i];
			$objSchedule->daytime 		= $daytime[$i];
			$objSchedule->add();
		}
		/* end new code */
		
		echo '{"success":"true"}';
	}
	else
	{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>