<?php 
	require_once("../includes/bootstrap2.php");
	$sesion=new sesion(); // inicio la sesion
	
	if(!comprobar_sesion()){
		$responce->page = 0;
		$responce->total = 0;
		$responce->records = 0;
		echo json_encode($responce);
		exit();
	}
	
	$academia=bootstrap::initBd($sesion->get('anio'));
	
	$nombre_grupo=$sesion->getVar('configuracion.nombres_grupos');
	
	
	$page = $_REQUEST['page']; // get the requested page
	$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
	$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
	$sord = $_REQUEST['sord']; // get the direction
	$cd = $_REQUEST['cd'];
	
	
	if(!$sidx) $sidx =1;
	if(!$sord) $sord ="asc";
	if(!$limit) $limit =10;
	$wh=" and aca_indicadores.cod_logro=$cd ";
	$searchOn = Strip($_REQUEST['_search']);
	if($searchOn=='true') {
		$fld = Strip($_REQUEST['searchField']);
		$fldata = Strip($_REQUEST['searchString']);
		$foper = Strip($_REQUEST['searchOper']);
		$wh .= " AND ".$fld;
		$wh .=construcWhSimple($foper,$fldata);
	}

	$start = $limit*$page - $limit; // do not put $limit*($page - 1)
	if ($start<0) $start = 0;
	

	$SQL = "SELECT SQL_CALC_FOUND_ROWS cod_indicador, definicion, nivel FROM aca_indicadores 
		WHERE 1=1".$wh." ORDER BY $sidx $sord LIMIT $start , $limit";
	
	$academia->instruccion($SQL,1);
	$count = $academia->totReg();

	if( $count >0 ) {
		$total_pages = ceil($count/$limit);
	} else {
		$total_pages = 0;
	}
	
	if ($page > $total_pages) $page=$total_pages;	

	$responce->page = $page;
	$responce->total = $total_pages;
	$responce->records = $count;
	$mayus_nom=$sesion->getVar('configuracion.format_nom');
	$i=0;
	while($row=$academia->extraer_registro()){
		$responce->rows[$i]['id']=$row['cod_indicador'];
		$responce->rows[$i]['cell']=array($row['nivel'],$row["definicion"]);
		$i++;
	}
	$academia->liberar();
	echo json_encode($responce);
		
	$academia->cerrar();

?>
