<?php

if(!isset($_SESSION)) {  session_start();  } 
include("DMMYSQLG.php");
include("DMMYSQLG.php");
include("varfun.php");
include("JQUERY.inc");
?>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<?php
      
		 
		 if ($_POST['fol_ini'] == '' || $_POST['fol_fin'] == ''){
		 echo alert_js("INGRESE LOS FOLIOS");
                 echo '<meta content="1; url=res_modificar_PR.php"  HTTP-EQUIV="REFRESH">';
		 return false;
		 
		 }
		 elseif(empty($_POST['tipo_hab'])){
		 echo alert_js("SELECCIONE EL TIPO DE HABITACION");
		 return false;
		 
		 }
		 elseif(empty($_POST['select1'])){
		 echo alert_js("SELECCIONE EL GRUPO");
                  echo '<meta content="1; url=res_modificar_PR.php"  HTTP-EQUIV="REFRESH">';
		 return false;
                
		 
		 }
		 $ini = $_POST['fol_ini'];
		 $fin = $_POST['fol_fin'];
		 $dif = $fin - $ini;
		 $dXd = $dif + 1;
		 
		 $fec = $_POST['ffecllegada'];
		 include('DF20000.php');
		 $fecha_inicial = $f_m;
        
		 $fec = $_POST['ffecsalida'];
		 include('DF20000.php');
		 $fecha_final = $f_m;
       
         $eDe = $_POST['tipo_hab'];
        
		 $FrF = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '$fecha_inicial' AND ffecsalida > '$fecha_inicial' and ftipocto = '$eDe' and status != 'HISTORICO' and cancelado = '0') or (ffecllegada < '$fecha_final' AND ffecsalida >= '$fecha_final' and ftipocto = '$eDe' and status != 'HISTORICO' and cancelado = '0') or (ffecllegada > '$fecha_inicial' AND ffecsalida < '$fecha_final' and ftipocto = '$eDe' and status != 'HISTORICO' and cancelado = '0') "); 
		 
		 while ($tipo = mysqli_fetch_array ($FrF)){
		 
		 $Ocu[] = $tipo['fnumcto'];
		 
		 }
	     $varO=(isset($Ocu))?$Ocu:"";
		 $contador = count($varO);
		 
		 if ($contador == 0){
						   
		 $WeW = mysqli_query($con ,"select * from valeryus08 where ntipo = '$eDe' order by ncto");
						 
		 }else{
					
		 for ($d=0; $d<= $contador-1; $d++){
                       	       
		 $data[] = "ncto <> '$varO[$d]'";
						   
		 }          
					 
		 $Where = implode(" and ",$data);		    
		                
		 $WeW = mysqli_query($con ,"select * from valeryus08 where $Where and ntipo = '$eDe' order by ncto");
	     
		 }           
					
		 while ($ob = mysqli_fetch_array($WeW)){
		      
		 $desob[] = $ob['ncto'];
		 $deso[] = $ob['ntipo'];
		         
	     }		
		 			
		 $count = count($desob);
		 
		 if ($dXd > $count){
		 echo alert_js("NO HAY SUFICIENTES HABITACIONES");
		echo '<meta content="1; url=res_modificar_PR.php"  HTTP-EQUIV="REFRESH">';
                 return false;
                 
		 }
		 
		 for ($e=0; $e<= $dif; $e++){
        
		 $n = $_POST["fol_ini"];
		 
		 $n_reg[] = $n + $e;
		               	       
		 $dat[] = mysqli_query($con ,"update valeryus19 set fnumcto = '$desob[$e]', ftipocto = '$deso[$e]' where n_reg = '$n_reg[$e]'");
		 
		 echo '<h4 align="center">!!! SE MODIFICO EL REGISTRO !!!</h4>';
		 
		 echo '<meta content="1; url=res_modificar_PR.php"  HTTP-EQUIV="REFRESH">';		   
		 }
		   
?> 