<?php




$cedula = $_GET['cedula'];
$limite = $_GET['limite'];

//$limite = 1;

$host     	= 'localhost';
$user 		= 'coopserp_t1';
$password 	= 'c00ps3rp*';
$db       	= 'coopserp_quiz';

$conn  = new mysqli($host,$user,$password,$db);


// Check connection
if ($conn  -> connect_errno) {
  echo "Failed to connect to MySQL: " . $conn  -> connect_error;
  exit();
}



$sql = "SELECT cedula_fun,CONCAT(primer_nombre,' ',segundo_nombre,' ',primer_apellido,' ',segundo_apellido) nombre,fecha_quiz,COUNT(cedula_fun) cant  FROM det_pre_fun, funcionario
WHERE cedula_fun = funcionario.cedula_funcionario AND
resp IN (1,3,5,7,9,11,13,15,17) AND cedula_fun = '$cedula'
GROUP BY  cedula_fun,nombre,fecha_quiz  
ORDER BY fecha_quiz ASC,cedula_fun ASC,cant DESC
LIMIT ".$limite;

$result = $conn->query($sql);

$titulo = array();
$cant   = array();

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {		
		$titulo[] 	= $row["fecha_quiz"];
		$cant[] 	= $row["cant"];
		$nombre 	= $row["nombre"];
    }
	
} else {
    echo "0 results";
	$nombre = "";
}

$conn  -> close();




//$titulo = array("dia 1","dia 2","dia 3","dia 4","dia 5");
//$cant   = array(2,9,4,5,7);




//$array['primero'=>'1', 'segundo'=>'2'];


?>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">
    google.charts.load("current", {packages:['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ["Fecha", "Sintomas positivos", { role: "style" } ],
        <?php 
		$c = count($titulo);
		for($i=0;$i<$c;$i++){
		 
		    if($i == ($c-1))
			{
				?>
				 ["<?php echo $titulo[$i]?>", <?php echo $cant[$i]?>, "gold"]
				<?php
			}
			else
			{
				?>
				  ["<?php echo $titulo[$i]?>", <?php echo $cant[$i]?>, "gold"],
				<?php				
			}
		  }
		?>
      ]);

      var view = new google.visualization.DataView(data);
      view.setColumns([0, 1,
                       { calc: "stringify",
                         sourceColumn: 1,
                         type: "string",
                         role: "annotation" },
                       2]);

      var options = {
        title: "Reporte de cuadro de sintomas de: <?php echo $nombre?>",
        width: 800,
        height: 400,
        bar: {groupWidth: "50%"},
        legend: { position: "none" },
      };
      var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
      chart.draw(view, options);
  }
  </script>
<div id="columnchart_values" style="width: 900px; height: 300px;"></div>