<?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();
}
$codigo_grupo = escapar($_POST["cdgr"], 'int');
$periodo = escapar($_POST["per_calif"], 'int');
if ($codigo_grupo == '0x') {
    header("Content-type: application/json");
    echo json_encode(array());
    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'));

$consulta = "SELECT
    cod_estudiantes_grupos AS cd
    , estudiante AS nombre
    , numedocumento_est
    ,(SELECT FORMAT(nonu_per_dis,1) FROM aca_observaxest WHERE cod_estudiantes_grupos=cd AND periodo='$periodo' ) AS nt,
    (SELECT observacion FROM aca_observaxest WHERE cod_estudiantes_grupos=cd AND periodo='$periodo' ) AS obs
FROM
    view_pag_estudiantes_activos
    WHERE cod_grupo =$codigo_grupo ORDER BY nombre";

$academia->instruccion($consulta);
$i = 0;
$responce = array(); 

$responce['sql']=$consulta;

while ($row = $academia->extraer_registro()) {
    $responce['rows'][] = array(
        'idest' => $row['cd'],
        'nombre' => ucwords($row['nombre']),
        'nt_num' => $row['nt'],
        'obs' => $row['obs'],
    );
}
header("Content-type: application/json");
echo json_encode($responce);

$academia->cerrar();
?>
        