<?php
//formato boletin Ciudad Puerto Limon
$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'];

$sql = "call SP_BOLETINES_INDIVIDUAL_GENERICO('$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_pres'];
$mayus_nom = $sesion->getVar('configuracion.format_nom');
$mayus_mat = $sesion->getVar('configuracion.format_mat');

$notest = str_replace("\n", "<br>", $row['notas']);
$notest = str_replace("\t", " ", $notest);
$notest = parseString($notest);
$notest = json_decode($notest, true);

$materias = $notest['materias'];
$numPeriodos = count($materias[0]['historicos']);
$bolFinal = $periodon == $numPeriodos ? true : false;
do {
    echo '<div id="pageBoletin">';
    echo $encabezado;
    $notest = str_replace("\n", "<br>", $row['notas']);
    $notest = str_replace("\t", " ", $notest);
    $notest = parseString($notest);
    $notest = json_decode($notest, true);
    if ($notest === NULL) {
        echo '</div>';
        continue;
    }

    $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');
    ?>
    <link href="../css/formato_boletin.css" rel="stylesheet" type="text/css">

    <table width="100%"
           style="border:1px solid; margin-bottom:2px; font-size: 9pt;  font-family: Arial, Helvetica, sans-serif;  vertical-align:top;">
        <tr align="left">
            <td width="19%"><strong>Id:</strong>&nbsp;&nbsp;<?php echo formatoPalabras($notest[dc_est], $mayus_nom); ?>
            </td>
            <td><strong>Estudiante:</strong>&nbsp;&nbsp;<span
                        style="font-size:11pt"><?php echo formatoPalabras($notest[no_est], $mayus_nom); ?></span></td>
            <td colspan="2"><strong>Grado:</strong> &nbsp;&nbsp;<?php echo $grado; ?></td>
        </tr>
        <tr align="left">
            <td><strong>Puesto en el grupo:</strong>&nbsp;&nbsp; <?php echo $notest[pto_gru]; ?></td>
            <td width="41%"><strong>Sede:</strong>&nbsp;&nbsp;<?php echo $sede; ?></td>
            <td width="20%"><strong>Jornada:</strong>&nbsp;&nbsp;<?php echo $jornada; ?></td>
            <td width="20%"><strong>Periodo:</strong>&nbsp;&nbsp;<?php echo $periodo; ?></td>
        </tr>
    </table>


    <table width="100%" cellspacing="1" class='boletin'>
        <tr>
            <td width="20%" class='spancabecera'>Dimensión</td>
            <td width="15%" class='spancabecera'>Desempeño</td>
            <td width="60%" class='spancabecera'>Descripción</td>
        </tr>

        <?php
        $materias = $notest['materias'];
        foreach ($materias

        as $rmat):
        $historicos = $rmat['historicos']
        ?>
        <tr>
            <td><?php echo ucfirst($rmat['no_asi']); ?></td>
            <td align="center"><?php
                $imagen = "images/preescolar/" . normaliza($rmat['nl']) . ".png";
                ?> <img src=<?php echo $imagen; ?> width="57" height="57" alt="<?php echo ucfirst($rmat['nl']) ?>">
                <div> <?php echo ucfirst($rmat['nl']); ?></div>
            </td>
            <td> <?php
                echo $rmat['obs_asi'];
                endforeach;
                ?>


    </table>

    <?php
    if ($bolFinal)
        echo "<br><div class='boletin'><strong>APRUEBA: SI___&nbsp;&nbsp;&nbsp;  NO___</strong><br></div>";
    ?>
    <br><br><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" valign="bottom">
            <td>
                <?php
                if ($tipouser == $codrector || $tipouser == $codadmin || $tipouser == $codsecre) {
                    if (file_exists("../images/firma.jpg")) {
                        echo "<img src='../images/firma.jpg' width='247' height='129' alt='Firma rector' class='codbar' style='vertical-align:bottom'>";
                    } else {
                        echo '_________________________________';
                    }
                }
                ?>
                <br>
                <?php echo strtoupper($nom_rector) ?><br>
                Rectora
            </td>
            <td>_________________________________<br>
                <?php echo strtoupper($director) ?><br>
                Director de Grupo
            </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="center"><?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>

    <?php
    echo "</div>"; //cirra la pagina
} while ($row = $academia->extraer_registro());
$academia->liberar();
?>