<?php
    $id = $_GET["id"];
    $cant = $_GET["cant"];

    $arrayGeneral = array();
    $dia_1 = array();
	$queryAnalitica = mysqli_query($connect,"SELECT * FROM Analitica_Vivo WHERE created_at	>= '2021-01-18 00:00:00' AND created_at <= '2021-01-18 13:00:00' ");
	while($dataAnalitica = mysqli_fetch_array($queryAnalitica)){
        $dataSnap = json_decode($dataAnalitica["dato"]);
        foreach($dataSnap as $data){
            array_push($dia_1, $data->user);
        }
	}
    $dia_1 = array_unique($dia_1);

    $dia_2 = array();
	$queryAnalitica = mysqli_query($connect,"SELECT * FROM Analitica_Vivo WHERE created_at	>= '2021-01-18 13:01:00' AND created_at <= '2021-01-18 23:59:00' ");
	while($dataAnalitica = mysqli_fetch_array($queryAnalitica)){
        $dataSnap = json_decode($dataAnalitica["dato"]);
        foreach($dataSnap as $data){
            array_push($dia_2, $data->user);
        }
	}
    $dia_2 = array_unique($dia_2);


    $dia_3 = array();
	$queryAnalitica = mysqli_query($connect,"SELECT * FROM Analitica_Vivo WHERE created_at	>= '2021-01-19 00:00:00' AND created_at <= '2021-01-19 23:59:00' ");
	while($dataAnalitica = mysqli_fetch_array($queryAnalitica)){
        $dataSnap = json_decode($dataAnalitica["dato"]);
        foreach($dataSnap as $data){
            array_push($dia_3, $data->user);
        }
	}
    $dia_3 = array_unique($dia_3);

    
    $dia_03 = array();
	$queryAnalitica = mysqli_query($connect,"SELECT * FROM Analitica_Vivo WHERE created_at	>= '2021-01-20 00:00:00' AND created_at <= '2021-01-20 23:59:00' ");
	while($dataAnalitica = mysqli_fetch_array($queryAnalitica)){
        $dataSnap = json_decode($dataAnalitica["dato"]);
        foreach($dataSnap as $data){
            array_push($dia_03, $data->user);
        }
	}
    $dia_03 = array_unique($dia_03);

    $dia_04 = array();
	$queryAnalitica = mysqli_query($connect,"SELECT * FROM Analitica_Vivo WHERE created_at	>= '2021-01-21 00:00:00' AND created_at <= '2021-01-21 23:59:00' ");
	while($dataAnalitica = mysqli_fetch_array($queryAnalitica)){
        $dataSnap = json_decode($dataAnalitica["dato"]);
        foreach($dataSnap as $data){
            array_push($dia_04, $data->user);
        }
	}
    $dia_04 = array_unique($dia_04);


/*
nombre
user
vista
*/
?>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js"></script>
<div class="row" style="padding-top: 15px;">
    
    <!-- FICHA -->
	<div class="col-md-12" style="margin-bottom: 20px">
        <div class="card" align="center">
          <div class="card-body">
			<h1>Visitas a esta página</h1>
              <b><?php echo $cant; ?></b>
          </div>
        </div>
    </div>
    
    
    <!-- FICHA -->
	<div class="col-md-12" align="center">
        <h1>Interacciones usuarios únicos</h1>
    </div>

    <!-- FICHA -->
	<div class="col-md-4">
        <table width="100%" style="background-color: #607d8b; color: #ffffff;">
			<tr>
				<td align="center" style="font-size: 20px; line-height: 35px;">
					Dia 1 - Mañana<br>
					<b style="font-size: 50px;"><?php echo count($dia_1) ; ?></b>
				</td>
			</tr>
		</table>
    </div>
    
    
    <!-- FICHA -->
	<div class="col-md-4">
        <table width="100%" style="background-color: #607d8b; color: #ffffff;">
			<tr>
				<td align="center" style="font-size: 20px; line-height: 35px;">
					Dia 1 - Tarde<br>
					<b style="font-size: 50px;"><?php echo count($dia_2) ; ?></b>
				</td>
			</tr>
		</table>
    </div>
    
    
    <!-- FICHA -->
	<div class="col-md-4">
        <table width="100%" style="background-color: #607d8b; color: #ffffff;">
			<tr>
				<td align="center" style="font-size: 20px; line-height: 35px;">
					Dia 2 - Mañana<br>
					<b style="font-size: 50px;"><?php echo count($dia_3) ; ?></b>
				</td>
			</tr>
		</table>
    </div>
    
    
    <!-- FICHA -->
	<div class="col-md-4">
        <table width="100%" style="background-color: #607d8b; color: #ffffff;">
			<tr>
				<td align="center" style="font-size: 20px; line-height: 35px;">
					Dia 3 <br>
					<b style="font-size: 50px;"><?php echo count($dia_03) ; ?></b>
				</td>
			</tr>
		</table>
    </div>
    
    <!-- FICHA -->
	<div class="col-md-4">
        <table width="100%" style="background-color: #607d8b; color: #ffffff;">
			<tr>
				<td align="center" style="font-size: 20px; line-height: 35px;">
					Dia 4 <br>
					<b style="font-size: 50px;"><?php echo count($dia_04) ; ?></b>
				</td>
			</tr>
		</table>
    </div>

	
	
	<!-- FICHA -->
	<div class="col-md-12" >
        
        <!-- INICIA -->
        <div class="card" style="margin-top: 20px">
            <div class="card-header">
                <h2>Día 1 - Mañana</h2>
            </div>
            <div class="card-body">
                <table class="table">
                  <thead>
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">Participante</th>
                        <th scope="col">Documento</th>
                      <th scope="col">Fecha</th>
                    </tr>
                  </thead>
                  <tbody>
                      <?php
                        $count = 1;
                        foreach($dia_1 as $dia){
                            $queryUser = mysqli_query($connect,"SELECT * FROM Asistentes WHERE id = '".$dia."' ");
                            $dataUser = mysqli_fetch_array($queryUser);
                            
                            
                            $txt_pais = '';
                            foreach($Lista_pais as $pais){
                                if($pais[0] == $dataUser["pais"] ){
                                    $txt_pais = $pais[1];
                                }
                            }
                            
                            echo '
                            <tr>
                              <th scope="row">'.$count.'</th>
                              <td>'.$dataUser["nombre"].' '.$dataUser["apellidos"].'</td>
                              <td>'.$dataUser["cedula"].'</td>
                              <td>18 de enero - tarde</td>
                            </tr>
                            ';
                            $count++;
                        }
                      ?>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- TERMINA -->
        
        
        <!-- INICIA -->
        <div class="card" style="margin-top: 20px">
            <div class="card-header">
                <h2>Día 1 - Tarde</h2>
            </div>
            <div class="card-body">
                <table class="table">
                  <thead>
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">Participante</th>
                        <th scope="col">Documento</th>
                      <th scope="col">Fecha</th>
                    </tr>
                  </thead>
                  <tbody>
                      <?php
                        $count = 1;
                        foreach($dia_2 as $dia){
                            $queryUser = mysqli_query($connect,"SELECT * FROM Asistentes WHERE id = '".$dia."' ");
                            $dataUser = mysqli_fetch_array($queryUser);
                            
                            
                            $txt_pais = '';
                            foreach($Lista_pais as $pais){
                                if($pais[0] == $dataUser["pais"] ){
                                    $txt_pais = $pais[1];
                                }
                            }
                            
                            echo '
                            <tr>
                              <th scope="row">'.$count.'</th>
                              <td>'.$dataUser["nombre"].' '.$dataUser["apellidos"].'</td>
                              <td>'.$dataUser["cedula"].'</td>
                              <td>18 de enero - tardes</td>
                            </tr>
                            ';
                            $count++;
                        }
                      ?>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- TERMINA -->
        
        
        
        <!-- INICIA -->
        <div class="card" style="margin-top: 20px">
            <div class="card-header">
                <h2>Día 2 - Mañana</h2>
            </div>
            <div class="card-body">
                <table class="table">
                  <thead>
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">Participante</th>
                        <th scope="col">Documento</th>
                      <th scope="col">Fecha</th>
                    </tr>
                  </thead>
                  <tbody>
                      <?php
                        $count = 1;
                        foreach($dia_3 as $dia){
                            $queryUser = mysqli_query($connect,"SELECT * FROM Asistentes WHERE id = '".$dia."' ");
                            $dataUser = mysqli_fetch_array($queryUser);
                            
                            
                            $txt_pais = '';
                            foreach($Lista_pais as $pais){
                                if($pais[0] == $dataUser["pais"] ){
                                    $txt_pais = $pais[1];
                                }
                            }
                            
                            echo '
                            <tr>
                              <th scope="row">'.$count.'</th>
                              <td>'.$dataUser["nombre"].' '.$dataUser["apellidos"].'</td>
                              <td>'.$dataUser["cedula"].'</td>
                              <td>19 de enero - mañana</td>
                            </tr>
                            ';
                            $count++;
                        }
                      ?>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- TERMINA -->
        
        
        <!-- INICIA -->
        <div class="card" style="margin-top: 20px">
            <div class="card-header">
                <h2>Día 3</h2>
            </div>
            <div class="card-body">
                <table class="table">
                  <thead>
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">Participante</th>
                        <th scope="col">Documento</th>
                      <th scope="col">Fecha</th>
                    </tr>
                  </thead>
                  <tbody>
                      <?php
                        $count = 1;
                        foreach($dia_03 as $dia){
                            $queryUser = mysqli_query($connect,"SELECT * FROM Asistentes WHERE id = '".$dia."' ");
                            $dataUser = mysqli_fetch_array($queryUser);
                            
                            
                            $txt_pais = '';
                            foreach($Lista_pais as $pais){
                                if($pais[0] == $dataUser["pais"] ){
                                    $txt_pais = $pais[1];
                                }
                            }
                            
                            echo '
                            <tr>
                              <th scope="row">'.$count.'</th>
                              <td>'.$dataUser["nombre"].' '.$dataUser["apellidos"].'</td>
                              <td>'.$dataUser["cedula"].'</td>
                              <td>20 de enero - mañana</td>
                            </tr>
                            ';
                            $count++;
                        }
                      ?>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- TERMINA -->
        
        
        
        
        <!-- INICIA -->
        <div class="card" style="margin-top: 20px">
            <div class="card-header">
                <h2>Día 4</h2>
            </div>
            <div class="card-body">
                <table class="table">
                  <thead>
                    <tr>
                      <th scope="col">#</th>
                      <th scope="col">Participante</th>
                        <th scope="col">Documento</th>
                      <th scope="col">Fecha</th>
                    </tr>
                  </thead>
                  <tbody>
                      <?php
                        $count = 1;
                        foreach($dia_04 as $dia){
                            $queryUser = mysqli_query($connect,"SELECT * FROM Asistentes WHERE id = '".$dia."' ");
                            $dataUser = mysqli_fetch_array($queryUser);
                            
                            
                            $txt_pais = '';
                            foreach($Lista_pais as $pais){
                                if($pais[0] == $dataUser["pais"] ){
                                    $txt_pais = $pais[1];
                                }
                            }
                            
                            echo '
                            <tr>
                              <th scope="row">'.$count.'</th>
                              <td>'.$dataUser["nombre"].' '.$dataUser["apellidos"].'</td>
                              <td>'.$dataUser["cedula"].'</td>
                              <td>21 de enero</td>
                            </tr>
                            ';
                            $count++;
                        }
                      ?>
                    </tbody>
                </table>
            </div>
        </div>
        <!-- TERMINA -->
        
        
       
        
        
        
    </div>


	
</div>


<style>
.col-md-4{
	margin-bottom:15px
}

.col-md-6{
	margin-bottom:15px
}

.btn-primary_blue{
	color: #fff;
    background-color: #2196f3;
    border-color: #2196f3;
}

</style>

<?php
$arrayFechas = array();
$arraycantidad = array();
$querySol = mysqli_query($connect,"SELECT COUNT(id),update_at FROM Asistentes WHERE acepto = 'on' GROUP BY DAYOFMONTH(update_at) ORDER BY update_at ASC  ");
while($dataSol = mysqli_fetch_array($querySol)){
    
    $fh = explode(" ", $dataSol["update_at"]);
	array_push($arrayFechas, $fh );
	array_push($arraycantidad, $dataSol["COUNT(id)"] );

}

?>

<script>
	var MONTHS = <?php echo json_encode($arrayFechas) ?>;
	var config = {
			type: 'line',
			data: {
				labels: MONTHS,
				datasets: [{
					label: 'Registros Días',
					backgroundColor: "#03A9F4",
					borderColor: "#035da5",
					data: <?php echo json_encode($arraycantidad) ?>,
					fill: false,
				}]
			},
			options: {
				responsive: true,
				title: {
					display: true,
					text: 'Registrados'
				},
				tooltips: {
					mode: 'index',
					intersect: false,
				},
				hover: {
					mode: 'nearest',
					intersect: true
				},
				scales: {
					x: {
						display: true,
						scaleLabel: {
							display: true,
							labelString: 'Month'
						}
					},
					y: {
						display: true,
						scaleLabel: {
							display: true,
							labelString: 'Value'
						}
					}
				}
			}
	};

	
</script>




