<?php
//FORMATO DEL BOLETIN GENERAL PARA JORGE ELIECER GAITAN  - ORITO
$academia->instruccion("SELECT ide_adtivo, LCASE(CONCAT_WS(' ', no1_adtivo, no2_adtivo,ape1_adtivo, ape2_adtivo)) nom_ape FROM adm_administrativos WHERE cod_cargo=1 or cod_cargo=2 order by cod_cargo");
$regFirmantes = $academia->fetchAll();
$nom_rector = $regFirmantes[0]['nom_ape'];
$nom_cordin = $regFirmantes[1]['nom_ape'];

$sql = "call SP_BOLETINES_GENERICO_NOTAS_INDIVIDUALES('$cod_estudiantes',$grupo,$periodon,'$iduser')";

$academia->instruccion($sql);
echo '<div style="display:none">' . $sql . '</div>';
unset($sql);
$row = $academia->extraer_registro();
$dtsColegio = $sesion->get('info_colegio');
$encabezado = $dtsColegio['enca_boletin'];
$observa = "";
$mayus_nom = $sesion->getVar('configuracion.format_nom');
$mayus_mat = $sesion->getVar('configuracion.format_mat');
do {
    $observa = "";
    #echo "<br><br><br>";
    echo '<div id="pageBoletin">';
    #echo "<br><br><br>";
    echo $encabezado;
    $notest = str_replace("\n", "<br>", $row['notas']);
    $notest = str_replace("\t", " ", $notest);
    $notest = parseString($notest);
    $notest = json_decode($notest, true);

    $infcom = json_decode($row['comportamiento'], true);
    $cod_est = $notest['cd_est'];
    $msgPbar = "id-" . $notest['dc_est'] . "-pto-" . $notest['pto_gru'];
    $msgPbar.="-grado-" . $grado . "-per-" . $periodon . '-val-si-anio' . $sesion->get('anio');
    $dtsObserva = json_decode($row['observaciones'], true);
    $prom_periodo_num = $notest['prom_periodo'];
    $prom_periodo_let = $notest['prom_peri_letra'];
    $pto_grupo = $notest['pto_gru'];
    ?>
    <link href="../css/formato_boletin_<?php echo $frm_bol_gral ?>.css" rel="stylesheet" type="text/css">

    <table width="100%" cellspacing="1" class='boletin'>
        <tr>
            <td style="font-weight: bold">Nombre del estudiante</td>
            <td colspan="3"><?php echo formatoPalabras($notest['no_est'], $mayus_nom); ?></td>
            <td style="font-weight: bold">Año lectivo</td>
            <td><?php echo $sesion->get('anio') ?></td>

        </tr>
        <tr>
            <td style="font-weight: bold">Grado</td>
            <td colspan="2"><?php echo $grado; ?></td>
            <td style="font-weight: bold">Periodo</td>
            <td colspan="2"><?php echo $periodo; ?></td>

        </tr>
        <tr>
            <td style="font-weight: bold">Director de grupo</td>
            <td colspan="5"><?php echo formatoPalabras($director, $mayus_nom) ?></td>
        </tr>
    </table>
    <div class="separador"></div>
    <?php
    $materias = $notest['materias'];
    $numPeriodos = count($materias[0]['historicos']);
    $bandera = $periodon == $numPeriodos ? true : false;
    ?>
    <div style="font-family: Calibri; font-size: 8pt">
        <?php
        $materias = $notest['materias'];
        $cdant = -1;
        $contNmat = 1;
        foreach ($materias as $rmat):
            ?>
            <div class="bloque_materia">
                <table  width="100%" cellspacing="1" class='boletin'>
                    <tr >
                        <td style="font-weight: bold; width: 13%;" >Campo de Formación:</td>
                        <td style="width: 23%;"><?php echo formatoPalabras($rmat['no_area'], $mayus_mat) ?></td>
                        <td  style="width: 10%;" rowspan="2" colspan="2"  class="bold">Inasistencia</td>
                        <td style="width: 3%;" class="spancabecera">IJ</td>
                        <td style="width: 3%;" class="spancabecera">ISJ</td>
                        <td style="width: 3%;" class="spancabecera">TI</td>
                    </tr>
                    <tr>
                        <td style="font-weight: bold">Área específica:</td>
                        <td><?php echo formatoPalabras($rmat['no_asi'], $mayus_mat) ?></td>
                        <td style="text-align: center"><?php echo empty($rmat['fj']) ? '' : $rmat['fj'] ?></td>
                        <td style="text-align: center"><?php echo empty($rmat['fi']) ? '' : $rmat['fi'] ?></td>
                        <td style="text-align: center"><?php echo $rmat['fi'] + $rmat['fj'] ?></td>

                    </tr>
                    <tr>
                        <td class="bold" style="text-align: left">Nombre del Docente:</td>
                        <td colspan="6" ><?php echo formatoPalabras($rmat['dte'], $mayus_nom) ?></td>
                    </tr>
                    <tr style="font-size: 8px !important">
                        <td rowspan="2" colspan="3" class="bold">DESEMPEÑO DE APRENDIZAJE</td>
                        <td  colspan="6" style=" text-align: center" class="bold">NIVEL DE DESEMPEÑO</td>
                    </tr>
                    <tr style="font-size: 8px !important">
                        <td style="width: 3%; text-align: center" class="bold">BJO</td>
                        <td style="width: 3%; text-align: center" class="bold">BSC</td>
                        <td style="width: 3%; text-align: center" class="bold">ALT</td>
                        <td style="width: 3%; text-align: center" class="bold">SUP</td>
                    </tr>


                    <?php
                    $totNtInd = count($rmat['notasind']);


                    foreach ($rmat['notasind'] as $dnt) {
                        echo "<tr>";
                        echo '<td colspan="3">' . $dnt['nomnota'] . '</td>';
                        echo '<td style="width: 3%; text-align: center"">' . (($dnt['valnota'] <= 1.9) ? 'X' : '' ) . '</td>';
                        echo '<td style="width: 3%; text-align: center"">' . (($dnt['valnota'] > 1.9 && $dnt['valnota'] <= 2.9 ) ? 'X' : '') . '</td>';
                        echo '<td style="width: 3%; text-align: center"">' . ( ($dnt['valnota'] > 2.9 && $dnt['valnota'] <= 3.9 ) ? 'X' : '' ) . '</td>';
                        echo '<td style="width: 3%; text-align: center" ">' . (($dnt['valnota'] > 3.9 && $dnt['valnota'] <= 5.0 ) ? 'X' : '' ) . '</td>';

                        echo "</tr>";
                    }
                    ?>

                </table>
            </div>
            <div class="separador"></div>
            <?php
        endforeach;
        ?>

        <?php
        $dtsObserva = str_replace("\n", "<br/>", $row['comportamiento']);
        $dtsObserva = str_replace("\t", "  ", $dtsObserva);
        $dtsObserva = parseString($dtsObserva);
        #echo $dtsObserva.'<br>';
        $dtsObserva = json_decode($dtsObserva, true);
        $notaDisPeriodo = $dtsObserva['comp']['disper'];
        ?>
        <table width="100%" cellspacing="1" class='boletin'>
            <tr><td class="bold" colspan="2" style="text-align: center">COMPORTAMIENTO</td></tr>
            <tr>
                <td class="bold" width="23%" style="text-align: center">Valoración Conceptual:</td>
                <td  class="bold" style="text-align: center">Descripción:</td>
            </tr>
            <tr>
                <td><?php echo ucwords($notaDisPeriodo['NOADIS']) ?></td>
                <td><?php echo ucfirst($notaDisPeriodo['DESCRIPDIS']) ?> </td>
            </tr>
        </table>
        <b>Convenciones:</b> <b>Bjo</b> (Desempeño Bajo), <b>Bsc</b> (Desempeño Básico) <b>Alt</b> (Desempeño Alto), <b>Sup</b> (Desempeño superior),  <b>IJ</b> (Inasistencia justificada), <b>ISJ</b> (Inasistencia sin justificar), <b>TI</b> (Total Inasistencias) 

        <?php
        $dtsObserva = str_replace("\n", "<br/>", $row['observaciones']);
        $dtsObserva = str_replace("\t", "  ", $dtsObserva);
        $dtsObserva = parseString($dtsObserva);
        $dtsObserva = json_decode($dtsObserva, true);
        $observa = $dtsObserva['hist'];
        $notaComporta = numberFormat($dtsObserva['notaobserva'], 1); //nota numeros

        echo '<br><br><table width="100%" align="center" class="observa"><tr><td><b>OBSERVACIONES:</b></td></tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr></table>';
        ?>
        <br>

        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:2px; font-size: 9pt;  font-family: Arial, Helvetica, sans-serif;  vertical-align:top;">
            <tr align="center"> 
                <td style="vertical-align: bottom">_________________________________<br>
                    <?php echo strtoupper($director) ?><br>
                    Director de Grupo
                </td>
                <td class="v-align-top" style="text-align: center">
                    <img src='../images/firma_cor.jpg' width='160' height='40' alt='Firma rector' class='codbar' style='vertical-align:bottom'>
                    <br>
                    Esp. EDSON NILSEN LOPEZ BARRERA
                    <?php echo "<br> Cordinador Académico" ?>
                </td>
            </tr> 
            <tr>
                <td colspan="2" style="text-align: center">
                    <br>
                    <img src='../images/firma_rec.png' width='160' height='40' alt='Firma rector' class='codbar' style='vertical-align:bottom'>
                    <br> Esp. DORIS CONSTANZA CORTES QUIJANO
                </td>
            </tr>
        </table>

        <table id="foot" width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td width="6%" rowspan="2" align="center" valign="middle">&nbsp;</td>
                <td align="center" valign="middle"><?php echo $sesion->getVar('info_colegio.pie_boletin') ?></td>
                <td width="6%" rowspan="2" align="right"><?php
                    // user data
                    $PNG_TEMP_DIR = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
                    $PNG_WEB_DIR = 'temp/';
                    //ofcourse we need rights to create temp dir
                    if (!file_exists($PNG_TEMP_DIR))
                        mkdir($PNG_TEMP_DIR);

                    $errorCorrectionLevel = 'L';
                    $matrixPointSize = 1;
                    //echo $msgPbar;
                    $filename = $PNG_TEMP_DIR . 'Boletin' . $cod_est . '_' . $sesion->get('academia_succes') . "-" . md5($errorCorrectionLevel . '|' . $matrixPointSize . '') . '.png';
                    QRcode::png($msgPbar, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
                    echo '<img src="' . $PNG_WEB_DIR . basename($filename) . '" class="codbar" />';
                    ?></td>
            </tr>
            <tr>
                <td align="center"><span class="copy"><?php echo $dtsLang['project']['nom_soft'] . ' ' . $dtsLang['project']['ver_soft'] . ' ' . $dtsLang['project']['footertext'] . " " . $dtsLang['project']['anio_ini'] . ' - ' . date('Y') ?></span></td>
            </tr>
        </table>
    </div>
    <?php
    echo "</div>"; //cirra la pagina
}while ($row = $academia->extraer_registro());
$academia->liberar();
