<?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");

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

require_once("../includes/MySQL.php");
require_once("../includes/funciones_buscador.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

if(!$sidx) $sidx =1;

$totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
if($totalrows) {$limit = $totalrows;}

$codigo=escapar($_POST["codigo"],'int');
		
		
$count = 10;
if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;

$wh=" AND aca_detalles_notas.cod_ponxperxsab ='$codigo'";
			
$SQL="SELECT
	aca_detalles_notas.cod_detalles_notas
	, aca_detalles_notas.nombre_nota
	, aca_detalles_notas.fecha_nota
	, aca_detalles_notas.por_nota
	, aca_detalles_notas.detalle_nota
	, aca_detalles_notas.num_nota
FROM aca_detalles_notas WHERE 1=1 ".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
	

$academia->instruccion($SQL);
if(!is_object($responce))
{
	$responce = new stdClass;
}
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$cd_fin=0;
$i=0;
$total_por=0;
while($row = $academia->extraer_registro()) {
	$responce->rows[$i]['id']=$row['cod_detalles_notas'];
	$responce->rows[$i]['cell']=array($row['cod_detalles_notas'],$row['nombre_nota'],$row['por_nota'],$row['fecha_nota'],$row['detalle_nota']);
	$i++;
	$total_por+=$row['por_nota'];
	$cd_fin=$row['cod_detalles_notas'];
} 

$responce->userdata->tot_por = $total_por;
$responce->userdata->sql = $SQL;
$responce->userdata->ide_final = $cd_fin;
echo json_encode($responce);         

$academia->cerrar();

?>
