<?php
	require "../commonincludefiles.php";
	
 	$arr = array();
 	$total = 0;
	$admyear =''; 
	
	if(isset($_REQUEST['branch']))
	{
		$branch = Escape($_REQUEST['branch']);
	}
	else
	{
		$branch ='';
	}
	if(isset($_REQUEST['Year']))
	{
		$admyear = substr($_REQUEST['Year'], 0, 4);
	}
	else
	{
		$admyear = '';
	}
	if($_REQUEST['Semester'])
	{
		$Semester = Escape($_REQUEST['Semester']);
	}
	else
	{
		$Semester = '';
	}
	if($_REQUEST['student_gturegno'])
	{
		$GtuNo = Escape($_REQUEST['student_gturegno']);
	}
	else
	{
		$GtuNo ='';
	}
	if($_REQUEST['Div'])
	{
		$Div = Escape($_REQUEST['Div']);
	}
	else
	{
		$Div ='';
	}

	$condition ="";
	if($_REQUEST['branch']!="" && $_REQUEST['branch']!= "All" )
	{
			$condition .= " and sd.cur_branchid = '".Escape($_REQUEST['branch'])."'";	
	}
	if($_REQUEST['Year']!="")
	{
		$condition .= "and sd.year_id = '".Escape($_REQUEST['Year'])."'";
	}
	
	if($_REQUEST['SemesterId']!="")
	{
		$condition .= "and sd.cur_semesterid = '".Escape($_REQUEST['SemesterId'])."'";
	}
	if($_REQUEST['BranchyearId']!="")
	{
		$condition .= "and sd.cur_branchyearid = '".Escape($_REQUEST['BranchyearId'])."'";
	}
	
	if($_REQUEST['student_gturegno']!="")
	{
		$condition .= " and sm.student_gturegno = '".Escape($_REQUEST['student_gturegno'])."'";
	}
	// for remove multitimes display of records..
	$condition .= " group by sm.student_id ";
	$condition .= "order by sm.student_gturegno ASC ";

	$StudentDetailMgmt = new StudentDetailMgmt();
	$rs=$StudentDetailMgmt->getstudentIcard($condition);
		
	
	/*$query = "SELECT 
				sm.student_id,
				sm.student_surname,
				sm.student_firstname, 
				sm.student_lastname ,
				sm.student_gturegno ,
				sm.student_gender,
				(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 semester_name FROM cms_semestermaster sem  WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sd.cur_semesterid) AS semester_name,
				(SELECT branchyear_name  FROM cms_branchyear bry  WHERE  bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "'AND bry.branchyear_id = sd.cur_branchyearid) AS branchyear_name		    	 	   	 	
		  	FROM cms_studentmaster sm,cms_studentdetail sd 
				WHERE sm.student_id = sd.student_id   ";*/
				 
	
		//echo $query;
			 
		//$rs = dbQuery($query);
		$HeadData = array("count" => $total, "data" => array());
		$i= 0;
		if(dbRows($rs) > 0)
		{
			while($row = dbArray($rs))
			{
				$name = $row["student_gturegno"].' - '.$row["student_surname"]." ".$row["student_firstname"]." ".$row["student_lastname"]; 
				$qtip ="Course:".$row["branch_name"].".<br/>GTU Reg No:".$row["student_gturegno"].".<br/>Batch Year:".$row["year_name"]; 
				$temparray["student_id"]  = $row["student_id"];
				$temparray["student_name"]  = "<div qtip=\"".$qtip."\">".$name."</div>";	
				$HeadData["data"][$i] = $temparray;   
				$i++;
			}
		}
	
	
	echo json_encode($HeadData);	
?>