<?php

require_once("../class/class.conectar.php");


session_start();



if(!isset($_SESSION['username'])) 

{

  header('Location: ../../principal.html'); 

  exit();

} else { 

    $fechaGuardada = $_SESSION["ultimoAcceso"]; 

    $ahora = date("Y-n-j H:i:s"); 

    $tiempo_transcurrido = (strtotime($ahora)-strtotime($fechaGuardada)); 
	
	//echo strtotime($ahora)."<br>";
	//echo strtotime($fechaGuardada)."<br>";
	//echo $tiempo_transcurrido."<br>";

     if($tiempo_transcurrido >= 180) { 
     //1140
      session_destroy();

     header('Location: ../../principal.html');
    
    }else { 

    $_SESSION["ultimoAcceso"] = $ahora; 

   } 

}



$Objcon = new Conectar();
$conex = $Objcon->con();

date_default_timezone_set("America/Lima"); setlocale(LC_TIME,"es_PE.UTF-8"); 

$ugid = $_GET['ugid'];
$idj = $_GET['idj'];
$ids = $_GET['ids'];

//$ugid='SCPHU1';
$sqlusu="select ua_dni as dni, concat(ua_nom,' ',ua_apepat) as nom from tb_usuasist where ug_id='$ugid'";
$resultusu = mysqli_query($conex,$sqlusu);
while ($row= mysqli_fetch_array($resultusu)){
$dni = $row['dni'];
$nombre = $row['nom'];
}

//conuslta jefatura
$sqlj="select j_desc from tb_jefatura where j_id='$idj'";
$resultj = mysqli_query($conex,$sqlj);
while ($rowj= mysqli_fetch_array($resultj)){
$jefatura = $rowj['j_desc'];
}
//sub jefatura
$sqlsj="select s_desc from tb_servicio where j_id='$idj' and s_id='$ids'";
$resultsj = mysqli_query($conex,$sqlsj);
while ($rowsj= mysqli_fetch_array($resultsj)){
$subjefatura = $rowsj['s_desc'];
}

//listado de descanso medico
$sqldm="select dm_id as id, concat(date_format(dm_fechaini,'%d/%m/%Y'),' - ', date_format(dm_fechafin,'%d/%m/%Y'),' (', dm_numdias,')') ";
$sqldm=$sqldm." as dias, dm_obs from tb_descmed where ug_id='$ugid' order by dm_fechaini desc";
//echo $sqldm;
$resultdm = mysqli_query($conex,$sqldm);
$cadenadm="<select size='4' style='width:25em;' id='dmselect' name='dmselect'>";
while ($rowdm= mysqli_fetch_array($resultdm)){
$codigo=$rowdm['id'];
$dias=$rowdm['dias'];
$cadenadm=$cadenadm."<option value='".$codigo."'>".$dias."</option>";
}
$cadenadm=$cadenadm."</select>";


//listado de horas permiso
$sqlhper="SELECT hrp_id as id, ug_id as cod, concat(date_format(hrp_fecha,'%d/%m/%Y'),'-',date_format(hrp_horaini,'%k:%i %p'),'-',date_format(hrp_horafin,'%k:%i %p'),' (',hrp_numhora,')') as hora "; 
$sqlhper=$sqlhper." FROM tb_horapermiso where  ug_id='$ugid' order by hrp_fecha desc";

//echo $sqldm;
$resulthper = mysqli_query($conex,$sqlhper);
$cadenahrsper="<select size='4' style='width:25em;' id='hrselect' name='hrselect' onClick='listarhrsfechalicper()'>";
//$cadenadm="<select size='4' style='width:22em;' id='dmselect' name='dmselect'>";
while ($rowhper= mysqli_fetch_array($resulthper)){
$codigo=$rowhper['id'];
$horas=$rowhper['hora'];
$cadenahrsper=$cadenahrsper."<option value='".$codigo."' >".$horas."</option>";
$sqldmdetalle ="";
}
$cadenahrsper=$cadenahrsper."</select>";

//listado de licencias
$sqllic="select a.lc_id as id, a.tlc_id as idtl, (select tlc_desc from tb_tplicencia where tlc_id=a.tlc_id) as desclic, concat(date_format(a.lc_fechaini,'%d/%m/%Y'),' - ', date_format(a.lc_fechafin,'%d/%m/%Y'),' (', a.lc_numdias,')') ";
$sqllic=$sqllic." as dias from tb_licencias a where a.ug_id='$ugid' order by a.lc_fechaini desc";
//echo $sqllic;
$resultlic = mysqli_query($conex,$sqllic);
$cadenalic="<select name='licselect' id='licselect' size='4' style='width:25em;' onClick='listardescfechalicper()' >";
while ($rowlic= mysqli_fetch_array($resultlic)){
$codigo=$rowlic['id'];
$dias=$rowlic['dias'];
$desclic=$rowlic['desclic'];
$cadenalic=$cadenalic."<option value='".$codigo."'>".$dias."</option>";
}
$cadenalic=$cadenalic."</select>";

//seleecionado vacaciones programadas
$sqlvacaprog="select v_id as id, concat(date_format(v_fechaini,'%d/%m/%Y'),' - ', date_format(v_fechafin,'%d/%m/%Y'),' (', v_numdias,')') ";
$sqlvacaprog=$sqlvacaprog." as dias, v_periodo as periodo from tb_vacaciones where ug_id='$ugid' and v_estado=0 order by v_fechaini desc";
$resultvacaprog = mysqli_query($conex,$sqlvacaprog);
$cadenavp="<select size='4' style='width:25em;' >";
while ($rowvp= mysqli_fetch_array($resultvacaprog)){
$codigo=$rowvp['id'];
//$dias=$rowvp['dias'];
$dias=$rowvp['dias']." ".$rowvp['periodo'];
$cadenavp=$cadenavp."<option value='".$codigo."'>".$dias."</option>";
}
$cadenavp=$cadenavp."</select>";

//seleecionado vacaciones ejecutadas
$sqlvacaeje="select v_id as id, concat(date_format(v_fechaini,'%d/%m/%Y'),' - ', date_format(v_fechafin,'%d/%m/%Y'),' (', v_numdias,')') ";
$sqlvacaeje=$sqlvacaeje." as dias, v_periodo as periodo from tb_vacaciones where ug_id='$ugid' and v_estado=1 order by v_fechaini desc";
$resultvacaeje = mysqli_query($conex,$sqlvacaeje);
$cadenave="<select size='4' style='width:25em;'>";
while ($rowve= mysqli_fetch_array($resultvacaeje)){
$codigo=$rowve['id'];
//$dias=$rowve['dias'];
$dias=$rowve['dias']." ".$rowve['periodo'];
$cadenave=$cadenave."<option value='".$codigo."'>".$dias."</option>";
}
$cadenave=$cadenave."</select>";

//armando grupo correo
$sqldepa="select j_id as codj, 0 as cods ,j_abrev as nom from tb_jefatura where j_id='$idj'";
$sqlserv="select j_id as codj, s_id as cods, s_abrev as nom from tb_servicio where j_id='$idj'";
$resultdepa = mysqli_query($conex,$sqldepa);
$resultserv = mysqli_query($conex,$sqlserv);

$cadenamail="<table align='center' class='FacetFormTABLE'>";
$cadenamail=$cadenamail."<tr><td class='FacetFieldCaptionTDT' colspan='2' align='center'>MENSAJERIA</td></tr>";
$cadenamail=$cadenamail."<tr><td><b>Seleccione Remitente:</b></td><td><b>Escribe Mensaje:</b></td></tr><tr><td>";
$cadenamail=$cadenamail."<table align='center' class='FacetFormTABLE' height='150'>";
while ($rowj= mysqli_fetch_array($resultdepa)){
$cadenamail=$cadenamail."<tr><td><input type='radio' id='msn' name='msn' value='".$rowj['cods']."'>".$rowj['nom']."</td></tr>";
}
while ($rows= mysqli_fetch_array($resultserv)){
$cadenamail=$cadenamail."<tr><td><input type='radio' id='msn' name='msn' value='".$rows['cods']."'>".$rows['nom']."</td></tr>";
}
$cadenamail=$cadenamail."</table></td><td>";
$cadenamail=$cadenamail."<table align='center' class='FacetFormTABLE' height='150'>";
$cadenamail=$cadenamail."<tr><td align='center'><textarea name='msntexto' id='msntexto' cols='28' rows='6'></textarea></td></tr>";
$cadenamail=$cadenamail."</table></td></tr><tr><td align='center' colspan='2'><input type='button' value='Enviar' class='FacetButton' onClick='enviarmailper()'></td></tr></table>";

$arraymes = array();
$arraymes[] = array('idmes'=>'1','mes'=>'ENERO');
$arraymes[] = array('idmes'=>'2','mes'=>'FEBRERO');
$arraymes[] = array('idmes'=>'3','mes'=>'MARZO');
$arraymes[] = array('idmes'=>'4','mes'=>'ABRIL');
$arraymes[] = array('idmes'=>'5','mes'=>'MAYO');
$arraymes[] = array('idmes'=>'6','mes'=>'JUNIO');
$arraymes[] = array('idmes'=>'7','mes'=>'JULIO');
$arraymes[] = array('idmes'=>'8','mes'=>'AGOSTO');
$arraymes[] = array('idmes'=>'9','mes'=>'SETIEMBRE');
$arraymes[] = array('idmes'=>'10','mes'=>'OCTUBRE');
$arraymes[] = array('idmes'=>'11','mes'=>'NOVIEMBRE');
$arraymes[] = array('idmes'=>'12','mes'=>'DICIEMBRE');

//consulta por datos del esposo(a)
$sqlesposo= "SELECT concat(uf_apepat,' ',uf_apemat,' ',uf_nom) as nombre FROM tb_usufamiliar where ug_id='$ugid' and uf_tipo='1'";
$resultesposo = mysqli_query($conex,$sqlesposo);
while ($rowe= mysqli_fetch_array($resultesposo)){
$nomesposo = $rowe['nombre'];
}

$sqlhijos = "SELECT count(*) nrohijos FROM tb_usufamiliar where ug_id='$ugid' and uf_tipo='2'";
$resulthijos = mysqli_query($conex,$sqlhijos);
while ($rowh= mysqli_fetch_array($resulthijos)){
$nrohijos = $rowh['nrohijos'];
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<link type="text/css" rel="stylesheet" href="src/css/jscal2.css" />
    <link type="text/css" rel="stylesheet" href="src/css/border-radius.css" />
    <!-- <link type="text/css" rel="stylesheet" href="src/css/reduce-spacing.css" /> -->

    <link id="skin-win2k" title="Win 2K" type="text/css" rel="alternate stylesheet" href="src/css/win2k/win2k.css" />
    <link id="skin-steel" title="Steel" type="text/css" rel="alternate stylesheet" href="src/css/steel/steel.css" />
    <link id="skin-gold" title="Gold" type="text/css" rel="alternate stylesheet" href="src/css/gold/gold.css" />
    <link id="skin-matrix" title="Matrix" type="text/css" rel="alternate stylesheet" href="src/css/matrix/matrix.css" />

    <link id="skinhelper-compact" type="text/css" rel="alternate stylesheet" href="src/css/reduce-spacing.css" />

    <script src="src/js/jscal2.js"></script>
	<!--script src="src/js/lang/en.js"></script-->
    <!-- you actually only need to load one of these; we put them all here for demo purposes -->
     <script src="src/js/lang/es.js"></script>
	  <script>setTimeout('document.location.reload()',180000); </script>     
    <link type="text/css" rel="stylesheet" href="demopage.css" />
<script type="text/javascript">
function verprog(){
//alert(ugid);
var ugid = document.getElementById("ugid").value;
var mes = document.getElementById("mmes").value;
var anno= document.getElementById("manno").value;
window.open("../reporte/programacionindividual.php?ugid="+ugid+"&anno="+anno+"&mes="+mes,"","height=500,width=1250,scrollbars=YES");
//window.open("verdetalle.php?ugid=SCPHU4&anno="+anno+"&mes="+mes,"","height=500,width=1250,,scrollbars=yes");
}

function verreprog(){
//alert(ugid);
var ugid = document.getElementById("ugid").value;
var mes = document.getElementById("mmes").value;
var anno= document.getElementById("manno").value;
window.open("../reporte/reprogramacionindividual.php?ugid="+ugid+"&anno="+anno+"&mes="+mes,"","height=500,width=1250,scrollbars=YES");
//window.open("verdetalle.php?ugid=SCPHU4&anno="+anno+"&mes="+mes,"","height=500,width=1250,,scrollbars=yes");
}

function verejehrs(){
//alert(ugid);
var ugid = document.getElementById("ugid").value;
var mes = document.getElementById("mmes").value;
var anno= document.getElementById("manno").value;
window.open("../reporte/ejeprogramacionindividual.php?ugid="+ugid+"&anno="+anno+"&mes="+mes,"","height=500,width=1250,scrollbars=YES");
//window.open("verdetalle.php?ugid=SCPHU4&anno="+anno+"&mes="+mes,"","height=500,width=1250,,scrollbars=yes");
}

function goProduccion(){
//alert(ugid);
var dni = document.getElementById("dni").value;
var ugid = document.getElementById("ugid").value;
var idj = document.getElementById("idj").value;
var ids= document.getElementById("ids").value;
var cadena= "../produccion/regproduccion.php?ugid="+ugid+"&dni="+dni+"&idj="+idj+"&ids="+ids;
document.location = cadena;
}

function editarfamiliar(tipo){
var ugid = document.getElementById("ugid").value;
window.open("editarfamiliar.php?ugid="+ugid+"&tipo="+tipo,"","height=250,width=500,scrollbars=YES");
//window.open("verdetalle.php?ugid=SCPHU4&anno="+anno+"&mes="+mes,"","height=500,width=1250,,scrollbars=yes");
}

function nuevofamiliar(){
var ugid = document.getElementById("ugid").value;
window.open("nuevofamiliar.php?ugid="+ugid,"","height=250,width=500,scrollbars=YES");
//window.open("verdetalle.php?ugid=SCPHU4&anno="+anno+"&mes="+mes,"","height=500,width=1250,,scrollbars=yes");
}

 function listarpersonal(){
 var ugid = document.getElementById("ugid").value;
 window.open("listarfamiliar.php?ugid="+ugid,"","height=250,width=500,scrollbars=YES");
 
 }

function LeerProgDiaria(){
var idj = document.getElementById("idj").value;
   var ids = document.getElementById("ids").value;
   var ugid = document.getElementById("ugid").value;
   var fecha = document.getElementById("fecha").value;
   //document.location= "../reporte/programaciondeldia.php?idj="+idj+"&ids="+ids+"&ugid="+ugid+"&fecha="+fecha;
   var cadena = "../reporte/reprogramaciondeldia.php?idj="+idj+"&ids="+ids+"&ugid="+ugid+"&fecha="+fecha;
   window.open(cadena,"","height=500,width=800");
}
function falta(){
alert("NO DISPONIBLE");
}
</script>
</head>
<body>
<hr color='blue' size='10'>
<hr color='blue'>
<table align='center' class='FacetFormTABLE' width='700' >
<tr><td class='FacetFieldCaptionTD' colspan='2'><font size='10'><?php echo "HI, ".$nombre; ?></font></td><td width='20'></td><td align='center' class='FacetFieldCaptionTDT'><a href='../login.php'>Salir</a></td><td width='20'></td></tr>
<tr><td width='20'></td><td>
	<table align='center' class='FacetFormTABLE' width='400'>
	<tr><td class='FacetFieldCaptionTDT' align='center'><font color='red'><?php echo $jefatura;?></font></td></tr>
	<tr><td class='FacetFieldCaptionTDT' align='center'><?php echo $subjefatura;?></td></tr>
	<br>
	<tr><td align='center'><b><?php setlocale(LC_TIME,"spanish"); 
	echo strftime("Hoy es %A, %d de %B del %Y." ,time()); ?></b></td><tr>
	</table>
<?php
echo "<input type='hidden' id='idj' name='idj' value='".$idj."'>";
echo "<input type='hidden' id='ids' name='ids' value='".$ids."'>";
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";
echo "<input type='hidden' id='dni' name='dni' value='".$dni."'>";
?>
<div id='datoperson'>

<?php 
$conex=$conex;
include("personal.php") ?>
</div>

	<table align='center' class='FacetFormTABLE'>
		<tr><td colspan='3' align='center' class='FacetFieldCaptionTDT'width='420' align='center'>DATOS FAMILIAR</td></tr>
		<tr><td width='124' >Nombre del Esposo(a):</td><td  align='left' ><?php echo $nomesposo; ?></td><td align='center' width='100' ><input class='FacetButton' type='button' value='Editar' onClick='editarfamiliar(1)'></td></tr>
		<tr><td>Numero de Hijos(as):</td><td width='200'  ><?php echo $nrohijos; ?></td><td align='center'><input class='FacetButton' type='button' onClick='listarpersonal()' value='Ver'><input class='FacetButton' type='button' onClick='nuevofamiliar()' value='Registrar Hijos'></td></tr>
		</table>
	<BR><BR>

<table align='center' class='FacetFormTABLE'>
			<tr><td class='FacetFieldCaptionTDT' colspan='2' align='center'>CONSULTA DE LA PROGRAMACION, REPROGRAMACION Y EJECUCION DE HORAS ASISTENCIALES</td></tr>
			<tr><td rowspan='6'>
			<table align='center' class='FacetFormTABLE'>
			<tr><td colspan='2'>Seleccione Fecha:</td></tr>
			<tr><td class='FacetFieldCaptionTD' width='50'>ANO</td><td>
			<?php
				echo "<select name='manno' id='manno'>";
				for ($i=2000;$i<2100;$i++){
				echo "<option value='".$i."'";
				if(date("Y",time())==$i){?> selected
				<?php 
				$anno=$i;
				} echo ">".$i."</option>";
				}
				echo "</select>";
				?>
			</td></tr>
			<br>
			<tr><td class='FacetFieldCaptionTD' width='50'>MES</td><td>
			<?php
				echo "<select name='mmes' id='mmes'>";
				for ($i=0;$i<count($arraymes);$i++){
				echo "<option value='".$arraymes[$i]['idmes']."'";
				if(date("n",time())==$arraymes[$i]['idmes']){?> selected
				<?php 
				$mm=$i+1;
				} echo ">".$arraymes[$i]['mes']."</option>";
				}
				echo "</select>";
				?>
			</td></tr>
			</table>
			</td><td>Seleccione Consulta:</td></tr>
			<tr><td><button type='button' id='pprog' style='width:350px' class='FacetButton' onClick='verprog()'>Programacion Individual Programado</button></td></tr>
			<tr><td><button type='button' id='preprog' style='width:350px' class='FacetButton' onClick='verreprog()'>Programacion Individual ReProgramado</button></td></tr>
			<tr><td><button type='button' id='peje' style='width:350px' class='FacetButton' onClick='verejehrs()'>Programacion Individual Ejecutado</button></td></tr>
			</table>
				<br>
			<table align='center'><tr><td><button type='button' id='pprod' style='width:350px' class='FacetButton' onClick='goProduccion()'>Registro de la Produccion</button</td></tr></table>

</td><td></td><td width='200' align='center'>
	<table align='center' class='FacetFormTABLE'>
	<tr><td class='FacetFieldCaptionTDT' align='center'>VACACIONES DEL PERSONAL ASISTENCIAL</td></tr>
	<tr><td>
		<table align='center' class='FacetFormTABLE' width='200'>
		<tr><td class='FacetFieldCaptionTD'><center>VACAC. PROGRAMADAS</center></td></tr>
		<tr><td><div id='vacaprog'>
				<?php echo $cadenavp; ?>
				</div>
		</td></tr>
		</table>
		<table align='center' class='FacetFormTABLE' width='200'>
		<tr><td class='FacetFieldCaptionTD'><center>VACAC. EJECUTADAS</center></td></tr>
		<tr><td width='160' align='center'>
				<div id='vacaeje'>
				<?php echo $cadenave; ?>
				</div>
			</td></tr>
		</table>
	</td></tr>
	</table>
	<br>
		<table align='center' class='FacetFormTABLE' width='200'>
		<tr><td class='FacetFieldCaptionTD'><center>PERIODOS DESC. MED. INFORMADOS</center></td></tr>
		<tr><td width='160' align='center'>
				<div id='vacaeje'>
				<?php echo $cadenadm; ?>
				</div>
			</td></tr>
		</table>
		<table align='center' class='FacetFormTABLE' width='200'>
		<tr><td class='FacetFieldCaptionTD'><center>HORAS PERMISO ACUMULADO</center></td></tr>
		<tr><td width='160' align='center'>
				<div id='divhoras'>
				<?php echo $cadenahrsper; ?>
				</div>
			</td></tr>
			<tr><td align='center'><div id='divdeschrsp'><input type="text" size="40" id='outhrper' class="SalidaText"></div></td></tr>
		</table>
	<table align='center' class='FacetFormTABLE' width='200'>
		<tr><td class='FacetFieldCaptionTD'><center>LICENCIAS</center></td></tr>
		<tr><td width='160' align='center'>
				<div id='fechalic'>
				<?php echo $cadenalic; ?>
				</div>
			</td></tr>
			<tr><td align='center'><div id='divdesclic'><input type="text" size="40" id='outtplic' class="SalidaText"></div></td></tr>
		</table>
	<br>
		<div id='divmail'>
				<?php echo $cadenamail; ?>
		</div>
		
	</td><td></td></tr>
	
<tr>
<td colspan='3'>
		
</td><td colspan='2'>
		<table align='center' class='FacetFormTABLE' width='100'>
		<tr><td class='FacetFieldCaptionTDT' align='center'>PROGRAMACION DIARIA<td><tr>
		<tr><td>
		<input type='text' id='fecha' name='fecha' size='15' value='<?php if(isset($_GET['ugid'])){ /*echo $fechaing;*/}?>'>
		<button id="f_rangeStart_trigger">...</button>
                <button id="f_clearRangeStart" onclick="clearRangeStart()">clear</button>
                <script type="text/javascript">
				  var LEFT_CAL = Calendar.setup({
                    //cont: "cont",
                    //weekNumbers: true,
                    //selectionType: Calendar.SEL_MULTIPLE,
                    //showTime: 12
                    // titleFormat: "%B %Y"
					})
                  new Calendar({
                          inputField: "fecha",
                          dateFormat: "%d/%m/%Y",
                          trigger: "f_rangeStart_trigger",
                          bottomBar: false,
                          onSelect: function() {
                                  var date = Calendar.intToDate(this.selection.get());
								  LEFT_CAL.setLanguage('es');
                                  LEFT_CAL.args.min = date;
                                  LEFT_CAL.redraw();
                                  this.hide();
                          }
                  });
                  function clearRangeStart() {
                          document.getElementById("fecha").value = "";
                          LEFT_CAL.args.min = null;
                          LEFT_CAL.redraw();
                  };
                </script>
		</td></tr>
		<tr><td align='center'>
		<button type='button' id='progd' style='width:100px' class='FacetButton' onClick='LeerProgDiaria()'>Consultar</button>
		</td></tr>
		</table>
</td></tr>
</table>
<hr color='blue'>
<hr color='blue' size='10'>
</body>
</html>