<?php include('./config/db.php'); ?>
<?php
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=detallePlan.xls");
?>
<?php
$selPlan=(isset($_GET['selPlan']))?$_GET['selPlan']:"";
?>
<table class="table table-hover">
    <thead>
        <tr>
            <th>Id</th>
            <th>Cliente</th>
            <th>Actividad</th>
            <th>F. realizaci&oacute;n</th>
            <th>Adjunto</th>
            <th>Instalaci&oacute;n</th>
        </tr>
    </thead>
    <tbody>
        <?php 
            $sql = "select fi.id, pp.nombrePlan, cli.nombre, act.detalle, fi.fechaRealizacion, fi.adjunto 
            from formularioingreso fi inner join planprevencion pp on fi.planId=pp.id
            inner join cliente cli on cli.id = fi.clienteId
            inner join actividades act on act.id = fi.actividadId
            where pp.id in (:selPlan)";
            $sql=$conexion->prepare($sql); 
            $sql->bindParam(":selPlan",$selPlan);
            $sql->execute();
            $listaInstalaciones = $sql->fetchAll(PDO::FETCH_ASSOC); //almacena todos los registros como arreglo
            foreach($listaInstalaciones as $acta) { ?>
                <tr>
                    <td><?php echo $acta['id'] ?></td>
                    <td><?php echo $acta['nombre'] ?></td>
                    <td><?php echo $acta['detalle'] ?></td>
                    <td><?php echo date("d-m-Y",strtotime($acta['fechaRealizacion']))?></td>
                    <td><?php echo $acta['adjunto'] ?></td>
                    <td>
                        <?php 
                            $sql=$conexion->prepare("SELECT inst.id, inst.nombre as nomInsti FROM formularioingreso ing inner JOIN 
                            formularioinstalacion ins on ins.formularioId = ing.id inner JOIN instalacion inst on inst.id = ins.instalacionId 
                            where ing.id in (:id) order by ins.id asc;");
                            $sql->bindParam(":id",$acta['id']);
                            $sql->execute();
                            $instalaciones = $sql->fetchAll(PDO::FETCH_ASSOC);
                            foreach($instalaciones as $inst) { 
                                echo ($inst['nomInsti']."; ");
                            }
                        ?>
                    </td>
                </tr>
        <?php } ?>
    </tbody>
</table>
