<?php if(!isset($_SESSION)){session_start();} ////// EMPIEZA CODIGO PARA VERIFICAR LOGEO
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False;
  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { $isValid = true; } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { $isValid = true; } 
    if (($strUsers == "") && true) { $isValid = true;  }  } 
  return $isValid; }
$MM_restrictGoTo = "index.php?banned";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;} ////// TERMINA CODIGO PARA VERIFICAR LOGEO

	require_once('Connections/odonto_connection.php');	
	include_once "ponder.php";

	include("header.html");
	include("menu.html");

	$user=$_SESSION['MM_Username'];
	
$query_rs_todos = "SELECT * FROM `ingreso` WHERE `user` like '$user'";
$rs_ingreso = mysqli_query($odonto_connection,$query_rs_todos) or die(mysql_error());
$row_rs_ingreso = mysqli_fetch_assoc($rs_ingreso);
$clinica=$row_rs_ingreso['clinica'];
	
	
	?>

	//desarrollar el cdodigo debajo de este comentario 

<div class='container' style="background-color:white">	
    <div class='row'>
		<h1>Todos los Pacientes
		
<?php
/*
	$user=$_SESSION['MM_Username'];
	$sql ="SELECT * FROM `ingreso` WHERE `user` LIKE '$user' LIMIT 0 , 30";
	$resultado0 = mysqli_query($odonto_connection,$sql);
	$fila0 = mysqli_fetch_assoc($resultado0);
	$id_user = $fila0['id_user']; */
	//$sql ="SELECT * FROM  `tabla1` ORDER BY fecha ASC";
	$sql ="SELECT * FROM  `tabla1` WHERE `clinica` like '$clinica'";
	$resultado = mysqli_query($odonto_connection,$sql);
	if (!$resultado)
	{ reportarErrorSQL($sql);
	return;} 
	echo "<font style='font-size:18px'>(".mysqli_num_rows($resultado).")</font>";
?></h1><?php
	if(mysqli_num_rows($resultado)==0)
	echo "No hay pacientes agregados";
	else
	{
	
		echo '<div>';
		//echo '<button id="exportarExcel" class="btn btn-primary">Exportar</button>';
		echo "<input type='text' id='myInput' onkeyup='myFunction()' style='width:170px' placeholder='Busqueda por apellido...'></input>";
		echo " <input type='text' id='myInput1' onkeyup='myFunction1()' style='width:170px' placeholder='Busqueda por nombre...'></input>";
		echo " <input type='text' id='myInput2' onkeyup='myFunction2()' style='width:170px' placeholder='Busqueda por dni...'></input>";
		echo "</div><br>";
		echo '<div class="table-responsive">';
		echo '<table class="table table-hover table-bordered" id="myTable">';
		echo "<thead>";
		//echo "<th>N&deg; Ref</th>";
		echo "<th> Apellido </th>";
		echo "<th> Nombre </th>";
		echo "<th> Dni </th>";
		echo "<th> Celu </th>";
		echo "<th> Profesional </th>";
		echo "<th></th>";
		echo "<th></th>";
		echo "<th></th>";
		echo "</thead>";
		echo "<tbody>";
/*
		while ($fila = mysql_fetch_assoc($resultado))
		{
			echo "<tr class=\"hover\">";
			//echo '<td><input type="checkbox" name="idausentismo[]" value="' . $fila["idausentismo"] . '" class="idausentismo" /></td>';
			echo "<td align=\"right\">" . $fila["idausentismo"] . "</td>";
			$apellido=textToHTML( $fila["apellido"] );
			$nombre=textToHTML( $fila["nombre"] );
			$sexo=textToHTML( $fila["sexo"] );
			$ciudad=textToHTML( $fila["ciudad"] );
			$provincia=textToHTML( $fila["provincia"] );
			//$telefono=textToHTML( $fila["telefonocontacto"] );
			$legajo=$fila["legajo"];
			$razonsocial=textToHTML( $fila["razonsocial"] );
			//$domicilio=textToHTML( $fila["domiciliocontacto"] );
			$comentario=textToHTML( $fila["comentario"] );
			$fechainicio=fechaDBToSystem( $fila["fechainicio"] );
			echo "<td>$fechainicio</td>";
			echo "<td>$legajo</td>";
			echo "<td>$apellido</td>";
			echo "<td>$nombre</td>";
			echo "<td>$comentario</td>";
			echo '<td><a href="javascript:cargarDiagnosticoPorAusentismo(' . $fila["idausentismo"] . ');">Detalles</a></td>';
			echo "</tr>";
		}
*/
		while ($fila = mysqli_fetch_assoc($resultado))
		{
		$id_pac=$fila['id_pac'];
		echo "<tr class=\"hover\">";
			//echo "<td align=\"right\">".$fila['id_pac']."</td>";
			echo "<td><a href=\"javascript:verDetalle($id_pac);\">".$fila['paciente']."</a></td>";
			echo "<td><a href=\"javascript:verDetalle($id_pac);\">".$fila['nombre']."</a></td>";
			echo "<td align=\"center\">".$fila['dni']."</td>";
			echo "<td align=\"center\">".$fila['celular']."</td>";
			echo "<td align=\"center\" style=\"font-size:10px\" >".substr($fila['usuario'],0,14)."</td>";
			echo "<td align=\"center\"><a href=\"../ajax/examples/turnos.php?id_pac=$id_pac\">Turno</a></td>";			echo "<td align=\"center\"><a href=\"javascript:verDetalle($id_pac);\">ENTRAR</a></td>";
			echo "<td align=\"center\"><a href=\"detalle_viaje.php?id_pac=$id_pac\">SMS</a></td>";
		echo "</tr>";
		}
		echo "</tbody></table>";
		echo "</div>";
//		mysql_free_result($resultado);
	}
?>

</div>	
</div>	
<?php
	include("footer.html");
?>

<script>
function myFunction() {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[0];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}

function myFunction1() {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput1");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[1];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}

function myFunction2() {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput2");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[3];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}
</script>
