<?php

    require_once '../app/model/db.class.php';
    require_once '../dompdf/dompdf_config.inc.php';
    require_once '../dompdf/www/functions.inc.php';

    $periodo=$_REQUEST['periodo'];

    $obj = new database();

    $obj->conectar(); $obj->consulta("set names 'utf8'");
    

    $obj->consulta("DELETE FROM cursos_temporal");
    $obj->consulta("INSERT INTO cursos_temporal(grado,codigo,jornada,descripcion,sede) select grado,codigo,jornada,descripcion,sede from cursos order by orden");

    $obj->consulta("create table faltantes_rendimiento select distinct grado,curso from rendimiento_general where periodo='".$periodo."'");

    $obj->consulta("delete from cursos_temporal where (grado,codigo) in (select grado,curso from faltantes_rendimiento)");

    $obj->consulta("DROP TABLE faltantes_rendimiento");



       /*-------------  HTML -----------*/

    $s="<html>";
    $s.="<head><meta http-equiv='expires' content='0'><meta http-equiv='Cache-Control' content='no-cache'><meta http-equiv='Pragma' CONTENT='no-cache'>";
    $s.="<title></title>";
    $s.="<link rel='stylesheet' type='text/css' href='style.css'/>";
    $s.="<script type='text/javascript' src='consolidado.js'></script>";
    $s.="</head>";

    $s.="<body>";
    $s.="<center>";

    $s.="<table width='80%'>";

     $s.="<tr>";
     $s.="<td align='right' rowspan='3'><img src='../imagenes/escudo.jpg' width='90' height='90'/></td>";
    
     /*----- NOMBRE DE LA INSTITUCIÓN-SEDE-GRADO-CURSO- ----- */

     $datos=$obj->consulta("select * from registrar");
     $row_inst = $obj->fetch_assoc($datos);
     $s.="<td align='center' colspan='5'>".($row_inst['institucion'])."</td>";
     $s.="</tr>";

     $s.="<tr>";
     $s.="<td align='center' colspan='5'>FALTANTES POR PROCESO DE RENDIMIENTO ACADEMICO</td>";
     $s.="</tr>";
     $s.="</table></center>";

     /*---- Mostramos los cursos por sedes ---- */

     $sedes=$obj->consulta("select * from sedes order by orden");


     while($row_s = $obj->fetch_assoc($sedes)){

            $cursos=$obj->consulta("select * from cursos_temporal where sede='".$row_s['codigo']."' order by orden_grados,orden_cursos");

            $s.="<center>".($row_s['descripcion'])."</center><BR>";
            $s.="<center><table align='center' border='1' class='hovertable' cellspacing='0' cellpadding='0' width='80%'>";
            $s.="<tr align='center'><td><b>GRADO</b></td> <td><b>CURSO</b></td> <td><b>DESCRIPCION</b></td></tr>";

            $l=1;
            while($row_plan = $obj->fetch_assoc($cursos)){
                 $s.="<tr>";
                 $s.="<td align='center' width='25%'>".$row_plan['grado']."</td>";
                 $s.="<td align='center' width='25%'>".$row_plan['codigo']."</td>";
                 $s.="<td width='50%'>".$row_plan['descripcion']."</td>";
                 $s.="</tr>";
                 $l++;
            }

            $s.="</table></center><br>";

     }



     
     $s.="</body></html>";

     /*--------------------------------------*/
//    echo $s;

    $obj->disconnect();

    $dompdf = new DOMPDF();
    $dompdf->load_html($s);
    $dompdf->set_paper('A4', 'portrait');
    $dompdf->render();

    $dompdf->stream("faltantes_rendimiento.pdf", array("Attachment" => false));



    $obj->disconnect();

   

?>

