<?php
 require "../commonincludefiles.php";
 
 $college_id	=	$_SESSION["VedantnrCollegeId"];
 $year_id	=	$_SESSION["aYear"];

	// collect request parameters
	$start   = isset($_REQUEST['start'])  ? $_REQUEST['start']  :  0;
	$limit   = isset($_REQUEST['limit'])  ? $_REQUEST['limit']  : 30000;
	$sort    = isset($_REQUEST['sort'])   ? $_REQUEST['sort']   : '';
	$dir     = isset($_REQUEST['dir'])    ? $_REQUEST['dir']    : 'ASC';
	$filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null;

// initialize variables
$where = '';
$qs = '';

if(is_array($filters)){
	$encoded = false;
} else{
	$encoded = true;
	$filters = json_decode($filters);
}

if(is_array($filters)){
	for ($i=0;$i<count($filters);$i++){
    	$filter = $filters[$i];
		if($encoded){
			$field = $filter->field;
			$value = $filter->value;
			$compare = isset($filter->comparison) ? $filter->comparison : null;
			$filterType = $filter->type;
		} else{
			$field = $filter['field'];
			$value = $filter['data']['value'];
			$compare = isset($filter['data']['comparison']) ? $filter['data']['comparison'] : null;
			$filterType = $filter['data']['type'];
		}
		switch($filterType){
			case 'string' : $qs .= " AND ".$field." LIKE '%".$value."%'"; break;
		}
	}
    $where .= $qs; 
}

if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"])){

	$objUserMgmt = new UserMgmt();
	
	if($college_id != ""){
		$where .= " and cms_usermaster.college_id='$college_id' ";
	}
	
	$arr = array();
	$k=0;
	$order_field = $sort;
	$order_type = $dir;
	
	$rs = $objUserMgmt->getAllRecords($limit,$start,$where,$order_field,$order_type);
	
	$total = $objUserMgmt->getCountRecords(0,0,$where,"","");;
			
	while($obj = dbObject($rs)) {
	
		$arr[$k] = $obj;   
		$k++;
	}	
	// return response to client
	echo '{"total":"'.$total.'","data":'.json_encode($arr).'}';
}
?>