<?php
require "../../commonincludefiles.php";
if($_SESSION["aCollegeId"]!="" && isset($_SESSION["aCollegeId"]))
{
	$branchid       = isset($_REQUEST['branchid'])  	  ? Escape($_REQUEST['branchid'])  :  0;
	$division_id1   = isset($_REQUEST['division_id1'])  ? Escape($_REQUEST['division_id1'])  :  0;
	$gtuno     	  = isset($_REQUEST['gtuno'])  	 	 ? Escape($_REQUEST['gtuno'])  	   :  0;
	$surname	    = isset($_REQUEST['surname'])       ? Escape($_REQUEST['surname'])    :  0;
	$firstname      = isset($_REQUEST['firstname'])     ? Escape($_REQUEST['firstname'])  :  0;
	$lastname       = isset($_REQUEST['lastname'])      ? Escape($_REQUEST['lastname'])   :  0;
	$isstudying     = isset($_REQUEST['isstudying'])    ? Escape($_REQUEST['isstudying']) :  0;
	$semesterid     = isset($_REQUEST['semesterid'])    ? Escape($_REQUEST['semesterid'])   :  0;
	$batchid        = isset($_REQUEST['batchid'])   	   ? Escape($_REQUEST['batchid'])   :  0;
	//$birthplace     = isset($_REQUEST['birthplace']) ? $_REQUEST['birthplace'] :  0;
	$birthdate      = isset($_REQUEST['birthdate'])     ? Escape($_REQUEST['birthdate'])  :  0;
	
	$start   		= isset($_REQUEST['start'])  	 ? $_REQUEST['start']  	   :  0;
	$limit   		= isset($_REQUEST['limit'])  	 ? $_REQUEST['limit']      : 30;

	$condition="";
	
	if($branchid != ""){
		$condition .= " and sm.branch_id='$branchid' ";
	}
	if($semesterid != ""){
		$condition .= " and sm.semester_id='$semesterid' ";
	}
	if($semesterid != ""){
		$condition .= " and sd.cur_divison='$division_id1' ";
	}
	if($gtuno != ""){
		$condition .= " and sm.student_gturegno='$gtuno' ";
	}
	
	if($surname != ""){
		$condition .= " and sm.student_surname like '%$surname%'";
	}
	
	if($firstname != ""){
		$condition .= " and sm.student_firstname like '%$firstname%' ";
	}
	
	if($lastname != ""){
		$condition .= " and sm.student_lastname like '%$lastname%' ";
	}
	
	if($isstudying != ""){
		$condition .= " and sm.student_active='$isstudying' ";
	}
		
	if($birthdate != ""){
		$condition .= " and sm.student_birthdate='$birthdate' ";
	}
	
	$arr = array();
	$i=0;		
		
		
	if($condition!=""){   
		
		$objStudentMgmt = new StudentMgmt();	
		
		$total = $objStudentMgmt ->getCountRecords(0,0,$condition,"","");	
	
		
		$result = $objStudentMgmt ->getAllStudentRecords($limit,$start,$condition,"","");		
		
		$generalsearchData = array("count" => $total, "result" => array());
		
		if	(dbRows($result) > 0){

		   $temparray = array();
		   
		   while($row = dbArray($result)) {
				$temparray["student_id"]  = $row["student_id"];
				$temparray["semester_id"]  = $row["semester_id"];
				$temparray["branch_id"]  = $row["branch_id"];
				$temparray["semester_name"]  = $row["semester_name"];
				$temparray["branch_name"]  = $row["branch_name"];
				$temparray["division_id"]  = $row["cur_divison"];
				$temparray["student_gturegno"]   = $row["student_gturegno"];
				//$temparray["student_curstdid"]   = $row["student_curstd"];
				//$temparray["student_curstdname"]   = $row["student_curstdname"];
				$temparray["student_birthdate"]   = $row["student_birthdate"];
				$temparray["student_surname"]   = $row["student_surname"];
				$temparray["student_firstname"]   = $row["student_firstname"];
				$temparray["student_lastname"]   = $row["student_lastname"];
				//$temparray["student_lcno"]   = $row["student_lcno"];
				$temparray["student_admdate"]   = $row["student_admdate"];					  
				$generalsearchData["result"][$i] = $temparray;   
				$i++;
		  	}										
		}
  	}	
    echo json_encode($generalsearchData);	
}
?>