<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
include("JQUERY.inc");
$mes=0;
$dia=0;
$anio=0;
//function cambioCelda(celda){
//echo "hola";
//}
?>
  
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script type="text/javascript" language="JavaScript1.2" src="js/searchtable.js"></script>
<script>
    $(function() {
		  theTable = $("#latabla");
		  $("#q").keyup(function() {
			$.uiTableFilter(theTable, this.value);
		  });
		});
</script>
<script type="text/javascript">
    
/*function(datos){
		//	document.getElementById(arrData.idLayer).style.display='';
		//	if(typeof arrData.width!='undefined' && typeof arrData.height!='undefined')
		//		resLay(arrData);
		//	document.getElementById(arrData.idLayer).innerHTML=datos;
		//}
	});

function getAjaxSource(){
	return "rec_checkin_PR-SRV.php";	
}

	
	   
	    function cambVCVia_color(celda){
	ajaxRequest("rec_checkin_PR-SRV.php",{
		g1:'1',
		celda2:celda
		
	},{
		okLoad:function(ceCVlda2){
			alert("Asignando......");
			
		celda.style.backgroundColor="#FF00CC";
		//return "rec_checkin_PR-SRV.php";	
		document.form1.submit();
        
		}
		}

});
*/
function cambia_color(celda,color){	
		//url: "rec_checkin_PR-SRV.php";
		//okLoad.('rec_checkin_NU.php');
                
		celda.style.backgroundColor="#FF00CC"
		//return "rec_checkin_PR-SRV.php";	


                var cto=$(celda).find(".desocu").html().trim();        
		var form={};
		
		form.ncto=cto;
		form.usuario='<?php echo $_SESSION['usuario']?>';
var r=false;		
    if(color=="#FF00CC"){
        form.status='DESASIGNADO';
                     r = confirm("\BFEsta seguro que desea des-asignar la HABITACION?");
        }else{
	form.status='ASIGNADO';
        r = confirm("\BFEsta seguro que desea asignar la HABITACION?");
     }
	if (r == true) {				
       $.ajax({ 
            data: form,
            url: 'ws_setstatus.php',
            type: 'post',
            beforeSend: function () {
                $("#desocu").html(name + " Guardando....");
            },
            success: function (response) {
                //$("#desocu").html(name);
                if (response.trim() == "ok") {	
                    document.getElementById('frm1').submit();
                }else { alert("OCURRIO UN PROBLEMA, intentarlo mas tarde!!"); }
            }
			});
} else {   }			

      //  envia('rec_checkin_PR-SRV.php','_self');
}

 





/*ajaxRequest(
		getAjaxSourcee()
	,{ 
		cancelaPedido:1
	},{
		async:false,
		okLoad:function(datos) {
			document.mainForm.submit();				
		}
	});

/*		
	
	ajaxRequest(
		getAjaxSource(),{
			agp:'A'
		},{
			async:true,
			okLoad:function(datos){
				
				ge('bot').value=datos;	
			}
	});	*/
		
	

</script>

<link href="css/estilo1.css?1" rel="stylesheet" type="text/css">
	
<body>

<div align="center">
  <form name="form1" id="form1" method="post" action="">
    <table width="486" border="0" align="center">
	    <tr>
        <th colspan="2"><span class="Estilo5">CHART DE OCUPACI&Oacute;N X CUARTO</span></th>
      </tr>
      <tr>
        <th width="344"> <input name="r1" type="radio" value="ffecllegada" tabindex="1">
        PERIODO</th>
        <th width="132"><input name="r1" type="radio" value="ncto" tabindex="2">
        HABITACI&Oacute;N</th>
      </tr>
      <tr>
        <td><div align="center">
                <?php $fech=(isset($_POST['t1']))?$_POST['t1']:date('d/m/Y'); ?>
          <input name="t1" type="text" class="thcons datefrom" id="t1" size="15"  readonly onBlur="valFecha(this)" value="<?=$fech?>"
			  <?php
 
			  if(isset($_POST['t1'])){
			  	echo 'value="'.$_POST['t1'].'"'; 
			  }else{
			  	echo 'value="'.date('d/m/Y').'"'; 
			  }
			  ?>
			  >
		      &nbsp;
		  <!--    <input name="reset2"  value=" ... " id="bot1" type="image" src="logos/cal4.jpg"/>
		      --><span class="Estilo16">/</span>
		      
       
          <input name="t2" type="text" class="thcons dateto" id="t2" size="15" readonly onBlur="valFecha(this)" value="<?php $tmt = mktime($mes, $dia, $anio); $eft = $tmt + 604800 ; // Eso me dar�a el timestamp de la fecha sumada 120 minutos. 
		   $fecha = date("d/m/Y", $eft); 
           echo $fecha;?>"			 				
		  <?php
 
			  	
			if(isset($_POST['t2'])){
			echo 'value="'.$fecha.'"'; 
			}else{
			echo 'value="'.$fecha.'"'; 
			}?>>
		         &nbsp;
		<!--    <input name="reset" value=" ... " id="bot2" type="image" src="logos/cal4.jpg"/>
		-->		
        </div></td>
        <td><div align="center">
          <input name="s3" type="text" id="s3" onBlur="may(this)" size="15"/>
        </div></td>
      </tr>
      <tr>
        <td colspan="2"><div align="center">
		<?php

		include("DE10000.php");
		?>
		<?php
                
		 $inicio=(isset($_POST['t1']))?$_POST['t1']:"";
		 $final=(isset($_POST['t2']))?$_POST['t2']:"";
         ?> 
		  <input name="Submit" type="submit" class="original" value="Buscar" />
		  <input name="bot4" type="button" class="bot_WsW" onClick="openpage('valeryus69000_IM.php?fec=<?php echo "".$inicio."";?>&fec2=<?php echo "".$final."";?>','_self')" value="Pdf"/>
		  <!--input name="imprimir" type="button" class="original" value="Imprimir" onClick="envia('rec_disponibilidad_IM.php?fec=<?php //echo "".$inicio."";?>&fec2=<?php //echo "".$final."";?>','_self')"/>
		  <input name="bot4" type="button" class="bot_WsW" onClick="envia('valeryus69000_IME.php?fec=<?php //echo "".$inicio."";?>&fec2=<?php //echo "".$final."";?>','_self')" value="Excel"/-->
        </div></td>
		<?php
                 if(!isset($_POST['t1'])){
                

		$f=mysqli_query($con ,"select n_reg,ffecllegada,ffecsalida,fnumcto,cancelado,status,fmuncto,fnumctos from valeryus19 where chart='0'");
	         while ($r=mysqli_fetch_array($f)){
	              $d=mysqli_query($con ,"insert into chart set n_reg='".$r['n_reg']."', ffecllegada='".$r['ffecllegada']."', "
                              . "ffecsalida='".$r['ffecsalida']."', fnumcto='".$r['fnumcto']."', cancelado='".$r['cancelado']."',"
                              . " status='".$r['status']."', fmuncto='".$r['fmuncto']."'");
				        $s=mysqli_query($con ,"update valeryus19 set chart='1' where n_reg='".$r['n_reg']."'");
	}

	       $i=mysqli_query($con ,"SELECT n_reg, ffecllegada, ffecsalida, fnumcto, cancelado, status, fmuncto, extra1, fnumctos from valeryus19 where chart='1'");
		      while ($y=mysqli_fetch_array($i)){
			          $u=mysqli_query($con ,"UPDATE chart set ffecllegada='".$y['ffecllegada']."', ffecsalida='".$y['ffecsalida']."', fnumcto='".$y['fnumcto']."',
			           cancelado='".$y['cancelado']."', status='".$y['status']."', fmuncto='".$y['fmuncto']."', extra1='".$y['extra1']."', fnumctos='".$y['fnumctos']."' 
			           where n_reg='".$y['n_reg']."'");
			  }   
        
                         
                 }

     

        
         
         
         
        
		?>
      </tr>
    </table>
  </form>
</div>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="" >
  <input name="botf1" type="hidden" value="
  <?php
 
  if(!isset($_POST['t1'])){
  	echo date('d/m/Y');
  }else{
  	echo $_POST['t1'];
  }
  ?>">
      <input name="botf2" type="hidden" value="
  <?php
 
  if(!isset($_POST['t1'])){
  	echo date('d/m/Y');
  }else{
  	echo $_POST['t2'];
  }
  ?>">
  <?php

	if(isset($_POST['t1'])){
		$fec = $_POST['t1'];
		include('DF20000.php');
			$ffecllegada = $f_m;
		$fec = $_POST['t2'];
		include('DF20000.php');
			$ffecsalida = $f_m;
		
	}
	?>
        <div id="busqueda" style="color:#000">
             Busqueda Rapida <input type="text" style="width: 70%" id="q" name="q" value=""  placeholder="cualquier texto de la busqueda actual(nombre, folio, hab.)"/>
		</div>
  	  <table width="713" border='1' id="latabla" bordercolor="#FFFFFF" bordercolordark="#FFFFFF">
              <thead>
              <tr>
        <th  colspan="61"><span class="Estilo2 Estilo3">CHART DE OCUPACI&Oacute;N X CUARTO</span></th>
	  </tr>
	
	     <tr>
        <th width="104"><div align="center">HABITACI&Oacute;N</div>          </th>        <div align="center"></div>                
      <th width="593" colspan="60">FECHA
	     </tr>
             </thead>
      <tbody>
	     <tr>
		 <th>&nbsp; </th>
	       
	           <?php

			   if(isset($_POST['t1'])){
		$fec = $_POST['t1'];
		include('DF20000.php');
			$ffecllegada = $f_m;
		$fec = $_POST['t2'];
		include('DF20000.php');
			$ffecsalida = $f_m;
			
	 while ( dateCmp($ffecllegada,$ffecsalida)<=0)
	 {
	echo "<td><div class='Estilo13'> ".whatDay($ffecllegada)." ".chfecha($ffecllegada,'Y-m-d','dd')."</div></td>";
	 
	 	$ffecllegada=addDay($ffecllegada,1); 
		
	 	 }
		 }
	 ?>        
        </tr>
<?php

		 if(isset($_POST['t1'])){
$fec = $_POST['t1'];
			include('DF20000.php');
				$ffecllegada = $f_m;
			$fec = $_POST['t2'];
			include('DF20000.php');
				$ffecsalida = $f_m;

				
        
        $query="folios, tipos";
              $from= " FROM valeryus08 ";
        
        $select=" SELECT ncto,ntipo,ocupado";
        $col=1;
	//echo dateCmp($ffecllegada,$ffecsalida);
              while ( dateCmp($ffecllegada,$ffecsalida)<=0) 
			  {
                 $select.=","."folios".$col;
                 $select.=","."tipos".$col;
                
                 $from.=" left outer join (SELECT GROUP_CONCAT(n_reg SEPARATOR ',') as folios$col, GROUP_CONCAT(status SEPARATOR ',') as tipos$col,fnumcto 
                            FROM chart where ffecllegada <= '$ffecllegada' 
                           and  ffecsalida>='$ffecllegada'
                            and cancelado='0' and extra1='0' and ffecllegada>'2014-01-01'  group by fnumcto) as dia$col on dia$col.fnumcto=ncto 
                           ";
     $col++; 
                  $ffecllegada=addDay($ffecllegada,1); 
                 }
                 $query=$select.$from." where ntipo<>'MAESTRA' order by ncto";
        $sql=mysqli_query($con ,$query);  

        ?>		
        
	<?php
        
   $col; 
		while($reg = mysqli_fetch_array($sql))
		{ 
		
				echo "<tr>";
				echo "<td style='background-color:".$reg['ocupado'].";  ;'><div align='center'>" . $reg["ncto"] ." | ".$reg['ntipo']. "&nbsp</div></td>";
				
		
	for ($i=1;$i<$col;$i++) {
	 echo "<td onclick='cambia_color(this,\"".$reg['ocupado']."\")'>";
             $folios=  explode(",", $reg['folios'.$i]);
             $tipos=  explode(",", $reg['tipos'.$i]);
                            
                        
				for ($j=0;$j<count($tipos);$j++) {
                                  //  echo $tipos[$j];
                                    if (trim($tipos[$j])=='RESERVA INDIVIDUAL' || trim($tipos[$j])=='RESERVA GRUPO'){
                                    echo "<div   style='background:#FF3366; color:#000000; font-size:12px'>Folio:". $folios[$j] ."</div>";
   echo "<div style='background:#00CC00; color:#000000; display:none; font-size:12px' class='desocu' > ".$reg['ncto']." </div>";	
                                      }elseif ($tipos[$j]=='HUESPED'){
                                    //echo "<div style='background:#FFFFFF; color:#000000; font-size:12px'>Folio:". $reb["n_reg"] ."". $reb["status"] ."". $reb["cancelado"] ."</div>";
                                    echo "<div   style='background:#FFFFFF; color:#000000; font-size:12px'>Folio:".  $folios[$j]."</div>";
   echo "<div style='background:#00CC00; color:#000000; display:none; font-size:12px' class='desocu' > ".$reg['ncto']." </div>";	
                                            }elseif ($tipos[$j]==''){
                                    echo "<div style='background:#00CC00; color:#000000; display:none; font-size:12px' class='desocu' > ".$reg['ncto']." </div>";	
					}else{
				echo "<div style='background:#FFFFFF; color:#000000; font-size:12px'>Folio:". $reb["n_reg"] ."</div>";	
					}
                                }
                                echo "</td>"; 
}
	
	///out
		 //$sqb2=mysqli_query($con ,"SELECT n_reg FROM chart where ffecllegada <= '$ffecllegada' and  fecha_real>'$ffecllegada' and fmuncto= '".$reg['ncto']."'and cancelado='0' and ffecllegada>'2013-04-01'");
	
			//while ($reb2= mysqli_fetch_array($sqb2)) {
				//echo "<div style='background:#FF9933; color:#000000; font-size:12px'>Folio:". $reb2["n_reg"] ."</div>";
			//}
			
			}	 	 
			
                        
			echo "</tr>";	
		}
	mysqli_close($con);	

	?>    
        </tbody>
  </table>
  </form>   
  </div>
</body>
</html>
