<?php

include '../../../conexion/config.inc.php';
$queryString = "SELECT * FROM sa_estudiantes";
$query = mysql_query($queryString);
echo "<thead>\n\t                  <tr>   \n\t                      <th>Cuenta</th>\n\t                      <th>Identidad</th>\n\t                      <th>Estudiante</th>\n\t                      <th>Correo</th>\n\t                      <th>Indice</th>\n\t                      <th>Mención Honorífica</th>\n\t                      <th>Solicitudes</th>\n\t                      <th></th>\n\t                  </tr>\n\t              </thead>\n                  <tbody>";
while ($row = mysql_fetch_assoc($query)) {
    $estudiante = obtenerEstudiante($row['dni']);
    $correo = obtenerCorreo($row['dni']);
    $mencion = obtenerMencion($row['dni']);
    $solicitudes = obtenercantidadSolicitudes($row['dni']);
    $nuevoRegistro = "<tr>" . "<td id='" . $row['no_cuenta'] . "'>" . $row['no_cuenta'] . "</td>" . "<td id='" . $row['dni'] . "'>" . $row['dni'] . "</td>" . "<td id='" . $row['no_cuenta'] . "'>" . $estudiante . "</td>" . "<td id='" . $row['dni'] . "'>" . $correo . "</td>" . "<td id='" . $row['indice_academico'] . "'>" . $row['indice_academico'] . "</td>" . "<td id='" . $mencion . "'>" . $mencion . "</td>" . "<td id='" . $solicitudes . "'>" . $solicitudes . "</td>" . "<td><a data-no_cuenta = '" . $row['no_cuenta'] . "' class='edit_estudiante btn btn-info fa fa-pencil'></a>" . "&nbsp;&nbsp;<a class='elimina btn btn-danger fa fa-trash-o'></a></td> " . "</tr></tbody>";
    echo $nuevoRegistro;
}
function obtenerEstudiante($dni)
{
    $queryString = "SELECT Primer_nombre,Segundo_nombre,Primer_apellido,Segundo_apellido FROM \n\t\t\t\t\t\tpersona p INNER JOIN sa_estudiantes e ON p.N_Identidad = e.dni WHERE e.dni = '" . $dni . "'";
    $query = mysql_query($queryString);
    $row = mysql_fetch_assoc($query);
    return $row['Primer_nombre'] . " " . $row["Segundo_nombre"] . " " . $row["Primer_apellido"] . " " . $row["Segundo_apellido"];
}
function obtenerCorreo($dni)
{
    $queryString = "SELECT correo from sa_estudiantes_correos where dni_estudiante ='" . $dni . "'";
    $query = mysql_query($queryString);
    $row = mysql_fetch_assoc($query);
    return $row['correo'];
}
function obtenerMencion($dni)
{
    $queryString = "SELECT descripcion FROM sa_menciones_honorificas WHERE codigo in (SELECT cod_mencion FROM sa_estudiantes_menciones_honorificas WHERE dni_estudiante ='" . $dni . "')";
    $pfecha = 'NULL';
} else {
    $pfecha = "'" . $pfecha . "'";
}
if ($tipoSolicitud == NULL) {
    $tipoSolicitud = 'NULL';
}
$query = 'select * from sa_estudiantes';
$result = mysql_query($query);
$json = array();
$contadorIteracion = 0;
while ($fila = mysql_fetch_array($result)) {
    $estudiante = obtenerEstudiante($fila['dni']);
    $correo = obtenerCorreo($fila['dni']);
    $mencion = obtenerMencion($fila['dni']);
    $solicitudes = obtenercantidadSolicitudes($fila['dni']);
    $pdf->Cell(25, 8, utf8_decode($fila['no_cuenta']), 1, 0, "C");
    $pdf->Cell(30, 8, utf8_decode($fila['dni']), 1, 0, "C");
    $pdf->Cell(45, 8, utf8_decode($estudiante), 1, 0, "C");
    $pdf->Cell(40, 8, utf8_decode($correo), 1, 0, "C");
    $pdf->Cell(10, 8, utf8_decode($fila['indice_academico']) . "%", 1, 0, "C");
    $pdf->Cell(33, 8, utf8_decode($mencion), 1, 0, "C");
    $pdf->Cell(10, 8, utf8_decode($solicitudes), 1, 0, "C");
    $pdf->Ln(8);
    //$pdf->Cell($w, $h, $txt, $border)
}
$pdf->SetFont('Arial', '', 10);
//$pdf->Image($maindir.'assets/img/pieDepagina.png', -2,260,212,40, 'PNG');
$pdf->Output();
function obtenerEstudiante($dni)
{