<?php 
require_once("../includes/clase_sesion.php");
$sesion=new sesion(); // inicio la sesion
require_once("../includes/academia_constantes.php");
require_once("../includes/funciones_generales.php");
require_once("../includes/lib_lenguaje.php");

$cleguaje=new cLanguage();

if(!comprobar_sesion()){
	$responce->page = 0;
	$responce->total = 0;
	$responce->records = 0;
	echo json_encode($responce);
	exit();
}

require_once("../includes/MySQL.php");
$academia = new Servidor_Base_Datos(AC_CONN_HOST,AC_CONN_USER,AC_CONN_PASS,AC_CONN_DB."".$sesion->get('anio'));


$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
$id = $_REQUEST['id'];
if(!$sidx) $sidx =1;
if(!$sord) $sord ="asc";
if(!$limit) $limit =10;

// search options
// IMPORTANT NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// this type of constructing is not recommendet
// it is only for demonstration
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

$cd=$academia->escapar($_GET[cdgr],'int');

$wh = " and cod_grupo=".$cd;

		$start = $limit*$page - $limit; // do not put $limit*($page - 1)
		if ($start<0) $start = 0;
		
		//$cons="SELECT COUNT(*) AS count FROM adm_administrativos WHERE 1=1 ".$wh;
		$SQL = "SELECT SQL_CALC_FOUND_ROWS  cd_asixgrup,nom_asi,nom_ape_pro,per_act,cant_periodos AS num_per FROM view_list_mat_x_grup_prof_per_act 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->sql=$SQL;
        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
		
        $i=0;
		while($row=$academia->extraer_registro()){
			$responce->rows[$i]['id']=$row[cd_asixgrup];
			$responce->rows[$i]['cell']=array($row["nom_asi"], $row["per_act"],$row["nom_ape_pro"],$row["num_per"]);
            $i++;
		}
		$academia->liberar();
        echo json_encode($responce);
		
$academia->cerrar();

?>
