<div align="left" style="padding: 10px 0px;">
	<table width="100%">
    	<tr>
        	<td><h5 style="margin-top: 8px;"><i class="fas fa-check"></i> LIST</h5></td>
            <td align="right" width="200">
            	
            </td>
        </tr>
    </table>
</div>





<div class="table-responsive">
	<table class="table table-bordered table-sm">
		<thead class="thead-dark">
		<tr>
			<th scope="col">#</th>
			<th scope="col">Fecha</th>
            <th scope="col">Nombre</th>
			<th scope="col">País</th>
			<th scope="col">Correo</th>
			<th scope="col">Ciudad</th>
			<th scope="col">Documento</th>
			<th scope="col">Especialidad</th>
			<th scope="col">Tratamientos</th>
			<th scope="col">Acepto</th>
            <th scope="col">Pre Registro</th>
            <th scope="col">Origen</th>
		</tr>
		</thead>

		<tbody id="tabla_lista">
		<?php
			$count = 1;
			$query = mysqli_query($connect,"SELECT * FROM Asistentes_pre");
			while($data = mysqli_fetch_array($query)){
                
                $queryCedula = mysqli_query($connect,"SELECT * FROM Asistentes_list WHERE cedula = '".$data["cedula"]."' ");
                
                
                $preregistrado = 'no';
                if($queryCedula->num_rows > 0){
                    $preregistrado = 'SI';
                    //$dataCedula = mysqli_fetch_array($queryCedula);
                    //mysqli_query($connect,"UPDATE Asistentes_list SET origen = 1 WHERE id = '".$dataCedula["id"]."' ");
                }
                else{
                   mysqli_query($connect,"INSERT INTO Asistentes_list (nombre, apellidos, correo, pais, ciudad, cedula, celular, especialidad, 
                   direccion, eps, ips, tratamientos, acepto, origen, created_at, update_at) 
                   VALUES 
                   ('".$data["nombre"]."', '".$data["apellidos"]."', '".$data["correo"]."', '".$data["pais"]."', '".$data["ciudad"]."', '".$data["cedula"]."', '".$data["celular"]."', '".$data["especialidad"]."', 
                   '".$data["direccion"]."', '".$data["eps"]."', '".$data["ips"]."', '".$data["tratamientos"]."', '".$data["acepto"]."', '".$data["origen"]."', '".$data["created_at"]."', '".$data["update_at"]."' ) "); 
                }


                $txt_pais = '';
                foreach($Lista_pais as $pais){
                    if($pais[0] == $data["pais"] ){
                        $txt_pais = $pais[1];
                    }
                }
                $txt_origen = '';
                if($data["origen"] == 1){
                    $txt_origen = "PreR";
                }
                if($data["origen"] == 1){
                    $txt_origen = "web";
                }
                
				echo '
				<tr>
					<th scope="row">'.$count.'</th>
                    <td>'.$data["created_at"].'</td>
					<td>'.$data["nombre"].' '.$data["apellidos"].'</td>
					<td>'.$txt_pais.'</td>
					<td>'.$data["correo"].'</td>
					<td>'.$data["ciudad"].'</td>
					<td>'.$data["cedula"].'</td>
					<td>'.$data["especialidad"].'</td>
					<td>'.$data["tratamientos"].'</td>
					<td>'.$data["acepto"].'</td>
                    <td>'.$preregistrado.'</td>
                    <td>'.$txt_origen.'</td>
				</tr>
				';
				$count++;

			}
		?>
		</tbody>
	</table>
</div>


<script src="js/functions.js"></script>