<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");

include("DF30000.inc");
require_once("DF80000.php");
require_once("DFMOVCAP.inc");
require_once("DFJQUERY.inc");
//require_once("RG16100_CL.php");
require_once("DFSELMAN.inc");
require_once("DFJSISCI.inc");
include("JQUERY.inc");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
addEvent(window,'load',function(){
	objSelRan=new SelectManager('selran');
	addEvent(ge('tesecorral'),'click',function(){
		getOnLayer({
			idLayer:'divCorrales', 
			action:'RF41000_PR-SRV.php',
			title:'CORRALES',
			width:'200',
			height:'300',
			left:'500',
			top:'50',
			className:'divCorrales'
		},{
			gc:'1',
			ir:objSelRan.getSelectedValue(),
			sc:ge('tesecorral').value
		});
	});
	addEvent(ge('selran'),'change',function(){
		ge('tesecorral').value="";
	});	
	addEvent(ge('tesecorral'),'focus',function(){
		ge('tesecorral').blur();
	});
});
function actDiet(valRad){
	if(confirm("DESEA ACTUALIZAR ESTA DIETA?"))
		openpage('RG41000_AC.php','_self');
}

function checkAllBox(check){
	var objCorr=document.getElementsByName('checorr'),i=0,auxCheck= new Array(),auxi=0;
	for(i=0;i<objCorr.length;i++){
			objCorr['i'].checked=check;
	}
}
function devCheCorr(){
	var objCorr=document.getElementsByName('checorr'),i=0,auxCheck= new Array(),auxi=0;
	for(i=0;i<objCorr.length;i++){
		if(objCorr['i'].checked){
			auxCheck['auxi']=objCorr['i'].value;
			auxi++;
		}
	}
	ge('tesecorral').value= "|"+auxCheck.join('|')+"|";
	removeHTML_OBJECT('divCorrales');
}
</script>
<body onLoad="movCap({idObj:'loadAse'});">
<form name="frm1" id="frm1" method="post" action="" >
    <table width="498"   border="0" align="center" >
      <tr>
        <th colspan="7" nowrap>
          
          <div align="left">
            <label></label>
            APLICACION DIETAS</div></th>
      </tr>
      <tr>
        <td height="19" colspan="5" nowrap class="dataAct">Fecha Actualizacion:
            <input name="fecact" type="text" class="emplea date" id="fecact" size="15" value="<?=date("d/m/Y")?>"
			<?php
 
				if(isset($_POST['fecfin']))
			  		echo 'value="'.$_POST['fecfin'].'"'; 
			  	else
			  		echo 'value="'.date('d/m/Y').'"'; 
			?>/>
          <!--<input name="botcal" id="botcal" value=" ... " type="image" src="logos/cal4.jpg"/> -->
       	    
        </td>
      </tr>
      <tr>
        <td height="19" nowrap class="dataAct">Rancho:</td>
        <td colspan="2" nowrap class="dataAct"><label>
          <select name="selran" id="selran">
		  	<option value="">Seleccione Rancho</option>
			<?php
 
			$sql = mysqli_query($con ,"SELECT * FROM valeryus05 order by descripcion");
			if(isset($_REQUEST['selran']))
				$selRancho=$_REQUEST['selran'];
			else
				$selRancho='';	
			while($row=mysqli_fetch_array($sql)){
				if($row['id_ranchos']==$selRancho)
					echo '<option value="'.$row['descripcion'].'" selected>'.$row['descripcion'].'</option>';
				else
					echo '<option value="'.$row['descripcion'].'">'.$row['descripcion'].'</option>';				
			}
			?>		
        </select>
        </label></td>
        <td colspan="2" nowrap class="dataAct">Corrales:
     
          <input name="tesecorral" type="text" id="tesecorral">     </td>
      </tr>
      <tr>
        <th width="29" height="19" nowrap>SEL</th>
        <th width="60" nowrap><div align="center">CLAVE. </div></th>
        <th width="143" nowrap>NOMBRE DIETA  </th>
		 <th width="96" nowrap>TIPO DE DIETA  </th>
		<th width="56" nowrap><div align="center">TOTAL</div></th>
	  </tr>
	  
	
	<?php

	$f_m="";
	$fec = '24/01/2014';
		include('DF20000.php');
		$fecha_inicial = $f_m;
		$fec = '25/01/2014';
		include('DF20000.php');
		$fecha_final = $f_m;
	echo "<td style=' '>";
		
		$proXlin=3;
$auxNumLin=-1;
@$resultado = mysqli_query($con ,"SELECT * FROM valeryus05 where clavetp <> 'MTA' order by n_reg");
echo mysqli_error($con);
$g=1;
$count=mysqli_num_rows($resultado);
while(@$registro=mysqli_fetch_array(@$resultado)){
$vart5=(isset($dt_invent['ncto']))?$dt_invent['ncto']:"";
$sqb=mysqli_query($con ,"SELECT * FROM valeryus19 where status='HUESPED' and fnumcto= '".$vart5."'");
$reb= mysqli_fetch_array($sqb);

	$auxNumLin++;
	if($auxNumLin==-1 || $auxNumLin%$proXlin==0){
		if($auxNumLin==-1){
			echo "<tr>";
		}else{
			echo "</tr><tr>";
		}
	}
	
	$ToT = $registro['totalcuartos'];
		$TiPo = $registro['descripcion'];
		
		$XoXo = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '".$fecha_inicial."' AND ffecsalida >= '".$fecha_inicial."' and ftipocto = '".$TiPo."' and status <> 'HISTORICO' and cancelado = '0') or (ffecllegada <= '".$fecha_final."' AND ffecsalida >= '".$fecha_final."' and ftipocto = '".$TiPo."' and status <> 'HISTORICO' and cancelado = '0') or (ffecllegada > '".$fecha_inicial."' AND ffecsalida < '".$fecha_final."' and ftipocto = '".$TiPo."' and status <> 'HISTORICO' and cancelado = '0') ");
		echo mysqli_error($con); 
                $i = 0;
		while ($as = mysqli_fetch_array ($XoXo)){
		  $OCU = $as['fnumcto'];
		   $i++;
		}
		
		$aMa = mysqli_query($con ,"SELECT * FROM valeryusst08 WHERE (fec_ini <= '".$fecha_inicial."' AND fec_fin >= '".$fecha_inicial."' and ftipocto = '".$TiPo."' ) or (fec_ini < '".$fecha_final."' AND fec_fin >= '".$fecha_final."' and ftipocto = '".$TiPo."' ) or (fec_ini > '".$fecha_inicial."' AND fec_fin < '".$fecha_final."' and ftipocto = '".$TiPo."') ");
		$a = 0;
		while ($status = mysqli_fetch_array ($aMa)){
		  $desocupadas = $status['fnumcto'];
		   //echo "-".$BLOQUEADAS."";
		   $a++;
		   
		} 
		 
		$rEs =$ToT -$i-$a;
		$vart=(isset($registro['descripcion']))?$registro['descripcion']:"";
		
		echo '<input name="ver1" type="hidden" value="'.$vart.'">';     
		
		echo "<td style=' '>";
		
		echo "<input name='box$g' type='checkbox' value='1' onClick='checkbox$g(box$g.checked)' "; 
	    
		if(isset($_REQUEST['box'.$g])&&$_REQUEST['box'.$g]) echo 'checked';
		
		echo " />";
		
		echo "<em> Hay ".$rEs." Habitaciones ".$vart. " desocupadas </em></td>";    
		
		//echo "<td  style=\"color:#66CCFF\" style=' ' onclick=\"openWindow({action:'ventana.php'},{ncto:'".$dt_invent['ncto']."'})\"><div  style='background-color:".$dt_invent["ocupado"].";' align='center'>
//".$reb['fapellido']."<br>
//<br>".$oco.''.substr($registro['descripcion'],0,5)."<br>".$registro['descripcion']."</div></td>";
		
		echo "<td width='130' style='#66CCFF'>";
		
		echo "<input name='ingHab$g' type='text' tabindex='1' size='4' maxlength='10' onKeyPress='return soloNumeros(event)' onKeyUp='suma_campo()' ";
		
		if(isset($_REQUEST['box'.$g]) && $_REQUEST['box'.$g]=='1'){ 
		echo 'value="' . $_POST['campo1'] .  '" />';
		}else{
		echo 'value="0" disabled />';
		} 
		
		echo "</td>"; 
	
	$g++;
} 
	
	
	/*$encDieta->resetData(array("esAct"=>"0"));
	$sq_dieTa=$encDieta->getRegBySta();
	echo mysqli_error($con);
	
	while($dt_dieTa = mysqli_fetch_array($sq_dieTa)){
		 @$sql = mysqli_query($con ,"SELECT * FROM rgtipdie WHERE id_tipdie='".$dt_dieTa['id_tipdie']."'");
	     $reg1 = mysqli_fetch_array($sql);
		 
		 @$sql2 = mysqli_query($con ,"SELECT * FROM rgdetdie WHERE id_dieta='".$dt_dieTa['id_dieta']."'");
	
			
		echo "<tr>";
		echo '<td><div align="center"'.$class.'><input name="bot" type="radio" value="'. $dt_dieTa["id_dieta"].'" onclick="actDiet(this.value)">&nbsp</div></td>';
		echo '<td><div align="left" '.$class.'>'.$dt_dieTa["id_dieta"]. '&nbsp</div></td>';
		echo '<td><div align="left" '.$class.'>'. $dt_dieTa["nom_diet"]. '&nbsp</div></td>';
		echo '<td><div align="left" '.$class.'>'.$reg1["nom_tip"] . '&nbsp</div></td>';	
		echo '<td><div align="right"'.$class.'>'.number_format($dt_dieTa["tot_dieta"],2,'.',','). '&nbsp</div></td>';
		echo '</tr>';
	}
	mysqli_close($con);
//}	*/
	?>
  </table>
</form>    
	</form>
    </div>
</body>
</html>