<?php

	require "../commonincludefiles.php";
	
 	$arr = array();
 	$total = 0;
	// echo $_REQUEST['shift1'];
	// && $_REQUEST['shift1']!=""
	//AND sm.shift = '".$_REQUEST['shift1']."' 
	
	if($_REQUEST['branch_id']!=""  && $_REQUEST['subject_id']!=""  )
	{
				
		if($_REQUEST['day_id']=="")
		{
		if (($_REQUEST['branch_id'])!=""){
			$where .= "  AND sd.cur_branchid = '".Escape($_REQUEST['branch_id'])."' ";
		}

		if (($_REQUEST['year_id'])!=""){
			$where .= " AND sd.year_id = '".Escape($_REQUEST['year_id'])."' ";
		}

		if (($_REQUEST['branchyear_id'])!=""){
			$where .= " AND sd.cur_branchyearid = '".Escape($_REQUEST['branchyear_id'])."' ";
		}

		if (($_REQUEST['semester_id'])!=""){
			$where .= " AND sd.cur_semesterid = '".Escape($_REQUEST['semester_id'])."' ";
		}

		if($_REQUEST['batch_id'] != '0'){
			$where .=	"AND sd.batch_id = '".Escape($_REQUEST['batch_id'])."' ";
		}
		$objStudentMgmt = new StudentMgmt();		
		$i=0;		
		$rs = $objStudentMgmt->getStudentDailyPresent($limit,$start,$where,"student_gturegno ASC,student_surname ASC,student_firstname ASC,student_lastname ","ASC");
		$total=dbRows($rs);
		$HeadData = array("count" => $total, "data" => array());
		if(dbRows($rs) > 0){
			while($row = dbArray($rs)){
				$temparray["student_id"]  = $row["student_id"];
				$temparray["student_name"]  = $row["studentname"];
				$temparray["student_gturegno"]  = $row["student_gturegno"];
				$temparray["student_mobilestudents"]  = $row["student_mobilestudents"];
				$temparray["student_mobileparents"]  = $row["student_mobileparents"];
					//$temparray["day_present"]  = true;
				if($_REQUEST['chk']== "true")
				{
				$temparray["day_present"]  = true;
				}
				
					
				
				$HeadData["data"][$i] = $temparray;   
				$i++;
			}
			echo json_encode($HeadData);
			exit;
		}
		}
		else
		{
				
			$objStudentPresentMaster = new PresentMasterMgmt();
			$condition .= " and day_id=".Escape($_REQUEST['day_id'])." ";
			
			$condition .= " and lec_id=".Escape($_REQUEST['lec_id'])." ";
			
			
			if($_REQUEST['batch_id'] != '' && $_REQUEST['batch_id'] !='0')
			{$condition .=	"and batch_id = '".Escape($_REQUEST['batch_id'])."' ";}
			$out = $objStudentPresentMaster ->getAllStudentPresent(0,0,$condition,"","");
			$day_absent="";
			//$row = dbArray($out);		
			//$day_absent  = $row["day_absent"];
			$i=0;
			while($row = dbArray($out))
			{
				if($i==0)
					{$day_absent  = $day_absent.$row["day_absent"];}
				else
					{$day_absent  = $day_absent.','.$row["day_absent"];}
					
				$i++;
			}
			
			
			$dayadsantArray=explode(',',$day_absent);
			$where="";
			if (($_REQUEST['branch_id'])!=""){
				$where .= "  AND sd.cur_branchid = '".Escape($_REQUEST['branch_id'])."' ";
			}
	
			if (($_REQUEST['year_id'])!=""){
				$where .= " AND sd.year_id = '".Escape($_REQUEST['year_id'])."' ";
			}
	
			if (($_REQUEST['branchyear_id'])!=""){
				$where .= " AND sd.cur_branchyearid = '".Escape($_REQUEST['branchyear_id'])."' ";
			}
	
			if (($_REQUEST['semester_id'])!=""){
				$where .= " AND sd.cur_semesterid = '".Escape($_REQUEST['semester_id'])."' ";
			}
			if($_REQUEST['batch_id'] != '' && $_REQUEST['batch_id'] !=0)
			{
				$where .=	"and sd.batch_id = '".Escape($_REQUEST['batch_id'])."' ";
			}
			$objStudentMgmt = new StudentMgmt();		
			$i=0;		
			$rs = $objStudentMgmt->getStudentDailyPresent($limit,$start,$where,"student_gturegno ASC,student_surname ASC,student_firstname ASC,student_lastname ","ASC");
			$total=dbRows($rs);
			$HeadData = array("count" => $total, "data" => array());
			if(dbRows($rs) > 0){
			while($row = dbArray($rs)){
				$temparray["student_id"]  = $row["student_id"];
				$temparray["student_name"]  = $row["studentname"];
				$temparray["student_gturegno"]  = $row["student_gturegno"];
				$temparray["student_mobilestudents"]  = $row["student_mobilestudents"];
				$temparray["student_mobileparents"]  = $row["student_mobileparents"];
				
				if(in_array($temparray["student_id"],$dayadsantArray))
				{
					$temparray["day_present"]  = false;
				}else
				{
					$temparray["day_present"]  = true;
				}
				
				$HeadData["data"][$i] = $temparray;   
				$i++;
			}
		}
		}
}
	
	echo json_encode($HeadData);	
?>
