<?php

include_once'conection.php';


 ini_set('date.timezone','America/Bogota');
    $fecha = date("Y-m-d");
   //$fecha = '2021-01-08';
 
    $sql = $connection->prepare("SELECT cu,cedula_fun, CONCAT(fun.primer_nombre, ' ',fun.segundo_nombre, ' ',fun.primer_apellido, ' ',fun.segundo_apellido) nombre ,COUNT(fun.cedula_funcionario) cantidad  FROM funcionario fun, det_pre_fun det 
WHERE  fun.cedula_funcionario = det.cedula_fun AND det.fecha_quiz = '$fecha' AND det.jornada = 'pm'
GROUP by fun.cedula_funcionario
HAVING COUNT(fun.cedula_funcionario) >= 1
ORDER BY cedula_fun ASC");
    $sql->execute();
    $rows = $sql->fetchAll(PDO::FETCH_ASSOC); 

 //   echo "<pre>"; 
 //        print_r($rows);    
 //   echo "<pre>"; 

 // echo $rows[0]['cantidad'];


?>
<table id="tabla_lista" class="table table-striped table-bordered">
              <thead>
                  <tr>
                     <th style="font-size:36px" colspan="4">Fecha Reporte: <?php echo $fecha ?></th>
                 </tr>
                <tr>
                  <!-- <th class="d-none">orden</th> -->
                  <th>cu</th>
                  <th>cedula</th>
                  <th>nombre</th>
                  
                  <th>Falta de aire?</th>
                  <th>Fiebre?</th>
                  <th>Tos seca?</th>
                  <th>Fatiga?</th>
                  <th>Congestión?</th>
                  <th>Dolor de garganta?</th>
                  <th>Sin olfato o gusto?</th>
                  <th>Malestar?</th>
                  <th>Náuseas, Vómito, Diarrea?</th>
                  <th>contacto sospechoso?</th>
                  <th>Dolor de cabeza?</th>
                  <th>ind</th>
                  

                  
                  

                </tr>
              </thead>
              <tbody>


                <?php

                $aux_cedula=0;
                $j=1;

                foreach ($rows as $resul) {
                    $cedula = $resul['cedula_fun'];
                    $nombre = $resul['nombre'];
                    $cu = $resul['cu'];
                    $cant = $resul['cantidad'];


                      if ($cant >= 10) {
                        if ($aux_cedula != $cedula) {
                            $aux_cedula=$cedula;

                            if ($j!=1) {
                                echo "</tr>";
                              }
                              echo "<tr>";
                              $j=0;




                              echo "<td>".$cu."</td>";
                              echo "<td>".$cedula."</td>";
                              echo "<td>".$nombre."</td>";
                              

$sql2 = $connection->prepare("SELECT * FROM det_pre_fun det, preguntas WHERE det.cons_pre = preguntas.cons AND cedula_fun =  $cedula AND fecha_quiz = '$fecha' AND jornada = 'pm' ORDER BY orden asc ");
    $sql2->execute();
    $datos2 = $sql2->fetchAll(PDO::FETCH_ASSOC);


                                $problemas=0;
                                $alex = 0;
                            foreach ($datos2 as $value) {
                                
                                $alex++;
                                
                                $p = $value['resp'];

                                $r = fmod($p,2);


                                if($r==1){
                                    $problemas++;
                                    $var = "Si";
                                       echo "<td style='background: yellow' align='center'>".$var."</td>";  

                                }else{
                                     $var = "No"; 
                                      echo "<td align='center'>".$var."</td>";

                                }                                  
                                
                            }
                            
                              if ($alex == 10)
                                {
                                  echo "<td align='center'> - </td>";
                                }

                             echo "<td align='center'>".$problemas."</td>";
                              

                        } 
                        }                                     

                }
                 ?>
              </tbody>
        </table>
   
 




