<html>
<head>
<title>CENTRO QUIRURGICO</title>
<link rel="stylesheet" type="text/css" href="../styles/Style.css">
</head>
<body >

<?php
include("bd/sql_variables.php");
include("paginacion/config_newpag.php");
include("paginacion/my_pagina_class.php");
define("NUM_ROWS",'2');
define("NUM_LINKS",'2');

$db_conexion= mysql_connect("$sql_host", "$sql_usuario", "$sql_pass") or die(header ("No Disponible Servidor de Base de Datos"));
mysql_select_db("$sql_db");


echo "<table class='FacetFormTABLE' align='center'><tr><td class='FacetInput'>ACTO MEDICO</td><td class='FacetInput'>AUTOGENERADO</td><td class='FacetInput' align='center'>PACIENTE</td><td class='FacetInput' align='center'>FECHA DE OPERACION</td><td class='FacetInput' width='70' align='center'>OPERACION</td><td class='FacetInput' align='center'>DET. OPERACION</td></tr>";


//if(!$_GET){
//$_pagi_sql = "SELECT A.CQ_NACTM AS ACTOMEDICO,A.CQ_AUTOG as  AUTOGENERADO,A.CQ_NOMBRE AS PACIENTE, DATE_FORMAT(A.CQ_FEOPER,'%d/%m/%Y') AS FECHA_OPE, (SELECT QU_CDES from CQ_OPERA WHERE QU_COPE = A.CQ_OPER2 GROUP BY QU_CDES) AS OPERACION from cq_parte A  order by A.CQ_FEOPER desc ";
//echo $_pagi_sql."-1<br>";
//}else{
$nombre = $_GET['nombre'];
$operacion = $_GET['operacion'];
if (isset($nombre) and isset($operacion)){

$_pagi_sql = "SELECT A.CQ_NACTM AS ACTOMEDICO, A.CQ_AUTOG as  AUTOGENERADO,A.CQ_NOMBRE AS PACIENTE, DATE_FORMAT(A.CQ_FEOPER,'%d/%m/%Y') AS FECHA_OPE, (SELECT QU_CDES from CQ_OPERA WHERE QU_COPE = A.CQ_OPER2 GROUP BY QU_CDES) AS OPERACION from cq_parte A  WHERE A.CQ_OPER2 IN (SELECT QU_COPE from CQ_OPERA WHERE QU_CDES like '$operacion%' GROUP BY QU_CDES) AND A.CQ_NOMBRE LIKE '$nombre%' ORDER BY A.CQ_FEOPER DESC";
//echo $_pagi_sql."-2<br>";
}
else{
if (isset($nombre)){
$_pagi_sql = "SELECT A.CQ_NACTM AS ACTOMEDICO, A.CQ_AUTOG as  AUTOGENERADO,A.CQ_NOMBRE AS PACIENTE, DATE_FORMAT(A.CQ_FEOPER,'%d/%m/%Y') AS FECHA_OPE, (SELECT QU_CDES from CQ_OPERA WHERE QU_COPE = A.CQ_OPER2 GROUP BY QU_CDES) AS OPERACION from cq_parte A  WHERE A.CQ_NOMBRE LIKE '$nombre%' ORDER BY A.CQ_FEOPER DESC";}

if (isset($operacion)){
$_pagi_sql = "SELECT A.CQ_NACTM AS ACTOMEDICO, A.CQ_AUTOG as  AUTOGENERADO,A.CQ_NOMBRE AS PACIENTE,
DATE_FORMAT(A.CQ_FEOPER,'%d/%m/%Y') AS FECHA_OPE, (SELECT QU_CDES from CQ_OPERA WHERE QU_COPE = A.CQ_OPER2 GROUP BY QU_CDES) AS OPERACION
from cq_parte A  WHERE A.CQ_OPER2 IN (SELECT QU_COPE from CQ_OPERA WHERE QU_CDES like '$operacion%' GROUP BY QU_CDES) ORDER BY A.CQ_FEOPER DESC";}

if(!$operacion and !$nombre){
$_pagi_sql = "SELECT A.CQ_NACTM AS ACTOMEDICO,A.CQ_AUTOG as  AUTOGENERADO,A.CQ_NOMBRE AS PACIENTE, DATE_FORMAT(A.CQ_FEOPER,'%d/%m/%Y') AS FECHA_OPE, (SELECT QU_CDES from CQ_OPERA WHERE QU_COPE = A.CQ_OPER2 GROUP BY QU_CDES) AS OPERACION from cq_parte A  order by A.CQ_FEOPER desc ";
}
} //end else
//} //end else


$test = new MyPagina;
       $test->sql = $_pagi_sql;
       $result = $test->get_page_result(); 
       $num_rows = $test->get_page_num_rows();  
       $nav_links = $test->navigation(" | ", "currentStyle"); 
	   $nav_info = $test->page_info("al"); 
       $simple_nav_links = $test->back_forward_link(); 
       $total_recs = $test->get_total_rows(); 


		if ($total_recs>=1)
	   {
		 $i = 0;
		 do
   		 {
		 $actomedico = mysql_result($result, $i, "ACTOMEDICO");
		 $autogenerado = mysql_result($result, $i, "AUTOGENERADO");
   		 $paciente_nombre = mysql_result($result, $i, "PACIENTE");
         $paciente_fecha = mysql_result($result, $i, "FECHA_OPE");
		 $paciente_operacion = mysql_result($result, $i, "OPERACION");

		echo "<tr><td class='FacetFieldCaptionTD'>".$actomedico."</td><td class='FacetFieldCaptionTD'>".$autogenerado."</td><td class='FacetFieldCaptionTD'>".$paciente_nombre."</td><td class='FacetFieldCaptionTD' align='rigth'>".$paciente_fecha."</td><td class='FacetFieldCaptionTD' align='left'>".$paciente_operacion."</td><td class='FacetFieldCaptionTD' align='center'><a href='leerpaciente.php?actomedico=".$actomedico."'><img src='imagen/servicio.png'></a></td></tr>";

		$i++;
  		}while($i < $num_rows);}
  
echo "</table><br>";

echo "<table align='center' class='FacetFormTABLE'><tr><td colspan='9' class='FacetFieldCaptionTD' align='center'><center>";
 if ((isset($total_recs))&&($total_recs>=1)){ echo'Registros(s) del '.$nav_info.' de '.$total_recs.' encontrado(s).' ;}else{echo'0 Registros(s) encontrado(s).';} 
 echo "</center></td></tr><tr><td colspan='9' class='FacetFieldCaptionTD' align='center'><center>";
 if (isset($total_recs)){  echo $nav_links; }
 echo "</center></td></tr>"; 


/*
$result = mysql_query($sql);
if ($result == false){
echo 'PROVOCO UN ERROR EN LA CONSULTA';
}else{
while ($row= mysql_fetch_row($result)){
//while ($row= mysql_fetch_array($result)){
//echo "<tr><td class='FacetFieldCaptionTD'>".$row['AUTOGENERADO']."</td><td class='FacetFieldCaptionTD'>".$row['PACIENTE']."</td><td class='FacetFieldCaptionTD' align='rigth'>".$row['FECHA_SOL']."</td><td class='FacetFieldCaptionTD' align='left'>".$row['OPERACION']."</td><td class='FacetFieldCaptionTD' align='center'><a href='leerpaciente.php?id=".$row['AUTOGENERADO']."&fecha=".$row['FECHA_SOL']."'><img src='imagen/servicio.png'></a></td><td class='FacetFieldCaptionTD' align='center'><a href='detalleservio.php?id=".$row['AUTOGENERADO']."&fecha=".$row['FECHA_SOL']."'><img src='imagen/pdf.jpg' width='15' height='20'></a></td></tr>";
echo "<tr><td class='FacetFieldCaptionTD'>".$row[0]."</td><td class='FacetFieldCaptionTD'>".$row[1]."</td><td class='FacetFieldCaptionTD' align='rigth'>".$row[2]."</td><td class='FacetFieldCaptionTD' align='left'>".$row[3]."</td><td class='FacetFieldCaptionTD' align='center'><a href='leerpaciente.php?id=".$row[0]."&fecha=".$row[2]."'><img src='imagen/servicio.png'></a></td><td class='FacetFieldCaptionTD' align='center'><a href='detalleservio.php?id=".$row[0]."&fecha=".$row[2]."'><img src='imagen/pdf.jpg' width='15' height='20'></a></td></tr>";

}
}
echo "</table>";
//header ("location:carga de datos.php");
*/
?>

</body>
</html>

