<?
session_start();
require('../valtiempoinact.php');
require("../conectar.php");
require("libFormato.php");
$nombremes=array("ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO","SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE");
$nombredias=array("D","L","M","M","J","V","S");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
     <head>
	     <style>
		     .tabla{position:absolute;border-collapse: collapse;table-layout:fixed;left:0;}
		     .m1{background:#045FB4;font-family:arial;font-size:12px;color:#FFFFFF;font-weight:bold;}
		     .m2{background:#585858;font-family:arial;font-size:12px;color:#FFFFFF;font-weight:bold;}
			 .tr{border-bottom:1px solid #A4A4A4;}
			 .d1{font-family:arial;font-size:10px;border-left:1px solid #A4A4A4; color:#848484;font-weight:bold;}
			 .d1:first-child{border-left:1px solid #A4A4A4;}
			 .d2{font-family:arial;font-size:10px;border-left:1px solid #A4A4A4; color:#848484;font-weight:bold;}
			 .p1{background:#585858;font-family:arial;font-size:12px;color:#FFFFFF;font-weight:bold;border-bottom:1px dotted  #A4A4A4;}
			 .p1:hover{cursor:pointer;cursor:hand;}
			 .tr1{font-family:arial;font-size:10px;border-bottom:1px solid #A4A4A4;background:#E0E6F8;color:#6E6E6E;font-weight:bold;display:table-row;}
			 .tr2{font-family:arial;font-size:10px;border-bottom:1px solid #A4A4A4;background:#FFFFFF;color:#6E6E6E;font-weight:bold;display:table-row;}
			 .cuadro{min-width:20px !important;}
			 
			 .activo{background:#F5DA81;border-top:3px solid #FE9A2E;border-bottom:3px solid #FE9A2E; -moz-opacity:.70; filter:alpha(opacity=70); opacity:.70;}
			 .pagado{background:#0431B4;}
			 .reservado{background:#F781BE;}
			 .libre{background:#DF0101;}
			 .fijot{z-index:1000;position:absolute;width:800px; max-height:18px !important;}
			 .fijo1{z-index:1000;position:absolute;width:100px; max-height:20px !important;height:14px;background:#E0E6F8;margin-top:-1px;border-right:solid 3px #A4A4A4;margin-left:-1px;}
			 .fijo2{z-index:1000;position:absolute;width:100px; max-height:20px !important;height:14px;background:#FFFFFF;margin-top:-1px;border-right:solid 3px #A4A4A4;margin-left:-1px;}
	     </style>
		 <script language="javascript" src="js/jquery-1.2.6.min.js"></script>
		 <script>
		     function acordion(name){
			     var tr=document.getElementsByTagName("tr");
				 for(i=0;i<tr.length;i++){
				     id=tr[i].id;
					 if(id==name){
					     disp=tr[i].style.display;
						 if(disp=="" || disp=="table-row"){
						     tr[i].style.display="none";
						 }else{
						      tr[i].style.display="table-row";
						 }
					 }
				 }
			 }
			 
			 function marcar(tr){
			     clase=tr.className;
				 if(/activo/.test(clase)){
				  clase=clase.replace(/activo/,"");
				  tr.className=clase;
				 }else{
				  tr.className=clase+" activo";
				 }
			 }
			 
		 </script>
     </head>
	 <body>
	     <table class="tabla">
		     <tr>
			     <td class="m1"></td>
			 <?
			     $fecha = date("Y-m-d");
                 $ano = substr($fecha, 0, 4);
                 $mes   = substr($fecha, 5, 2);
                 $dia = substr($fecha, 8,2);
				 $anof=$ano+1;
				 $fechaini=$ano."-01-01";
				 $fechafin=$anof."-01-01";
				 $n=1;
				 for($i=$fechaini;$i<$fechafin;$i = date("Y-m-d", strtotime($i ."+ 1 month"))){
				  $ano = substr($i, 0, 4);
                  $mes   = substr($i, 5, 2);
                  $dia = substr($i, 8,2);
				  $nmes=mktime( 0, 0, 0, $mes, 1, $ano );
				  ?>
				  <td colspan="<?echo date("t",$nmes);?>" align="center" class="m<?echo $n?>"><?echo $nombremes[intval($mes-1)]?></td>
				  <?
				  if($n==1){
				     $n=2;
				    }else{
					$n=1;
					}
				 }			 
			 ?>
			 </tr>
			 <tr>
			     <td class="m1"></td>
			     <?
				 $n=1;
				 for($i=$fechaini;$i<$fechafin;$i = date("Y-m-d", strtotime($i ."+ 1 days"))){
				  $ano = substr($i, 0, 4);
                  $mes   = substr($i, 5, 2);
                  $dia = substr($i, 8,2);
				  $nmes=mktime( 0, 0, 0, $mes, 1, $ano );
				  ?>
				  <td class="d<?echo $n?>" align="center"><? echo $nombredias[intval(date("w",strtotime($i)))];?></td>
				  <?
				     if($n==1){
				     $n=2;
				    }else{
					$n=1;
					}
				 }			 
				 ?>
			 </tr>
			  <tr class="tr">
			     <td class="m1"><div  style="width:100px;text-align:center">DEPARTAMENTO</div></td>
			     <?
				 $n=1;
				 $cont=1;
				 for($i=$fechaini;$i<$fechafin;$i = date("Y-m-d", strtotime($i ."+ 1 days"))){
				  $ano = substr($i, 0, 4);
                  $mes   = substr($i, 5, 2);
                  $dia = substr($i, 8,2);
				  $nmes=mktime( 0, 0, 0, $mes, 1, $ano );
				  ?>
				  <td class="d<?echo $n?>" align="center"><?echo " ".intval($dia); ?></td>
				  <?
				     if($n==1){
				     $n=2;
				    }else{
					$n=1;
					}
					$cont++;
				 }			 
				 ?>
			 </tr>
			 <?
			 $id=1;
			 $sql="SELECT nombre as propiedad, id_complejo FROM complejo WHERE nombre!='GENERAL'";
			 $r=mysql_query($sql);
			 while($ls=mysql_fetch_array($r)){
			    ?>
				     <tr>
					     <td class="p1" colspan="<?echo $cont?>" onclick="javascript:acordion('<?echo $ls["propiedad"]?>')"><div class="fijot" id="<?echo $id?>"><?echo $ls["propiedad"]?></div>&nbsp;</td>
					 </tr>
				<?
				 $sql="SELECT clave as clave, id_departamento as id FROM departamentos WHERE id_complejo='$ls[id_complejo]'";
			     $res=mysql_query($sql);
				 $tr=1;
			     while($dp=mysql_fetch_array($res)){
				     $id++;
			    ?>
				     <tr class="tr<?echo $tr?>" id="<?echo $ls["propiedad"]?>" onclick="javascript:marcar(this);">
					     <td><div class="fijo<?echo $tr?>" id="<?echo $id?>"><?echo $dp["clave"]?></div>&nbsp;</td>
					 
				<?
				   
				 $n=1;
				 for($i=$fechaini;$i<$fechafin;$i = date("Y-m-d", strtotime($i ."+ 1 days"))){
				  $ano = substr($i, 0, 4);
                  $mes   = substr($i, 5, 2);
                  $dia = substr($i, 8,2);
				  $nmes=mktime( 0, 0, 0, $mes, 1, $ano );
				  
				  $sqlcon="SELECT status_renta FROM conceptos WHERE id_departamento='$dp[id]' AND (dia_inicio BETWEEN '$i' AND '$i' OR dia_salida BETWEEN '$i' AND '$i')";
				  $c=mysql_query($sqlcon);
				  $st=mysql_fetch_array($c);
				  
				  ?>
				  <td class="d<?echo $n;
				   switch($st["status_renta"]){
					     case "PAGADO":              
						                             if($i>date("Y-m-d")){echo " reservado";}else{echo " pagado";}
						                             break;
						 case "OCUPADO": 
						                             echo " pagado";
						                             break;
						 case  "RESERVADO":
						                             echo " reservado";
													 break;													
						 default: if($i>date("Y-m-d")){echo " ";}else{echo " libre";} 
					 }
				  ?>">
				     <div class="cuadro">
					 </div>
				  </td>
				  <?
				  
				     if($n==1){
				     $n=2;
				    }else{
					$n=1;
					}
				 }			
				   
				?>
				</tr>
				<?   
				
				
				  if($tr==1){
				     $tr=2;
				    }else{
					$tr=1;
					}
			     }
				 $id++;
			 }
			 ?>
		 </table>
		 <div id="px"></div>
	 </body>
</html>