<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
include ("varfun.php");
include("JQUERY.inc");
$f_m="";
?>
<html>
<HEAD> <meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">

</HEAD>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
  
<body>
<div align="left">

</div>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
    <table width="441" border="0">
	<tr> <th colspan="2"><span class="Estilo16">HISTORICO DE ESTANCIAS</span></th> 
	</tr>
	<tr>
	  <td colspan="2"><div align="center"><span class="Estilo19">De:</span>
              <?php    $ffecllegada=(isset($_POST['fec']))?$_POST['fec']:date('d/m/Y'); ?>
	      <input name="fec" type="text" class="emplea datefrom" id="fec" size="9" maxlength="20" value="<?= $ffecllegada?>"
			<?php

				if(isset($_POST['fec'])){ //este es el truco
					echo 'value="' . $_POST['fec'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"
		/>
        
            <span class="Estilo19">A:</span>
            <?php    $ffecllegada2=(isset($_POST['fec2']))?$_POST['fec2']:date('d/m/Y'); ?>
            <input name="fec2" type="text" class="emplea dateto" id="fec2" size="9" maxlength="20"  value="<?= $ffecllegada2?>"
			<?php

				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"
		/>
          
	  </div></td>
	  </tr>
	<tr>
        <td><div align="center" class="Estilo19"><img src="magnifier.png" alt="Buscar" onClick="alert('Buscar')" />
		<select name="r1">
		<option value="APELLIDO"<?php
if(isset($_REQUEST['r1']) && $_REQUEST['r1']=="APELLIDO") echo 'selected';?>>APELLIDO</option>
		<option value="FOLIO"<?php
if(isset($_REQUEST['r1']) && $_REQUEST['r1']=="FOLIO") echo 'selected';?>>FOLIO</option>
		<option value="HABITACION"<?php
if(isset($_REQUEST['r1']) && $_REQUEST['r1']=="HABITACION") echo 'selected';?>>HABITACION</option>
	    </select>
		Asiduos
		
		
		<select name="r2">
		<option value="1"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="1") echo 'selected';?>>1</option>
		<option value="2"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="2") echo 'selected';?>>2</option>
		<option value="3"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="3") echo 'selected';?>>3</option>
		<option value="4"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="4") echo 'selected';?>>4</option>
		<option value="5"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="5") echo 'selected';?>>5</option>
		<option value="6"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="6") echo 'selected';?>>6</option>
		<option value="7"<?php
if(isset($_REQUEST['r2']) && $_REQUEST['r2']=="7") echo 'selected';?>>7</option>
	    </select>
		</div></td>
	</tr>
      <tr>
        <td colspan="2">
          <div align="center">   
            <input name="Submit" type="button" class="original" onClick="openpage('caj_estancias_PR.php','_self')" value="Buscar"/>
			<input name="bot4" type="button" class="bot_WsW" onClick="openpage('caj_estancias_IM.php','_self')" value="Imprimir "/>
		  </div></td>
      </tr>
    </table>
  </form>
</div>
<div align="center">
  <form method="post" action="" >
     <?php

	@$result = mysqli_query($con ,"SELECT * from valeryus19 where status='1'");
	@$tot=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total from valeryus19 where status='1'"));
if(isset($_REQUEST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']=='1'){?>
     <table width="1057" align="center" >
     <tr>
     <th width="50"><div align="center">FOLIO</div></th>
	 <th width="190"><div align="center">HUESPED</div></th>
	 <th width="107">STATUS</th>
	 <th width="35"><div align="center">HAB</div></th>
	 <th width="35"><div align="center">TELEFONO</div></th>
	 <th width="35"><div align="center">DIRECCION</div></th>
	 <th width="49"><div align="center">E-MAIL</div></th>
	 <th width="70"><div align="center">FEC. DE LLEGADA</div></th>
	 <th width="70"><div align="center">FEC. DE SALIDA</div></th>
	 </tr>
	 <?php
 }elseif(isset($_REQUEST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']!='1'){ ?>
	      <table width="1057" align="center" >
          <tr>
          <th width="50"><div align="center">HUESPED</div></th>
	      <th width="190"><div align="center">FOLIO</div></th>
	      <th width="107">STATUS</th>
	      <th width="35"><div align="center">HAB</div></th>
	      <th width="35"><div align="center">TELEFONO</div></th>
	      <th width="35"><div align="center">DIRECCION</div></th>
	      <th width="49"><div align="center">E-MAIL</div></th>
	      <th width="70"><div align="center">FEC. DE LLEGADA</div></th>
	      <th width="70"><div align="center">FEC. DE SALIDA</div></th>
	      </tr>
	      <?php
}elseif(isset($_REQUEST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']=='1'){ ?>
	           <table width="1057" align="center" >
               <tr>
               <th width="35"><div align="center">HAB</div></th>
		       <th width="190"><div align="center">HUESPED</div></th>
		       <th width="50"><div align="center">FOLIO</div></th>
		       <th width="107">STATUS</th>
		       <th width="35"><div align="center">TELEFONO</div></th>
		       <th width="35"><div align="center">DIRECCION</div></th>
		       <th width="49"><div align="center">E-MAIL</div></th>
		       <th width="70"><div align="center">FEC. DE LLEGADA</div></th>
		       <th width="70"><div align="center">FEC. DE SALIDA</div></th>
	           </tr>
			   <?php
}elseif(isset($_REQUEST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']!='1'){ ?>
			   <table width="1057" align="center" >
               <tr>
               <th width="35"><div align="center">HUESPED</div></th>
		       <th width="190"><div align="center">HAB</div></th>
		       <th width="50"><div align="center">FOLIO</div></th>
		       <th width="107">STATUS</th>
		       <th width="35"><div align="center">TELEFONO</div></th>
		       <th width="35"><div align="center">DIRECCION</div></th>
		       <th width="49"><div align="center">E-MAIL</div></th>
		       <th width="70"><div align="center">FEC. DE LLEGADA</div></th>
		       <th width="70"><div align="center">FEC. DE SALIDA</div></th>
	           </tr> 
			   <?php
}elseif(isset($_REQUEST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){ ?>
	                <table width="1057" align="center" >
                    <tr>
                    <th width="190"><div align="center">HUESPED</div></th>
					<th width="50"><div align="center">FOLIO</div></th>
					<th width="35"><div align="center">HAB</div></th>
		            <th width="107">STATUS</th>
		            <th width="35"><div align="center">TELEFONO</div></th>
		            <th width="35"><div align="center">DIRECCION</div></th>
		            <th width="49"><div align="center">E-MAIL</div></th>
		            <th width="70"><div align="center">FEC. DE LLEGADA</div></th>
		            <th width="70"><div align="center">FEC. DE SALIDA</div></th>
	                </tr> 
	                <?php
}elseif(isset($_REQUEST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){ ?>
					<table width="1057" align="center" >
                    <tr>
                    <th width="182"><div align="center">HUESPED</div></th>
					<th width="114"><div align="center">FOLIO</div></th>
					<th width="80"><div align="center">STATUS</div></th>
		            <th width="85">HAB</th>
		            <th width="128"><div align="center">TELEFONO</div></th>
		            <th width="92"><div align="center">DIRECCION</div></th>
		            <th width="112"><div align="center">E-MAIL</div></th>
		            <th width="103"><div align="center">FEC. DE LLEGADA</div></th>
		            <th width="103"><div align="center">FEC. DE SALIDA</div></th>
	                </tr> 
                    <?php
}
	// --->
	  	$fec = (isset($_POST['fec']))?$_POST['fec']:"";
		include('DF20000.php');
		$fecha_inicial = $f_m;

		$fec = (isset($_POST['fec2']))?$_POST['fec2']:"";
		include('DF20000.php');
		$fecha_final = $f_m;
	  // -->
	  
if(isset($_POST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']=='1'){
     echo '<input name="tbusqueda" type="hidden" value="no">';
	 $result = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' order by n_reg");
     @$tot=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total from valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto'901'"));
	
}elseif(isset($_POST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']!="1"){
	 $result=mysqli_query($con ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' group by NomApe having cnt >= '".$_POST['r2']."'");
		
     }elseif(isset($_POST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']=='1'){
	      echo '<input name="tbusqueda" type="hidden" value="r">';
		  $result = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' order by fmuncto");
   	      @$tot=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total from valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901'"));
	    
	 }elseif(isset($_POST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']!='1'){
		  $result=mysqli_query($con ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' group by NomApe having cnt >= '".$_POST['r2']."'");
		  
	      } elseif(isset($_POST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){
	      echo '<input name="tbusqueda" type="hidden" value="p">';
	  	  $result = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' ORDER BY fapellido");
	      @$tot=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status = 'HISTORICO' and fmuncto<>'900' and fmuncto<>'901'"));  
	
	      } elseif(isset($_POST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){
		  $result=mysqli_query($con ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' group by NomApe having cnt >= '".$_POST['r2']."'");
		  }

if(isset($_POST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']=='1'){
     include("DE10000.php");
	 while($reg = mysqli_fetch_array($result)){
	 echo "<tr>";
	 echo "<td> <div align='center'><strong>" . $reg["n_reg"] . "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["fapellido"] .' '.$reg["fnombre"]. "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["status"] . "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["fmuncto"] . "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["ftelefono"] . "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["fdireccion"] . "&nbsp;</strong></div></td>";
	 echo "<td> <div align='center'><strong>" . $reg["fmail"] . "&nbsp;</strong></div></td>";
	 $fec1=$reg["ffecllegada"];
	 include('DF20000.php');
	 echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
	 $fec1=$reg["ffecsalida"];
	 include('DF20000.php');
	 echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";	 }
	 echo "<tr><td><div align='center' style=' '><strong>FOLIOS :</strong></div></td>
     <td><div align=\"center\" style=' '><strong>".$tot['total']."</strong></div></td></tr>";
	      }elseif(isset($_POST['r1']) && $_POST['r1']=="FOLIO" and $_POST['r2']!="1"){
	      include("DE10000.php");
		  $a=0;
	      while($reg = mysqli_fetch_array($result)){
	  	  echo "<tr>";
		  echo "<td colspan='2'> <div align='center'><strong>" . $reg["NomApe"] . "&nbsp;</strong></div></td>";
		  $esT=mysqli_query($con ,"select * from valeryus19 where fnombre='".$reg['fnombre']."' and fapellido='".$reg['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' order by n_reg");
		  while ($anC=mysqli_fetch_array($esT)){
		  echo "<tr><td> <div align='center'><strong>&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["n_reg"] . "&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["status"] . "&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["fmuncto"] . "&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["ftelefono"] . "&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["fdireccion"] . "&nbsp;</strong></div></td>";
		  echo "<td> <div align='center'><strong>" . $anC["fmail"] . "&nbsp;</strong></div></td>";
		  $fec1=$anC["ffecllegada"];
		  include('DF20000.php');
		  echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		  $fec1=$anC["ffecsalida"];
		  include('DF20000.php');
		  echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>"; } $a++;}
	      echo "<tr><td><div align='center' style=' '><strong>HUESPEDES :</strong></div></td>
          <td><div align=\"center\" style=' '><strong>".$a."</strong></div></td></tr>";
		       }elseif(isset($_POST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']=='1'){
			   include("DE10000.php");
	           while($reg = mysqli_fetch_array($result)){
	  	       echo "<tr>";
		       echo "<td> <div align='center'><strong>" . $reg["fmuncto"] . "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["fapellido"] .' '.$reg["fnombre"]. "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["n_reg"] . "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["status"] . "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["ftelefono"] . "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["fdireccion"] . "&nbsp;</strong></div></td>";
		       echo "<td> <div align='center'><strong>" . $reg["fmail"] . "&nbsp;</strong></div></td>";
		       $fec1=$reg["ffecllegada"];
		       include('DF20000.php');
		       echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		       $fec1=$reg["ffecsalida"];
		       include('DF20000.php');
		       echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>"; }
	           echo "<tr><td><div align='center' style=' '><strong>FOLIOS :</strong></div></td>
               <td><div align=\"center\" style=' '><strong>".$tot['total']."</strong></div></td></tr>";
			        } elseif(isset($_POST['r1']) && $_POST['r1']=="HABITACION" and $_POST['r2']!='1'){
			        include("DE10000.php");
	                $e=0;
					while($reg = mysqli_fetch_array($result)){
	  	            echo "<tr>";
		            echo "<td colspan='2'> <div align='center'><strong>" . $reg["NomApe"] . "&nbsp;</strong></div></td>";
		            $esT=mysqli_query($con ,"select * from valeryus19 where fnombre='".$reg['fnombre']."' and fapellido='".$reg['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto<>'900' and fmuncto<>'901' order by fnumcto");
		            while ($anC=mysqli_fetch_array($esT)){
		            echo "<tr><td> <div align='center'><strong>&nbsp;</strong></div></td>";
		            echo "<td> <div align='center'><strong>" . $anC["fmuncto"] . "&nbsp;</strong></div></td>";
					echo "<td> <div align='center'><strong>" . $anC["n_reg"] . "&nbsp;</strong></div></td>";
					echo "<td> <div align='center'><strong>" . $anC["status"] . "&nbsp;</strong></div></td>";
		            echo "<td> <div align='center'><strong>" . $anC["ftelefono"] . "&nbsp;</strong></div></td>";
		            echo "<td> <div align='center'><strong>" . $anC["fdireccion"] . "&nbsp;</strong></div></td>";
		            echo "<td> <div align='center'><strong>" . $anC["fmail"] . "&nbsp;</strong></div></td>";
		            $fec1=$anC["ffecllegada"];
		            include('DF20000.php');
		            echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		            $fec1=$anC["ffecsalida"];
		            include('DF20000.php');
		            echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>"; } $e++;}
	                echo "<tr><td><div align='center' style=' '><strong>HUESPEDES :</strong></div></td>
                    <td><div align=\"center\" style=' '><strong>".$e."</strong></div></td></tr>"; 
					     } elseif(isset($_POST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){
					     include("DE10000.php");
	                     while($reg = mysqli_fetch_array($result)){
	  	                 echo "<tr>";
		                 echo "<td> <div align='center'><strong>" . $reg["fapellido"] .' '.$reg["fnombre"]. "&nbsp;</strong></div></td>";
		                 echo "<td> <div align='center'><strong>" . $reg["n_reg"] . "&nbsp;</strong></div></td>";
		                 echo "<td> <div align='center'><strong>" . $reg["fmuncto"] . "&nbsp;</strong></div></td>";
						 echo "<td> <div align='center'><strong>" . $reg["status"] . "&nbsp;</strong></div></td>";
		                 echo "<td> <div align='center'><strong>" . $reg["ftelefono"] . "&nbsp;</strong></div></td>";
		                 echo "<td> <div align='center'><strong>" . $reg["fdireccion"] . "&nbsp;</strong></div></td>";
		                 echo "<td> <div align='center'><strong>" . $reg["fmail"] . "&nbsp;</strong></div></td>";
		                 $fec1=$reg["ffecllegada"];
		                 include('DF20000.php');
		                 echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		                 $fec1=$reg["ffecsalida"];
		                 include('DF20000.php');
		                 echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>"; }
	                     echo "<tr><td><div align='center' style=' '><strong>FOLIOS :</strong></div></td>
                         <td><div align=\"center\" style=' '><strong>".$tot['total']."</strong></div></td></tr>";
					          } elseif(isset($_POST['r1']) && $_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){
							  include("DE10000.php");
	                          $i=0;
							  while($reg = mysqli_fetch_array($result)){
	  	                      echo "<tr>";
		                      echo "<td colspan='2'> <div align='center'><strong>" . $reg["NomApe"] . "&nbsp;</strong></div></td>";
		                      $esT=mysqli_query($con ,"select * from valeryus19 where fnombre='".$reg['fnombre']."' and fapellido='".$reg['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'");
		                      while ($anC=mysqli_fetch_array($esT)){
		                      echo "<tr><td> <div align='center'><strong>&nbsp;</strong></div></td>";
		                      echo "<td> <div align='center'><strong>" . $anC["n_reg"] . "&nbsp;</strong></div></td>";
							  echo "<td> <div align='center'><strong>" . $anC["status"] . "&nbsp;</strong></div></td>";
		                      echo "<td> <div align='center'><strong>" . $anC["fmuncto"] . "&nbsp;</strong></div></td>";
		                      echo "<td> <div align='center'><strong>" . $anC["ftelefono"] . "&nbsp;</strong></div></td>";
		                      echo "<td> <div align='center'><strong>" . $anC["fdireccion"] . "&nbsp;</strong></div></td>";
		                      echo "<td> <div align='center'><strong>" . $anC["fmail"] . "&nbsp;</strong></div></td>";
		                      $fec1=$anC["ffecllegada"];
		                      include('DF20000.php');
		                      echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		                      $fec1=$anC["ffecsalida"];
		                      include('DF20000.php');
		                      echo "<td> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>"; } $i++;}
	                          echo "<tr><td><div align='center' style=' '><strong>HUESPEDES :</strong></div></td>
                              <td><div align=\"center\" style=' '><strong>".$i."</strong></div></td></tr>"; 
							  }
	mysqli_close($con);
	?>
    </table>
  </form>
</div>
</body>
</html>
<?php

//173--> 100 ultima actualizacion 30/noviembre/2011 HISTORICO DE ESTANCIAS
//359--> 300 ultima actualizacion 15/diciembre/2011 HUESPEDES ASIDUOS
?>