<?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'");

    $s="<html>";
    $s.="<head>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
    <meta http-equiv='expires' content='0'>
    <meta http-equiv='Cache-Control' content='no-cache'>
    <meta http-equiv='Pragma' CONTENT='no-cache'>";
    
    $s.="<title>Labor Acad&eacute;mica</title>";

    $s.="</head>";

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


    $s.="<table border=1 width='70%'>";

     $s.="<tr>";
     $s.="<td align='center' rowspan='3'><img src='../../../../imagenes/escudo.jpg' width='90' height='90'/></td>";
    
    //----- NOMBRE DE LA INSTITUCI&oacute;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' rowspan='2'>LABOR ACAD&Eacute;MICA</td>";
     $s.="</tr>";
     $s.="</table><br>";
     
             
             $obj->consulta("CREATE TABLE labor_general SELECT sedes.codigo AS cod_sede, sedes.descripcion AS nom_sede, cursos.grado, cursos.codigo, cursos.jornada, cursos.descripcion AS nom_curso, curso_asignatura_profesor.asignatura, catalogo.descripcion AS nom_asign, curso_asignatura_profesor.intensidad, profesores.cedula, profesores.nombres
                             FROM catalogo INNER JOIN ((sedes INNER JOIN cursos ON sedes.codigo = cursos.sede) INNER JOIN (profesores INNER JOIN curso_asignatura_profesor ON profesores.cedula = curso_asignatura_profesor.profesor) ON (cursos.grado = curso_asignatura_profesor.grado) AND (cursos.codigo = curso_asignatura_profesor.curso)) ON catalogo.codigo = curso_asignatura_profesor.asignatura
                             ORDER BY catalogo.descripcion, profesores.nombres, sedes.orden, cursos.orden");

            
            $sedes1=$obj->consulta("SELECT cod_sede,nom_sede FROM labor_general GROUP BY cod_sede");
            
            
             $sw_sede=1;
             while($row = $obj->fetch_assoc($sedes1)){
             
                    
                  
                       $s.="<table border=1 width='70%'>";
                       $s.="<tr style='font-weight:bold;font-size: 14px;background:#F4BDB0'>
                            <td>SEDE  :".$row['cod_sede']." - ".($row['nom_sede'])."</td>
                            </tr>";
                       $s.="</table>";
                       
                   
                   
                   
                                                         
                   $profes=$obj->consulta("SELECT cedula,nombres FROM labor_general WHERE cod_sede='".$row['cod_sede']."' GROUP BY cedula ORDER BY nombres");
                   
                   
            
                   
                   while($row_pro = $obj->fetch_assoc($profes)){
                   $s.="<br><center><table class='features-table' border=1 width='70%'>"; 
                         
                         $s.="<tr style='background: rgba(184,243,85,0.3)'>";             
                         $s.="<td align='center'>".$row_pro['cedula']."</td>";
                         $s.="<td colspan=3>".($row_pro['nombres'])."</td>
                         </tr>";
                         
                                               
                         $asign=$obj->consulta("SELECT nom_curso,asignatura,nom_asign,intensidad FROM labor_general WHERE cedula='".$row_pro['cedula']."' ORDER BY grado,codigo");
                         
                         $n=1;
                         $total=0;
                
                         while($row_asign = $obj->fetch_assoc($asign)){            
                         
                            $s.="<tr>";
                            $s.="<td align='center'>".$n."</td>";
                            $s.="<td>".($row_asign['nom_curso'])."</td>";
                            $s.="<td>".($row_asign['asignatura'])."  -  ".($row_asign['nom_asign'])."</td>";
                            $s.="<td align='center'>".($row_asign['intensidad'])."</td>";
                            $s.="</tr>";
                         
                            $total=$total+$row_asign['intensidad'];
                            $n=$n+1;
                         }
                        
                         $s.="<tr>
                              <td align='center' colspan=3 width='40%'>TOTAL HORAS</td>
                              <td align='center' width='10%'>".$total."</td>
                              </tr>"; 
                   
                    $s.="</table></center>";                                                  
                   } 
                                                                             
                   $s.="<br><br>";
                 
             } 

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

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

    $obj->disconnect();

  /*

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

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

    */

?>
