<?php

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

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

   $query1=$obj->consulta("SELECT alumnos_desertores.clase_desercion AS codigo, desercion.descripcion
                           FROM desercion INNER JOIN alumnos_desertores ON desercion.codigo = alumnos_desertores.clase_desercion
                           GROUP BY alumnos_desertores.clase_desercion, desercion.descripcion ORDER BY alumnos_desertores.clase_desercion");
  
   $s="<BR><table width='90%' border='1' class='normal' cellspacing='0' cellpadding='2' align='center' id='font'>";
   
   while($row = $obj->fetch_assoc($query1)){ 
   
       $query2=$obj->consulta("SELECT alumnos.codigo AS cod_alumno, CONCAT(p_apellido,' ',s_apellido,' ',p_nombre,' ',s_nombre) AS nombres, cursos.grado, cursos.codigo, cursos.descripcion,alumnos_desertores.fecha
                                FROM cursos INNER JOIN (matriculas INNER JOIN (desercion INNER JOIN (alumnos INNER JOIN alumnos_desertores ON alumnos.codigo = alumnos_desertores.codigo) ON desercion.codigo = alumnos_desertores.clase_desercion) ON matriculas.codigo = alumnos_desertores.codigo) ON (cursos.grado = matriculas.grado) AND (cursos.codigo = matriculas.curso)
                                WHERE (((alumnos_desertores.clase_desercion)=".$row['codigo'].")) ORDER BY cursos.grado, cursos.codigo");
 

  $s.="<tr style='font-size:14px'> 
        <td colspan='5' bgcolor='#CEECF5'>&nbsp;<b>".$row['codigo']." - ".$row['descripcion']. "  </b></td>
        </tr>";

  $s.="<tr align='center' style='font-size:12px'> 
        <td><b>FECHA</b></td> <td><b>CODIGO</b></td>   <td><b>APELLIDOS Y NOMBRES</b></td>  <td><b>GRADO</b></td> <td><b>CURSO</b></td>
        </tr>";
                            
    $i=1;

       while($row1 = $obj->fetch_assoc($query2)){
       
             $s.="<tr style='font-size:12px'> 
                  <td width='10%' align='center'>".$row1['fecha']."</td>
                  <td width='10%' align='center'>".$row1['cod_alumno']."</td>   
                  <td width='50%'>".$row1['nombres']."</td>  
                  <td width='10%' align='center'>".$row1['grado']."</td>  
                  <td width='20%'>".$row1['codigo']." - ".$row1['descripcion']."</td>
                  </tr>";     
       
       } 
   
   
   
   }
   $s.="</table>";
       
       
   $reg1=$obj->consulta("select * from registrar");
   $reg = $obj->fetch_assoc($reg1);
  
   $param1=$obj->consulta("select * from parametros");
   $param = $obj->fetch_assoc($param1);
     

$html="<html>
<head><meta http-equiv='expires' content='0'><meta http-equiv='Cache-Control' content='no-cache'><meta http-equiv='Pragma' CONTENT='no-cache'>
<title>Evaluaci&oacute;n</title>

<style>
  
       .normal {

          border: 1px solid #000;
          border-collapse: collapse;
        }
        .normal th, .normal td {
          border: 1px solid #000;
        }
        
       #font{
            font-size:11px;
        }
        
        .font2{
            font-size:12px;
        }
        
        
</style>
</head>
<body>
<center>
<table align='center' border='0' width='90%'>

<tr><td rowspan='2'><img height='80' width='80' src='../../../../fotografias/escudo.jpg'/></td>
    <td><center><font size='3' ><b>".$reg['institucion']."</b></font></center></td>
</tr>

<tr><td><center><font size='3' ><b>A&Ntilde;O LECTIVO ".$param['anolectivo']."</b></font></center></td></tr>
 
<tr>
    <td colspan='2' bgcolor=#808080><center><font color='#ffffff' size='2' ><b>ALUMNOS DESERTORES</b></font></center></td>
</tr>

</table>
</center>
<br>
".$s."
</body>
</html>";


$obj->disconnect();

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

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

?>