<?php
session_start();
require('45789417/ref4780.php');
if (!isset($_SESSION['userid'])) {
	echo "<script language='Javascript'> location.href='login.php';</script>";
   	exit();
	};
class Buscador {
	var $host=DB_SERVER,$user=DB_USER,$pass=DB_PASS,$db=DB_NAME,$c_Servidor='Se conecto con el servidor correctamente',$i_Servidor='No se conecto con el Servidor',$c_DB='Se selecciono correctamente la DB',$i_DB='No se selecciono la DB';
	public function Conectar() {	
    		$this->conexion = new mysqli($this->host, $this->user, $this->pass,$this->db) or die(mysql_error());
      		$this->conexion->set_charset("utf8");
	} 
	public function Buscar($q) {
		$query = $this->conexion->query("SELECT * FROM hc_paciente WHERE name LIKE '%$q%' or cc LIKE '%$q%'")or die($this->conexion->error);
		if (mysqli_num_rows($query)<=0){
			print '<div id="alert2"><div align="right"><a HREF="javascript:history.go(0)"><span style="color: black;" class="glyphicon glyphicon-remove-circle"></span> </a></div>No se encontro ningun resultado</div>';		
		} else {
			print '<div id="alert2"><div align="right"><a HREF="javascript:history.go(0)"><span style="color: black;" class="glyphicon glyphicon-remove-circle"></span> </a></div><table class="table table-hover">
					<thead>
					  <tr>
						<th>Cedula</th>
						<th>Nombre</th>
						<th>Edad</th>
						<th>Ultimo Registro </th>
						<th></th>
					  </tr>
					</thead><tbody>';
			while ($row = mysqli_fetch_assoc($query)) {
				print ' <tr>
						<td>'.$row['cc'].'</td>
						<td>'.$row['name'].'</td>
						<td>'.$row['age'].' años</td>
						<td>'.$row['proceso'].'</td>
						<td><a class="btn btn-default btn-xs" href="result_diet.php?id='.$row['id'].'"><span class="glyphicon glyphicon-search"> Ver</span></td>
					  </tr>';
			}
			print '</tbody></table></div>';
		}
			
	}
}
?>
