<?php
require_once("../includes/bootstrap2.php");
$sesion = new sesion(); 
$academia = bootstrap::initBd($sesion->get('anio'));
$codest = $_GET['id']; 
$codgru = $_GET['codgru'];
$idtbl = $sesion->get('ac_userid');

$sql = "CALL SP_RESUMEN_PADRES($codest,$codgru,'$idtbl')";

$academia->instruccion($sql);
if ($academia->extraer_error() != 0) {
    echo '<div style="display:none">' . $sql . '</div>';
    echo "Error";
    exit(); 
}  

$reg = $academia->extraer_registro();
//$mayus_nom=$sesion->getVar('configuracion.format_nom');
$mayus_mat = $sesion->getVar('configuracion.format_mat');

$columns = array_keys($reg);
$numcols = count($columns);
echo '<div style="display:none">' . $sql . '</div>';
echo '<div id="acorPerdiodos"  class="easyui-accordion" style="width:auto;height:480px;"> ';
 
$ip = 1; // contador periodos;
$dtsGrafMat = array();
do {


    echo '<div title="Periodo ' . $ip++ . '"  style="overflow:auto;padding:3px;" data-options="
				tools:[{
					iconCls:\'icon-grafico\',
					handler:function(){
						viewGrafico(' . ($ip - 1) . ')
					}
				}]">';

    $i = 1;
    echo '<table class="table table-bordered table-condensed" id="tbAreas">';
    echo '<thead><tr>
						<th>N°</th>
						<th>Materia</th>
						<th width="80px">F. Jus.</th>
						<th width="80px">F. Injus.</th>
						<th width="100px">Definitiva</th>
						<th width="100px" align="right"></th>
					</thead></tr>';
    $cn = 1;
    for ($i = 2; $i <= $numcols - 3; $i++) {
        $dtsRegCol = json_decode($reg[$columns[$i]], TRUE);
        ;
        $nomArea = formatoPalabras($dtsRegCol['nom_area'], $mayus_mat);
        foreach ($dtsRegCol['materias'] as $dtsMat) {
            $dtsGrafMat[($ip - 1)]['cat'][] = formatoPalabras($dtsMat['nom_asi'], $mayus_mat);
            $dtsGrafMat[($ip - 1)]['dts'][] = (float) $dtsMat['definitiva']['nd'];
            echo '<tr>
								<td>' . $cn++ . '</td>
								<td>' . formatoPalabras($dtsMat['nom_asi'], $mayus_mat) . '</td>
								<td>' . $dtsMat['faljus'] . '</td>
								<td>' . $dtsMat['falinj'] . '</td>
								<td>' . number_format($dtsMat['definitiva']['nd'], 1) . '</td>
								<td align="right">
									<a href="javascript:verDtllsNts(' . $dtsMat['cod_asi'] . $codest . $ip . ',\'' . formatoPalabras($dtsMat['nom_asi'], $mayus_mat) . '\')" class="easyui-linkbutton" data-options="iconCls:\'icon-vermas\'"></a>
								</td>
							</tr>';
            echo '<div id="dtllsNotas' . $dtsMat['cod_asi'] . $codest . $ip . '"style="display:none">';
            echo json_encode($dtsMat['desempenios']);
            echo '</div>';
        }
    }
    echo '</table>'; // cirra tababla de areas
    echo '</div>'; // cierra div de item del acordeon
} while ($reg = $academia->extraer_registro());
echo '</div>'; // cirrea acordeon
echo '<div id="dtsGraficos" style="display:none">' . json_encode($dtsGrafMat) . '</div>';
?>
