<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
</head><body>
<?php
include_once("validareprogramacionmes.php");

$mes = mktime( 0, 0, 0, $mm, 1, $anno ); 
$numeroDeDias = intval(date("t",$mes)); 

if(isset($cabcal)){
echo $cabcal;
}

//pregunta por las areas
$Objaa = new Area();
$res_a_p=array();
$res_a_p=$Objaa->listar_area_prog_all_repro($conex,$anno,$mm,$idj,$ids,$idtp,$idga);

if(count($res_a_p)>0){
for($iaa=0;$iaa<sizeof($res_a_p);$iaa++){
$ida=$res_a_p[$iaa]['ida'];
$area=$res_a_p[$iaa]['area'];

$Objhaa = new Horario();
$cantreg=$Objhaa->cont_horario_reprog_area_all($conex,$anno,$mm,$idj,$ids,$idtp,$idga,$ida);

echo "<tr><td rowspan='".$cantreg."' class='llenarTablaGarea' width='120'>".$area."</td>";

$res_h_a = array();
$res_h_a =$Objhaa->lis_horario_reprog_area_all($conex,$anno,$mm,$idj,$ids,$idtp,$idga,$ida);

for($iha=0;$iha<sizeof($res_h_a);$iha++){
$idh=$res_h_a[$iha]['idhora'];
$Objha = new Horario();
$res_hr = array();
$res_hr = $Objha->buscar_horario($conex,$idh);

for($ihs=0;$ihs<sizeof($res_hr);$ihs++){
$hora =$res_hr[$ihs]['hora'];
$turno = $res_hr[$ihs]['turno'];
$numhora = $res_hr[$ihs]['numhora'];
echo "<td class='llenarTablaGareadet' width='120' align='center'>$hora</td><td class='llenarTablaGareadet' align='center'>$turno</td><td align='center' class='llenarTablaGareadet'>$numhora</td>";
}

for ($i=1;$i<=$numeroDeDias;$i++){
$Objhp = new HoraReprogramacion();
$res_hp=array();
$res_hp=$Objhp->listar_hrreprog($conex,$anno,$mm,$idj,$ids,$idtp,$idh,$i,$idga,$ida);


//$resultcontur = mysql_query($sqlconsultaturno);
$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
$fechacal = $anno.'-'.$mm.'-'.$i;
$diaft=0;


$Objdf = new DiaFeriado();
$res_df=array();
$res_df=$Objdf->buscar_dia_feriado($conex,$fechacal);
if(count($res_df)>0){
$diaft=$res_df[0]['tipo'];
}

if(count($res_hp)==0){
switch ($dia) {
    case 0: echo "<td width='20' class ='FacetDataText'> </td>"; break;
    case 1: 
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
		echo "<td align='center' width='20' ";if($diaft==1){ echo " class='FacetDataText'> </td>";}elseif($diaft==2){echo " class='FacetDataTextDNL'> </td>";}else{ echo " class='llenarTabla'> </td>"; }
        break;
}

}else{
for($ihp=0;$ihp<sizeof($res_hp);$ihp++){
$codprog = $res_hp[$ihp]['cod'];
$tipohora = $res_hp[$ihp]['tipo'];
// consulta de cruce de horario
$resalta = validareprog($conex,$anno, $mm, $i, $idj, $ids, $per, $codprog, $idga, $ida, $idh, $tipohora);
$fecha = $anno.'-'.$mm.'-'.$i;	
//moestra programacion 
switch ($dia) {
    case 0: echo "<td width='20'"; if($resalta==2){ echo "bgcolor='green' ";}elseif($resalta==1){ echo "bgcolor='red' ";}elseif($resalta==3){ echo "bgcolor='#48A3F3' ";}elseif($resalta==4){ echo "bgcolor='litlegreen' ";}elseif($resalta==5){ echo "bgcolor='brown' ";}elseif($resalta==6){ echo "bgcolor='pink' ";}elseif($resalta==7){ echo "bgcolor='purple' ";}elseif($resalta==8){ echo "bgcolor='orange' ";} elseif($resalta==11){ echo "bgcolor='#CC66FF' ";} elseif($resalta==12){ echo "bgcolor='#99FF66' ";}elseif($resalta==9){ echo "bgcolor='#FF00CC' ";}elseif($resalta==10){ echo "bgcolor='#CCCC00' ";}else{ echo "class ='FacetDataText' ";} echo " align='center' ><b>"; if($resalta==13){ $lectura = consulta_hrpermiso($conex,$codprog,$fecha,$idtp,$anno,$mm,$idj,$ids);echo  "<img src='' border=0 height='5' width='5' style='background-color:#FF0000;' alt='".$lectura."'>";} if($tipohora==1){ echo $codprog."e</td>";}else{ echo $codprog."</b></td>";} break;
    case 1: 
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        echo "<td width='20'"; if($resalta==2){ echo "bgcolor='green' ";}elseif($resalta==1){ echo "bgcolor='red' ";}elseif($resalta==3){ echo "bgcolor='#48A3F3' ";}elseif($resalta==4){ echo "bgcolor='litlegreen' ";}elseif($resalta==5){ echo "bgcolor='brown' ";}elseif($resalta==6){ echo "bgcolor='pink' ";}elseif($resalta==7){ echo "bgcolor='purple' ";}elseif($resalta==8){ echo "bgcolor='orange' ";} elseif($resalta==11){ echo "bgcolor='#CC66FF' ";} elseif($resalta==12){ echo "bgcolor='#99FF66' ";}elseif($resalta==9){ echo "bgcolor='#FF00CC' ";}elseif($resalta==10){ echo "bgcolor='#CCCC00' ";} else{ if($diaft==1){ echo " class='FacetDataText' ";}elseif($diaft==2){echo " class='FacetDataTextDNL' ";}else{ echo " class ='llenarTabla' ";}} echo " align='center' ><b>"; if($resalta==13){ $lectura = consulta_hrpermiso($conex,$codprog,$fecha,$idtp,$anno,$mm,$idj,$ids);echo  "<img src='' border=0 height='5' width='5' style='background-color:#FF0000;' alt='".$lectura."'>";} if($tipohora==1){ echo $codprog."e</b></td>";}else{ echo $codprog."</b></td>";} break;
}
}

}}

echo "<td><input class='FacetButton' type='button' value='VER' onclick='editarturno(".$idj.",".$ids.",".$idga.",".$ida.",".$idh.",2)'/></td></tr>";
/*if($save==1){ echo "disabled";} echo"*/
}

}}
echo "</table>";


?>
</body></html>