<?php
	require "../commonincludefiles.php";
	
 	$total = 0;
	$where="";
	if($_SESSION["VedantnrCollegeId"]!="" ){
		$date=date('Y-m-d',strtotime(Escape($_REQUEST['day_date'])));
		$where ="";

		if($_SESSION["Employee_Id"]!="" && $_SESSION["Employee_Id"]!=0 && $_SESSION["VedantnrUserRole"] != 'PowerUser' && $_SESSION["VedantnrUserRole"] != 'Hod' && $_SESSION["VedantnrUserName"] != 'indrajeet'){
			$where = " and pm.login_id= '".$_SESSION["VedantnrUserId"]."'";
		}
		
		if($_REQUEST["branch_name"]!="" && $_REQUEST["branch_name"]!=0){
			$where.= " and pm.branch_id= '".Escape($_REQUEST["branch_name"])."'";
		}
		if($_REQUEST["semester_name"]!="" && $_REQUEST["semester_name"]!=0){
			$where.= " and pm.semester_id= '".Escape($_REQUEST["semester_name"])."'";
		}

		if($_REQUEST["year_name"]!="" && $_REQUEST["year_name"]!=0){
			$where.= " and pm.year_id= '".Escape($_REQUEST["year_name"])."'";
		}

		if($_REQUEST["branchyear_name"]!="" && $_REQUEST["branchyear_name"]!=0){
			$where.= " and pm.branchyear_id= '".Escape($_REQUEST["branchyear_name"])."'";
		}
		
	
		
		$where.= " and pm.day_date= '".$date."'";
		$objPresentMasterMgmt = new PresentMasterMgmt();		
		$order_field = " branch_name ";
		$order_type = " ASC ";
		$i=0;
		$rs = $objPresentMasterMgmt->getpresentdetails($limit,$start,$where,$order_field,$order_type);
		$total=dbRows($rs);
		$HeadData = array("count" => $total, "data" => array());
		if(dbRows($rs) > 0){
			while($row = dbArray($rs)){
				
				$temparray["day_id"]  = $row["day_id"];
				$temparray["branch_name"]  = $row["branch_name"];
				$temparray["subject_name"]  = $row["subject_name"];
				$temparray["batch_name"]  = $row["batch_name"];	
				if($row["day_present"] != "")
				{
				$temppr = explode(",",$row["day_present"]);
				$temparray["day_present"]  = count($temppr);
				}
				else
				{
					$temparray["day_present"]=0;
				}
				if($row["day_absent"] != "")
				{
				$tempab = explode(",",$row["day_absent"]);
				$temparray["day_absent"]  = count($tempab);
				}
				else
				{
					$temparray["day_absent"]=0;
				}
				
					
				$temparray["lectype"]=$row["lectype_name"];
				$temparray["lec_name"]=$row["lec_name"];
				$temparray["day_date"]  = $row["day_date"];
				$temparray["day_working"]  = $row["day_working"];
				$temparray["branch_id"]  = $row["branch_id"];	
				$temparray["subject_id"]  = $row["subject_id"];	
				$temparray["yesr_id"]  = $row["yesr_id"];
				$temparray["yesr_name"]  = $row["yesr_name"];

				$temparray["branchyear_id"]  = $row["branchyear_id"];
				$temparray["branchyear_name"]  = $row["branchyear_name"];
				$temparray["semester_id"]  = $row["semester_id"];
				$temparray["semester_name"]  = $row["semester_name"];
				$temparray["batch_id"]  = $row["batch_id"];
				$temparray["div_id"]  = $row["div_id"];
				$temparray["shift"]  = $row["shift"];
				$temparray["day_comment"]  = $row["day_comment"];
				$temparray["present_by"]  = $row["user_name"];
				$HeadData["data"][$i] = $temparray;   
				$i++;
			}
		}
	}
	
	echo json_encode($HeadData);	
?>
