<?php

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

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

    $periodo=$_REQUEST['periodo'];

    /*-------------  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");
     $anyo=$obj->consulta("select * from parametros");

     $row1 = $obj->fetch_assoc($anyo);
     $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'>CANTIDAD DE ASIGNATURAS REPROBADAS</td>";
     $s.="</tr>";

     $s.="<tr>";
     $s.="<td align='center' colspan='2'>PERIODO: ". $periodo."</td>";
     $s.="<td align='center' colspan='3'>A&Ntilde;O LECTIVO: ".$row1['anolectivo']."</td>";
     $s.="</tr>";
     $s.="</table></center>";

    /*--------------------------------------*/

    $num_reg="select * from cursos_temporal where activar='1'";

    $result5 = $obj->consulta($num_reg);
    $numero = $obj->numero_de_filas($result5); // obtenemos el numero de registros

    if  ($numero!=0) {

         $c="";
         
         while($reg_ren = $obj->fetch_assoc($result5)){

            $suma=0;             
            $reg = $obj->consulta("select count(*) as cantidad from  rendimiento_general where periodo='".$periodo."' and grado='".$reg_ren['grado']."' and curso='".$reg_ren['codigo']."'");
            $row = $obj->fetch_assoc($reg);

           if ($c!=$reg_ren['grado']){

              $s.="<center>";
              $s.="<table align='center' border=0 cellspacing='0' cellpadding='0' width='80%'>";
              $s.="<tr>";
              $s.="<td>GRADO: ".$reg_ren['grado']."</td>";
              $s.="</tr>";
              $s.="</table></center>";

           }

              $s.="<center>";
              $s.="<table align='center' border=1 cellspacing='0' cellpadding='0' width='80%'>";
              $s.="<tr align='center'>";
              $s.="<td>".$reg_ren['descripcion']."</td>";
              $s.="<td>ASIGN. REPROBADAS</td>";
              $s.="<td>ALUMNOS</td>";
              $s.="</tr>";


              //-------------------------------
              $i=0;
              while ($suma<$row['cantidad']){

                  $reg1 = $obj->consulta("select count(*) as total from  rendimiento_general where periodo='".$periodo."' and grado='".$reg_ren['grado']."' and curso='".$reg_ren['codigo']."' and bajo=".$i);
                  $row1 = $obj->fetch_assoc($reg1);

                  if ($row1['total']!=0){
                     $s.="<tr align='center'>";
                     $s.="<td colspan=2>".$i."</td>";
                     $s.="<td>".$row1['total']."</td>";
                     $s.="</tr>";
                  }

                  $suma=$suma+$row1['total'];
                  $i++;
              }

              $s.="<tr align='center'>";
              $s.="<td colspan=2>TOTAL ALUMNOS</td>";
              $s.="<td>".$row['cantidad']."</td>";
              $s.="</tr>";

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

              $c=$reg_ren['grado'];

         }
    }


     /*--------------------------------------*/

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

   


    $obj->disconnect();

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

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



    $obj->disconnect();

   

?>

