require FPDF_PDF_RUTA . 'lib/pdftable.inc.php';
 $p = new PDFTable('P');
 $p->SetMargins(3, 43, 0);
 if ($_POST['modo_resumen']) {
     $p->AddPage('L');
     $p->SetMargins(3, 10, 0);
     $p->titulo(5, $titulo);
     $p->setfont('Arial', '', 8);
     $p->SetTitle(date("d-m-Y") . "_informe");
     $p->SetFillColor(255, 255, 255);
     $p->SetTextColor(0, 0, 0);
     $p->SetDrawColor(0, 0, 0);
     $filtrostab = "<table>";
     $filtrostab .= $l_filtros;
     $filtrostab .= "</table>";
     $p->HTMLtable($filtrostab);
     $p->ln(5);
     $tabla_cantidad = "<table>\n\t\t\t\t<tr><td>Cantidad total de Acciones Correctivas: " . count($acpm) . "</td></tr>\t\n\t\t\t</table>";
     $p->HTMLtable($tabla_cantidad);
     $p->ln(5);
     $color1 = 'A6A6A6';
     $color2 = 'FFFFFF';
     $tit = "bgcolor=#{$color1} color=#{$color2} align=center valign=middle style=bold height=8";
     $nor = "align=center height=5 valign=middle";
     if (!$_POST['ag_tipo']) {
         $tabla = "<table border=1>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td {$tit} width=20>Num NC</td>\n\t\t\t\t\t\t<td {$tit} width=23>Fecha apertura</td>\n\t\t\t\t\t\t<td {$tit} width=140>Causa probable</td>\n\t\t\t\t\t\t<td {$tit} width=54>" . html_entity_decode("Tipo acci&oacute;n") . "</td>\n\t\t\t\t\t\t<td {$tit} width=15>Coste</td>\n\t\t\t\t\t\t<td {$tit} width=19>Fecha cierre</td>\n\t\t\t\t\t\t<td {$tit} width=19>Cierre eficaz</td>\n\t\t\t\t\t</tr>";
     }
 }
 if ($acpm) {
     foreach ($acpm as $key => $valor) {
         if (!$_POST['modo_resumen']) {
if ($_POST['pdf']) {
    require FPDF_PDF_RUTA . 'lib/pdftable.inc.php';
    $p = new PDFTable('L');
    $p->SetMargins(3, 43, 0);
    $p->AddPage('L');
    $p->SetMargins(3, 10, 0);
    $p->titulo(5, $titulo);
    $p->setfont('Arial', '', 8);
    $p->SetTitle(date("d-m-Y") . "_informe");
    $p->SetFillColor(255, 255, 255);
    $p->SetTextColor(0, 0, 0);
    $p->SetDrawColor(0, 0, 0);
    $filtrostab = "<table>";
    $filtrostab .= $l_filtros;
    $filtrostab .= "</table>";
    $p->HTMLtable($filtrostab);
    $p->ln(5);
    $color1 = 'A6A6A6';
    $color2 = 'FFFFFF';
    $tit = "bgcolor=#{$color1} color=#{$color2} align=center valign=middle style=bold height=8";
    $nor = "align=center height=5 valign=middle";
    if ($cursos) {
        $tabla = "<table width=260 border=1>\n\t\t\t<tr>\n\t\t\t\t<td {$tit} width=9>" . html_entity_decode("A&ntilde;o") . "</td>\n\t\t\t\t<td {$tit} width=16>Finalizado</td>\n\t\t\t\t<td {$tit} width=60>Accion formativa</td>\n\t\t\t\t<td {$tit} width=22>Fecha prevista</td>\n\t\t\t\t<td {$tit} width=24>Fecha comienzo</td>\n\t\t\t\t<td {$tit} width=17>Fecha final</td>\n\t\t\t\t<td {$tit} width=50>Impartido por</td>\n\t\t\t\t<td {$tit} width=42>Proceso relacionado</td>\n\t\t\t\t<td {$tit} width=50>Responsable seguimiento</td>\n\t\t\t</tr>";
        foreach ($cursos as $key => $valor) {
            $tabla .= "<tr>\n\t\t\t\t\t<td {$nor}>" . $valor['ano'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['accionfinalizada'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['accionformativa'] . "</td>\t\n\t\t\t\t\t<td {$nor}>" . $valor['fechaprevista'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['fechacomienzo'] . "</td>\t\n\t\t\t\t\t<td {$nor}>" . $valor['fechafinal'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['impartidopor'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['procesorelacionado'] . "</td>\n\t\t\t\t\t<td {$nor}>" . $valor['responsableseguimiento'] . "</td>\t\n\t\t\t\t</tr>";
        }
        $tabla .= "</table>";
    } else {
        echo "<script>alert('No se puede mostrar el informe. No hay cursos.');</script>";
        echo "<script>window.close();</script>";
    }
 $p->SetTitle(date("d-m-Y") . "_revision_direccion");
 $p->SetFillColor(255, 255, 255);
 $p->SetTextColor(0, 0, 0);
 $p->SetDrawColor(0, 0, 0);
 $reunion = select_normal("Select * from kz_tec_dir_reuniones where id = " . $_POST['reunion'] . "");
 $reunion = $reunion[0];
 $p->AddPage('P');
 $p->SetMargins(3, 10, 0);
 $p->titulo(5, $titulo);
 $p->setfont('Arial', '', 8);
 $color1 = 'A6A6A6';
 $color2 = 'FFFFFF';
 $tit = "bgcolor=#{$color1} color=#{$color2} align=center valign=middle style=bold height=8";
 $nor = "align=center height=5 valign=middle";
 $tabla .= "<table border=1>\n\t\t<tr>\n\t\t\t<td {$tit} width=40>Fecha: </td>\n\t\t\t<td {$nor} width=100>" . $reunion['fecha'] . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td {$tit}>Asistentes: </td>\n\t\t\t<td {$nor}> " . $reunion['asistentes'] . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td {$tit}>" . html_entity_decode("Objeto de la reuni&oacute;n") . ": </td>\n\t\t\t<td {$nor}>" . $reunion['objeto'] . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td {$tit}>" . html_entity_decode("Fecha siguiente reuni&oacute;n") . ": </td>\n\t\t\t<td {$nor}>" . $reunion['fechasig'] . ", " . $reunion['horasig'] . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td {$tit}>Departamento: </td><td {$nor}>" . $reunion['departamento'] . "</td>\n\t\t</tr>\n\t</table>";
 $p->HTMLtable($tabla);
 $p->Ln(5);
 $temas_tratados = select_normal("Select * from kz_tec_dir_temasreunion where idreunion  = " . $reunion['id'] . "");
 $tabla = "<table border=1>\n\t\t<tr>\n\t\t\t<td {$tit} width=191>" . html_entity_decode("&Oacute;rden del d&iacute;a") . "</td>\n\t\t\t<td {$tit} width=13>Cerrado</td>\n\t\t</tr>";
 if ($temas_tratados) {
     foreach ($temas_tratados as $key => $valor) {
         $tema = select_normal("Select * from kz_tec_dir_temas where id=" . $valor['idtema'] . "");
         $tema = $tema[0];
         $tabla .= "<tr>\n\t\t\t\t<td {$nor}>" . $tema['tema'] . "</td>\n\t\t\t\t<td {$nor}>" . siono($valor['cerrado']) . "</td>\n\t\t\t</tr>";
     }
 }
 $tabla .= "</table>";
 $p->HTMLtable($tabla);
 $p->ln(5);
 $dec = select_normal("Select * from kz_tec_dir_decisionesreunion a, kz_tec_dir_decisiones b where idreunion=" . $reunion['id'] . " and a.iddecision=b.id");
 $tabla = "<table border=1>\n\t\t<tr>\n\t\t\t<td {$tit} width=132>" . html_entity_decode("Decisi&oacute;n adoptada") . "</td>\n\t\t\t<td {$tit} width=55>Responsable</td>\n\t\t\t<td {$tit} width=17>Plazo</td>\n\t\t</tr>";
     $p->AddPage('L');
     $p->SetMargins(3, 10, 0);
     $p->titulo(5, $titulo);
     $p->setfont('Arial', '', 8);
     $p->SetTitle(date("d-m-Y") . "_informe");
     $p->SetFillColor(255, 255, 255);
     $p->SetTextColor(0, 0, 0);
     $p->SetDrawColor(0, 0, 0);
     $color1 = 'A6A6A6';
     $color2 = 'FFFFFF';
     $tit = "bgcolor=#{$color1} color=#{$color2} align=center valign=middle style=bold height=8";
     $nor = "align=center height=5 valign=middle";
     $filtrostab = "<table>";
     $filtrostab .= $l_filtros;
     $filtrostab .= "</table>";
     $p->HTMLtable($filtrostab);
     $p->ln(5);
     $p->Cell(0, 3, "Cantidad total de NC: " . count($nc), 0, 1);
     $p->Ln(5);
     $tabla = "<table border=1>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td {$tit} width=25>CNC</td>\n\t\t\t\t\t\t<td {$tit} width=20>Fecha detec.</td>\n\t\t\t\t\t\t<td {$tit} width=25>Origen de la NC</td>\n\t\t\t\t\t\t<td {$tit} width=32>Especific. de origen</td>\n\t\t\t\t\t\t<td {$tit} width=27>Clasific. de origen</td>\n\t\t\t\t\t\t<td {$tit} width=30>Detectada por</td>\n\t\t\t\t\t\t<td {$tit} width=75>" . html_entity_decode("Resumen descripci&oacute;n") . "</td>\n\t\t\t\t\t\t<td {$tit} width=10>Coste</td>\n\t\t\t\t\t\t<td {$tit} width=10>Unid.</td>\n\t\t\t\t\t\t<td {$tit} width=19>Fecha cierre</td>\n\t\t\t\t\t\t<td {$tit} width=17>Cierre efic.</td>\n\t\t\t\t\t</tr>";
 }
 if ($nc) {
     foreach ($nc as $key => $valor) {
         if (!$_POST['modo_resumen']) {
             $p->AddPage('P');
             $p->SetMargins(3, 10, 0);
             $p->titulo(5, $titulo);
             $p->setfont('Arial', '', 8);
             $p->SetTitle(date("d-m-Y") . "_informe");
             $p->SetFillColor(255, 255, 255);
             $p->SetTextColor(0, 0, 0);