<?php
require "../commonincludefiles.php";

 if($_REQUEST['branch']!=""  && $_REQUEST['subject']!="" && $_REQUEST['day_date']!="" && $_REQUEST['lec_id']!="" && $_REQUEST['batch_id'] != "" )
 {
	 $branch		= 	Escape($_REQUEST['branch']);
	 $year		= 	Escape($_REQUEST['year']);
	 $branchyear	  = 	Escape($_REQUEST['branchyear']);
	 $semester	  = 	Escape($_REQUEST['semester']);
	 $subject	   = 	Escape($_REQUEST['subject']);
	 $batch_id	  = 	($_REQUEST['batch_id']==""?0:Escape($_REQUEST['batch_id']));
	 $lec_id		= 	Escape($_REQUEST['lec_id']);
	// $lectype	   = 	Escape($_REQUEST['lectype']);
	
	 $entrydate	 = 	date("Y-m-d",strtotime(Escape($_REQUEST['day_date'])));

	$condition="";
	
	if($branch != "" ){
		$condition .= " and branch_id ='$branch' ";
	}
	
	if($year != ""){
		$condition1 .= " and year_id ='$year' ";
	}

	if($branchyear != ""){
		$condition1 .= " and branchyear_id ='$branchyear' ";
	}

	if($semester != ""){
		$condition .= " and semester_id ='$semester' ";
	}
	
	
	if($subject != ""){
		$condition .= " and subject_id ='$subject' ";
	}
	
	if($entrydate != ""){
		$condition .= " and day_date='$entrydate' ";
	}
	
	//if($batch_id != "" && $batch_id != 0){
		$condition .= " and batch_id=$batch_id ";
	//}
	
	if($lec_id != ""){
		$condition .= " and lec_id In ($lec_id) ";
	}
	
	if($lectype != ""){
		//$condition .= " and lectype = '$lectype' ";
	}
	

	$objPresentMaster = new PresentMasterMgmt();	
	$out = $objPresentMaster ->getAllStudentPresent(0,0,$condition,"","");	
	$count=dbRows($out);
	
	$strStudentIds ="";
	$day_id =0;

	if($count > 0)
	{ 
		/*if($_SESSION["VedantnrUserRole"]!='PowerUser')
		{
			echo "{success:'true',day_id:'-3'}";
		}
		else
		{ */
			
			if($count > 1)
			{
				$day_id = -1;
				echo "{success:'true',day_id:'".$day_id."'}"; 	
			}
			else
			{
				if(strstr( $lec_id,",")!='')
				{
					$day_id = -1;
				echo "{success:'true',day_id:'".$day_id."'}"; 
				}
				else
				{
				$row = dbArray($out);		
				$day_id = $row["day_id"];
				echo "{success:'true',day_id:'".$day_id."'}"; 
				}
			}
		
		//}
	
	}
	else
	{
	$condition1="";
	
	if($branch != "" ){
		$condition1 .= " and branch_id ='$branch' ";
	}
	

	if($year != ""){
		$condition1 .= " and year_id ='$year' ";
	}

	if($branchyear != ""){
		$condition1 .= " and branchyear_id ='$branchyear' ";
	}
	if($semester != ""){
		$condition1 .= " and semester_id ='$semester' ";
	}


	if($entrydate != ""){
		$condition1 .= " and day_date='$entrydate' ";
	}
	
	//if($batch_id != "" && $batch_id != 0){
		$condition1 .= " and batch_id=$batch_id ";
	//}
	
	if($subject != ""){
		$condition1 .= " and subject_id ='$subject' ";
	}
	
	if($lec_id != ""){
		$condition1 .= " and lec_id In ($lec_id) ";
	}
	
	$objPresentMaster1 = new PresentMasterMgmt();	
	$out1 = $objPresentMaster1 ->getAllStudentPresent(0,0,$condition1,"","");	
	$count1=dbRows($out1);
	
//	echo $count1; 
	
	$day_id =0;

	if($count1 > 0)
	{ 
	echo "{success:'true',day_id:'-2'}";
	}
	else
	{
	echo "{success:'true',day_id:'0'}";
	}
	
}}
?>