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

if (!isset($_SESSION)) { session_start(); }

   $obj = new database();

   $grado=$_REQUEST['grado'];
   $curso=$_REQUEST['curso'];

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


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

    $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>Asignaturas Reprobadas</title>";
    $s.="</head>";

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

    $s.="<table align='center' style='font-family: verdana,arial,sans-serif;font-size:14px' border='1' cellspacing='0' cellpadding='0' class='hovertable' width='90%'>";

     $s.="<tr>";
     $s.="<td align='center' rowspan='2'><img src='../imagenes/escudo.jpg' width='100' height='90'/></td>";

     /*----- NOMBRE DE LA INSTITUCI&oacute;N-GRADO-CURSO- ----- */

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

     $s.="<tr>";
     $s.="<td align='center'>ALUMNOS CON ASIGNATURAS REPROBADAS<br>GRADO : ".$grado." - GRUPO : ".$curso."</td>";
     $s.="</tr>";

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

     $query = $obj->consulta("SELECT alumnos.codigo,alumnos.p_apellido,alumnos.s_apellido,alumnos.p_nombre,alumnos.s_nombre 
                              FROM alumnos INNER JOIN matriculas ON alumnos.codigo=matriculas.codigo 
                              WHERE matriculas.grado='".$grado."' 
                              AND matriculas.curso='".$curso."' 
                              AND matriculas.estado='A'");

     $n = $obj->numero_de_filas($query);

  if ($n > 0) {  //--$n

    while ($row = $obj->fetch_assoc($query)){  //---ALUMNOS -----

      $query1 = $obj->consulta("SELECT boletin.periodo,boletin.asignatura,detalleboletin.valor_asigna,detalleboletin.superacion FROM boletin INNER JOIN detalleboletin ON boletin.numero=detalleboletin.boletin WHERE alumno='".$row['codigo']."' and (definitiva='.b' OR definitiva='D') ORDER by boletin.periodo");
      $n1 = $obj->numero_de_filas($query1);

      if ($n1 > 0) {
          
          $s.="<table align='center' border='1' cellspacing='0' cellpadding='0' class='hovertable' width='90%'>";
          $s.="<tr style='background:#CEECF5;font-family: verdana,arial,sans-serif;font-size:12px'>";
          $s.="<td width='20%' align='center'>".$row['codigo']."</td>";
          $s.="<td>&nbsp;&nbsp;".$row['p_apellido']." ".$row['s_apellido']." ".$row['p_nombre']." ".$row['s_nombre']."</td>";
          $s.="</tr></table>";
      
          $s.="<table style='font-family: verdana,arial,sans-serif;font-size:12px' align='center' border='1' cellspacing='0' cellpadding='0' class='hovertable' width='90%'>";         

          $s.="<tr>";
          $s.="<td width='15%' align='center'>TRIMESTRE</td>";
          $s.="<td width='55%' align='center'>ASIGNATURA</td>";
          $s.="<td width='15%' align='center'>VALORACI&Oacute;N</td>";
          $s.="<td width='15%' align='center'>SUPERACI&Oacute;N</td>";          
          $s.="</tr>"; 
                          
          while ($row1 = $obj->fetch_assoc($query1)){
                 
                 $query3 = $obj->consulta("SELECT * FROM catalogo WHERE codigo='".$row1['asignatura']."'");
                 $row3 = $obj->fetch_assoc($query3);
                 
                 $s.="<tr>";
                 $s.="<td align='center'>".$row1['periodo']."</td>";
                 $s.="<td>&nbsp;&nbsp;".$row1['asignatura']." - ".$row3['descripcion']."</td>";
                 $s.="<td align='center'>&nbsp;&nbsp;".$row1['valor_asigna']."</td>";
                 $s.="<td align='center'>&nbsp;&nbsp;".$row1['superacion']."</td>";
                 $s.="</tr>";          
          
          }
          $s.="</table><br>";
          
      } 
   }
 
 } //--$n

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

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

    $obj->disconnect();

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

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

    $obj->disconnect();

?>