<?php
 require "../commonincludefiles.php";
 
 $arr = array();
 $total = 0;
      	
		 $qry = "SELECT 
	  			sm.student_id,
				sm.shift,
				sm.student_gturegno,
				sm.student_scholarship,
				sm.student_admdate, 
				CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS studentname,
				sm.student_birthdate,
				sm.student_gender,
				sm.student_admby,
				sm.student_category,	
				sm.student_mobilestudents,
				sm.student_mobileparents,
				sm.tfw_scheme,  		  
			  	sd.batch_id, 
				sm.leave_type,
				
					(SELECT branch_name 
	  FROM cms_branchmaster sec 
	  WHERE sec.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id = sd.cur_branchid) AS branch_name,
		  (SELECT year_name
		  FROM cms_yearmaster ym 
	   WHERE ym.year_id = sd.year_id) AS year_name,
	  (SELECT branchyear_name
		  FROM 	cms_branchyear bry 
	   WHERE bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND bry.branchyear_id = sd.cur_branchyearid) AS branchyear_name,
	   (SELECT semester_name
		  FROM cms_semestermaster sem 
	   WHERE sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sd.cur_semesterid) AS semester_name		   	 
				(SELECT 
					semester_name
			   	 FROM 
				 	cms_semestermaster sem 
			     WHERE 
				 sem.college_id   = '".$_SESSION["VedantnrCollegeId"]."'
				 AND sem.semester_id = sd.cur_semesterid) AS semester_name		   	 
		  	  FROM
			  	cms_studentmaster sm,
				cms_studentdetail sd				
		  	  WHERE								
				sm.college_id  = '".$_SESSION["VedantnrCollegeId"]."' 
				AND sm.student_id=sd.student_id  AND sm.student_active=1  ";
		
		if($_REQUEST['barnch'] != "" && $_REQUEST['barnch'] != "All"){
			$where .= " and sd.cur_branchid = '".Escape($_REQUEST['barnch'])."'";
		}
		if($_REQUEST['semester']!="")
		{
			$where .= " and sd.cur_semesterid = '".Escape($_REQUEST['semester'])."'";
		}
		
		if($_REQUEST['branchyear_id']!="")
		{
			$where .= " and sd.cur_branchyearid = '".Escape($_REQUEST['branchyear_id'])."'";
		}
		if($_REQUEST['year_id']!="")
		{
			$where .= " and sd.year_id = '".Escape($_REQUEST['year_id'])."'";
		}
				
		$where .= " order By sm.student_gturegno ASC,sm.student_surname ASC , sm.student_firstname ASC,sm.student_lastname ASC ";
		
		$qry.=	$where;	
		$k=0;
		
		//echo $qry;
				
		$rs = dbQuery($qry);
		$total = dbRows($rs);
		
		while($obj = dbObject($rs)) {
		
			$arr[$k] = $obj;   
		   $k++;
		}
	echo '{"total":"'.$total.'","data":'.json_encode($arr).'}';
	
		
?>
