<?php
//FORMATO DEL BOLETIN GENERAL JORGE ELIECER GAITAN 2018
$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_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'];
$mayus_nom = $sesion->getVar('configuracion.format_nom');
$mayus_mat = $sesion->getVar('configuracion.format_mat');
$num_est = $academia->num_rows();
$observa = "";
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);

    $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');
    $observa = "";
    ?>
    <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 colspan="2"><strong>Estudiante:</strong>&nbsp;&nbsp;<span
                        style="font-size:11pt"><?php echo formatoPalabras($notest[no_est], $mayus_nom); ?></span></td>
            <td width="20%"><strong>Grado:</strong> &nbsp;&nbsp;<?php echo $grado; ?></td>
        </tr>
        <tr align="left">
            <td><strong>Puesto general:</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><strong>Periodo:</strong>&nbsp;&nbsp;<?php echo $periodo; ?></td>
        </tr>
    </table>

-->
    <table class="boletin" width="100%"
           style="border:1px solid; margin-bottom:2px; font-size: 9pt;  font-family: Arial, Helvetica, sans-serif;  vertical-align:top;">
        <tr>
            <td colspan="2" align="center" style="background-color: #c3c3c3"><strong>BOLETIN ACADÉMICO
                    INFORMATIVO</strong></td>
            <td><strong>Año Lectivo</strong></td>
            <td><?php echo $sesion->get('anio') ?></td>
        </tr>
        <tr>
            <td width="30%"><strong>Apellidos y nombres del Estudiante</strong></td>
            <td><?php echo formatoPalabras($notest[no_est], $mayus_nom); ?></td>
            <td><strong>Doc. Ident</strong></td>
            <td><?php echo $notest['dc_est'] ?></td>
        </tr>
        <tr>
            <td><strong>Grado</strong></td>
            <td><?php echo $grado; ?></td>
            <td><strong>Periodo</strong></td>
            <td><?php echo $periodo; ?></td>
        </tr>
        <tr>
            <td colspan="4"><strong>Director(a) de grupo:</strong> <?php echo strtoupper($director) ?></td>
            <!--<td>Puesto</td>
            <td><?php echo $notest[pto_gru]; ?></td>-->
        </tr>
    </table>
    <?php
    $materias = $notest['materias'];
    $numPeriodos = count($materias[0]['historicos']);
    $bandera = $periodon == $numPeriodos ? true : false;
    $banderaFinal = $bandera;
    $bandera = false; // verifica si se usa un boletin diferentes
    ?>
    <table width="100%" cellspacing="1" class='boletin'>
        <tr>
            <td width="35%" rowspan=3 class='spancabecera'>Asignatura</td>
            <td width="20%" rowspan=3 class='spancabecera'>Docente</td>
            <td width="15%" colspan=4 class='spancabecera'>DESCRIPCIÓN</td>
            <?php if ($bandera): ?>
                <td width="28%" <?php echo 'colspan="2"' ?>
                    class='spancabecera'><?php echo 'Definitiva' ?></td>
            <?php endif; ?>
        </tr>
        <tr>
            <td rowspan="2" class='spancabecera'> Valoración Conceptual</td>
            <td colspan="3" class='spancabecera'>Inasistencia</td>
        </tr>
        <tr>
            <td width="5%" class="spancabecera">Just</td>
            <td width="5%" class="spancabecera">Injus</td>
            <td width="5%" class="spancabecera">Total Faltas</td>

            <?php if ($bandera) { ?>
                <td width="5%" class="spancabecera">Num</td>
                <td width="10%" class="spancabecera">Val</td>
            <?php } ?>
        </tr>

        <?php
        $obs = '';
        $materias = $notest['materias'];
        $TotIntHora = 0;
        $TotNotaComporta = 0;
        foreach ($materias as $rmat):
            $historicos = $rmat['historicos'];
            $pierdey = $rmat['pierde'];
            if (!empty($rmat['obs_asi'])) {
                $obs .= '<tr><td width="25%">' . formatoPalabras($rmat['no_asi'], $mayus_mat) . '</td><td>' . $rmat['obs_asi'] . '</td></tr>';
            }
            $TotIntHora += $rmat['ihs'];
            $TotNotaComporta = 0;

            $notasInd = $rmat['notasindividuales'];
            ?>
            <tr>
                <td><?php echo formatoPalabras($rmat['no_asi'], $mayus_mat); ?></td>
                <td class="bordes_arriba nom_doc"><?php echo ucwords($rmat['dte']); ?></td>

                <td width="10%" style="font-size:10pt"><?php
                    if (mb_strtolower($rmat['nl']) == 'bajo') {
                        echo "<b>" . ucfirst($rmat['nl']) . "</b>";
                    } else {
                        echo ucfirst($rmat['nl']);
                    }
                    ?>
                </td>

                <td><?php echo $rmat['fj']; ?></td>
                <td><?php echo $rmat['fi']; ?></td>
                <td><?php echo $rmat['fi'] + $rmat['fj'] ?></td>
                <?php
                $prmSum = empty($prmSum) ? '0.0' : $prmSum;
                if ($bandera) {
                    $txNtNum = ($rmat['prom_mat_tot'] <= $pierdey) ? ('<b>' . numberFormat($rmat['prom_mat_tot'], 1, '.', '') . '</b>') : numberFormat($rmat['prom_mat_tot'], 1, '.', '');
                    $txNtLet = ($rmat['prom_mat_tot'] <= $pierdey) ? ('<b>' . $rmat['prom_mat_tot_let'] . '</b>') : $rmat['prom_mat_tot_let'];
                    $cdAux = '<td style="text-align:center">' . $txNtNum . '</td>';
                    $cdAux .= '<td style="text-align:center">' . $txNtLet . '</td>';
                }
                echo $cdAux;
                ?>
            </tr>
            <?php
            if (!empty($rmat['obs_asi']) && strlen($rmat['obs_asi']) > 5) {
                $observa .= '<tr><td> <strong>- ' . ucfirst($rmat['no_asi']) . ':</strong>' . ucfirst($rmat['obs_asi']) . '</td></tr>';
            }

        endforeach;
        ?>
    </table>

    <?php
    $observacionGral=$row['observaciones'];
   # echo $observacionGral;
    $dtsObserva = str_replace("\n", "<br>", $row['comportamiento']);
    $dtsObserva = str_replace("\t", " ", $dtsObserva);
    #echo $dtsObserva.'<br>';
    $dtsObserva = json_decode($dtsObserva, true);
    $observa = $dtsObserva['obsobserva'];
    #echo $observa .'Hola';
    #print_r($dtsObserva);
    $notaComporta = numberFormat($dtsObserva['notaobserva']); //nota numeros
    $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']) ?>&nbsp;</td>
            <td><?php echo ucfirst($notaDisPeriodo['DESCRIPDIS']) ?> &nbsp;</td>
        </tr>
    </table>

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

    $observacionGral = json_decode($observacionGral, true);
    #var_dump($observacionGral);
    $promueve = $observacionGral['perdio'] == 'N' ? 'SI <u>&nbsp;&nbsp;X&nbsp;&nbsp;</u> &nbsp; NO___' : 'SI___  NO <u>&nbsp;&nbsp;X&nbsp;&nbsp;</u>';

    echo ($banderaFinal) ? "<br>Se promueve al siguiente grado: " . $promueve : '';
    ?>
    <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">
            <td style="vertical-align: bottom">_________________________________<br>
                <?php echo strtoupper($director) ?><br>
                Director(a) 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> Coordinador 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<br>Rectora
            </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">F. Imp: <?php echo date('Y-m-d H:i:s') ?>
                    - &nbsp;&nbsp; <?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();
?>
