<style>
    td{

FONT-SIZE: 14PX;
    }
</style>
<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
require_once("DF80000.php");
$f_m=""; 
$sa=array();
$bloHab=array();

if(isset($_POST['gc'])){
////		$selRancho=$_POST['ir'];
//		$selCorral=$_POST['sc'];
//		$selNreg=$_POST['rg'];
//		$ffecllegada=$_POST['fl'];
//		$ffecsalida=$_POST['fs'];
	// $tiphab=$_POST['ir'];
		$habsel=isset($_POST['sc'])?$_POST['sc']:"";
		$Nreg=isset($_POST['rg'])?$_POST['rg']:"";
		$ffecllegada=isset($_POST['fl'])?$_POST['fl']:"";
		$ffecsalida=isset($_POST['fs'])?$_POST['fs']:"";	
		
                //print_r($_POST);
		$fec = "".$ffecllegada."";
		include('DF20000.php');
		$fecha_inicial = $f_m;
		//echo $fecha_inicial;
		$fec = "".$ffecsalida."";
		include('DF20000.php');
		$fecha_final = $f_m;
		//echo $fecha_final;
	     
	          //selecciono las habItaciones ocupadas	
	        
				@$ocua = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '$fecha_inicial' AND ffecsalida > '$fecha_inicial'  and status <> 'HISTORICO' and cancelado = '0') or (ffecllegada < '$fecha_final' AND ffecsalida >= '$fecha_final'  and status <> 'HISTORICO' and cancelado = '0') or (ffecllegada > '$fecha_inicial' AND ffecsalida < '$fecha_final'  and status <> 'HISTORICO' and cancelado = '0') ");
				while ($aa = mysqli_fetch_array ($ocua)){
        
		          $sa[] = $aa['fnumcto'];	
		//echo "oooooooooooooooooooooooooooooooooo".$aa['fnumcto']."<br>";
		        }		
			//print_r($sa);	
		$aMa = mysqli_query($con ,"SELECT * FROM valeryusst08 WHERE (fec_ini <= '$fecha_inicial' AND fec_fin > '$fecha_inicial'  ) or (fec_ini < '$fecha_final' AND fec_fin >= '$fecha_final'  ) or (fec_ini > '$fecha_inicial' AND fec_fin < '$fecha_final' ) ");
		
		while ($status = mysqli_fetch_array ($aMa)){
		  $bloHab[] = $status['fnumcto'];
		//echo "bbbbbbbbbbbbbbbbbbbbbbbbbb".$status['fnumcto']."<br>";
		    
		}
		
				  $numa=count($sa);
				  $numb=count($bloHab);
			//	  print_r($bloHab);
				  //echo "-->".$numa."";
				  //echo "-->".$numb."";
				  				  $totHab=$numa+$numb;

		     //echo $totHab;            u
				    if ($totHab == 0){
						   
					  $sq_habdes = mysqli_query($con ,"select * from valeryus08 WHERE  ntipo <> 'MAESTRA' order by ntipo");
						 
					}else{
					   
					  for ($da=0; $da<= $numa-1; $da++){
                        //del total de habitaciones excluyo las ocupadas	       
						$data[] = "ncto <> '$sa[$da]'";
				      }      
                                        for ($da=0; $da<= $numb-1; $da++){      
						
						$datb[] = "ncto <> '$bloHab[$da]'";
				      }    
					    //se dividen de un and
                                  
		                $where = implode(" and ",$data);
                                
						$wherb = implode(" and ",$datb);		    
		                    $wherb=(count($datb)==0)?"":" and ". $wherb;
						//echo $where;
						
                     if(	$where==''){
                          $wherb= substr($wherb, 4); 
					 }						 
						  //habitaciones desocupadas    
		                  $sq_habdes = mysqli_query($con ,"select * from valeryus08 where $where  $wherb AND ntipo <> 'MAESTRA'  order by ntipo");
                              //    echo "select * from valeryus08 where $where $wherb and ntipo <> 'MAESTRA'  order by ntipo";
                                  echo mysqli_error($con);
	                }
	 
		echo '<table border="0" width="500">'; 
		echo "
		<tr>
			<td class=\"encCorr\" width=\"50\"><input type=\"checkbox\" value=\"\" onclick=\"checkAllBox(this.checked)\">Sel.</td>
			<td class=\"encCorr\" width=\"134\"></td>
                        <td class=\"encCorr\" width=\"200\"style=\"color:#9900ff\">HABITACIONES DISPONIBLES</td>
		</tr>";

		while($dt_habd=mysqli_fetch_array($sq_habdes)){
			if(strpos($habsel,"|".$dt_habd['ncto'])!==false){
				$checked='checked';
			}else{
				$checked="";
			}
			echo "
			<tr>
				<td><input type='checkbox' value='".$dt_habd['ncto']."' title='".$dt_habd['ntipo']."'  class='habitacionchk' name='checor'". $checked."></td>
				<td>".$dt_habd['ncto']."</td>
				<td>".$dt_habd['ntipo']."</td></tr>";			
		}
		echo "</table>";
}
?>

<?php

/*if($_POST['oij'] == 1){ 
          //selecciono el tipo de habotacion KING SIZE
	      $tipoa = mysqli_fetch_array(mysqli_query($con ,"select * from valeryus05 where n_reg = '1'"));
            $ta = $tipoa["descripcion"];
		     
	          //selecciono las habotaciones ocupadas	
	          $ocua = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '$fecha_inicial' AND ffecsalida > '$fecha_inicial' and ftipocto = '$ta' and status != 'HISTORICO' and cancelado = '0') or (ffecllegada < '$fecha_final' AND ffecsalida >= '$fecha_final' and ftipocto = '$ta' and status != 'HISTORICO' and cancelado = '0') or (ffecllegada > '$fecha_inicial' AND ffecsalida < '$fecha_final' and ftipocto = '$ta' and status != 'HISTORICO' and cancelado = '0') ");
		        while ($aa = mysqli_fetch_array ($ocua)){
        
		          $sa[] = $aa['fnumcto'];	
		
		        }
				  $numa=count($sa);
		                 
				    if ($numa == 0){
						   
					  $desa = mysqli_query($con ,"select * from valeryus08 where ntipo = '$ta' order by ncto");
						 
					}else{
					   
					  for ($da=0; $da<= $numa-1; $da++){
                        //del total de habitaciones excluyo las ocupadas	       
						$dataa[] = "ncto <> '$sa[$da]'";
						   
				      }          
					    //se dividen de un and
		                $Wherea = implode(" and ",$dataa);		    
		                  //habitaciones desocupadas   
		                  $desa = mysqli_query($con ,"select * from valeryus08 where $Wherea and ntipo = '$ta' order by ncto");
	                }
					
					  while ($oa = mysqli_fetch_array($desa)){
		                //echo "".$owoie['ncto']."";
		                  $desoa[] = $oa['ncto'];
		              }

                        for ($ia=0; $ia<$_POST['campo1']; $ia++){  
		
		                  $varible_clase->ftipocto=strtoupper($tipoa["descripcion"]);
		
		                    $varible_clase->fnumcto=$desoa[$ia];
							
							  $varible_clase->folio=strtoupper("EXTRAS");
							  $varible_clase->fnumadu=$_POST["t25"];
                              $varible_clase->fnummenor=$_POST["t24"];
		                      //echo "".$desoa[$ia]."";
		                      $res=$varible_clase->agregar();
		                }		
}else{
}*/
?>
