<?php  
	require "commonincludefiles.php";
	
	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{
		/* start new code */
		$objATKT = new ATKTMgmt();
		$branch_id 		= $_POST['branch_hidden'];	
		$semester_id 	= $_POST['semester_hidden'];
		$subject_id 	= $_POST['subject_hidden'];
		
		$status			= explode(",",$_POST['status']);
		$student_id 	= explode(",",$_POST['student_id']);
		
		$objATKT->branch_id		= $branch_id;
		$objATKT->semester_id	= $semester_id;
		$objATKT->subject_id	= $subject_id;		
		
		$sql_select = "SELECT * FROM cms_atktmaster WHERE branch_id = '".$branch_id."' AND 
		               semester_id = '".$semester_id."' AND subject_id = '".$subject_id."'
					   AND year_id = ".$_SESSION["VedantnrYearId"]." AND student_id IN(".$_POST['student_id'].") ";
		$res_select = dbQuery($sql_select);
		
		if(dbRows($res_select) > 0){
			$sql_delete = "DELETE FROM cms_atktmaster WHERE branch_id = '".$branch_id."' AND 
		               semester_id = '".$semester_id."' AND subject_id = '".$subject_id."'
					   AND year_id = ".$_SESSION["VedantnrYearId"]." AND student_id IN(".$_POST['student_id'].") ";
			$res_delete = dbQuery($sql_delete);
		}		
		
		for($i = 0; $i < count($student_id); $i++){			
			if($status[$i] == "true")
			{
				$objATKT->student_id = $student_id[$i];
				$objATKT->status	 = 1;
				$objATKT->add();
				
			}
		}
		/* end new code */
		
		echo '{"success":"true"}';
	}
	else
	{
		echo '{"success":"false","msg":"session expiry"}';
	}
?>