<?php

require_once("../class/class.descrad.php");
require_once("../class/class.jefaturas.php");
require_once("../class/class.personal.php");
require_once("../funcionesphp/func.calculo.php");


$ugid=$_GET['ugid'];
$idfecha=$_GET['idfecha'];

if(isset($_POST['fechaini']) && isset($_POST['fechafin'])){
$fechainia=$_POST['fechaini'];
$fechafina=$_POST['fechafin'];
$ugid = $_POST['ugid'];
$numid = $_POST['numid'];
$diaini=substr($fechainia, 0, 2);
$diafin=substr($fechafina, 0, 2);
$mesini=substr($fechainia, 3, 2);
$mesfin=substr($fechafina, 3, 2);
$annoini=substr($fechainia, 6, 4);
$annofin=substr($fechafina, 6, 4);
$fechaini =$annoini.'/'.$mesini.'/'.$diaini;
$fechafin =$annofin.'/'.$mesfin.'/'.$diafin;
$numdias=restaFechas($fechainia,$fechafina);
$numdias=$numdias+1;
//$obs=$_POST['obs'];
	if($diaini<=$diafin && $mesini<=$mesfin && $annoini<=$annofin){

		$Objdr = new DescansoRadiacion();
		$res_a = array(); $res_p = array();

		$res_a = $Objdr->consultar_descrad_anterior_id($ugid, $fechaini,$numid);
		$res_p = $Objdr->consultar_descrad_posterior_id($ugid, $fechafin,$numid);

			if((count($res_a)==0) && (count($res_p)==0)){
			$Objdr = new DescansoRadiacion();
			$Objdr->modificar_fechas_descrad($fechaini, $fechafin, $numdias, $numid, $ugid);
			$error=0;
			echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";
			}else{
			$error = 1;
			}
	}else{
	$error=1;
	}}
	
if(isset($_GET['idt'])){
$ugid = $_GET['ugid'];
$idfecha = $_GET['idfecha'];
	$Objdr = new DescansoRadiacion();
	$Objdr->modificar_estado_descrad($idfecha, $ugid);
echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";
}

	//seleccionando al personal
	$Objper = new Personal();
	$datosper = array();
	$datosper = $Objper->buscar_datos_per_campo($ugid);
		for($i=0;count($datosper)>$i;$i++){
			$nombre = $datosper[$i]['nombre'];
			$fechaing = $datosper[$i]['fechaing'];
		}

		//lectura de las fechas
	$Objdr = new DescansoRadiacion();
	$datosf = array();
	$datosf = $Objdr->consultar_fechas_descrad_personal($ugid,$idfecha,0);
		for($i=0;count($datosf)>$i;$i++){
			$fechaini = $datosf[$i]['fechaini'];
			$fechafin = $datosf[$i]['fechafin'];
			$annoprog = $datosf[$i]['periodo'];	
		}
	
//seleccionando al combo jefatura
$Objjef = new Jefaturas();
$listjef = array();
$listjef = $Objjef->listar_jefatura();
$cadenaj="<select id='jefatura' name='jefatura' onChange='actualizaservicio()'>";
	for($i=0;count($listjef)>$i;$i++){
		$cadenaj=$cadenaj."<option value='".$listjef[$i]['cod']."'";
		if ($listjef[$i]['cod']==$idj){
		$cadenaj=$cadenaj." selected ";
		}
		$cadenaj=$cadenaj.">".$listjef[$i]['descripcion']."</option>";
	}
	$cadenaj=$cadenaj."</select>";

	
	//seleccionando al comnbo servicio
	$listserv = array();
	$listserv = $Objjef->listar_jefatura_servicio($idj);
	$cadenaserv="<select id='servicio' name='servicio'>";
	for($i=0;count($listserv)>$i;$i++){
		$cadenaserv=$cadenaserv."<option value='".$listserv[$i]['cod']."'";
		if ($listserv[$i]['cod']==$ids){
		$cadenaserv=$cadenaserv." selected ";
		}
		$cadenaserv=$cadenaserv.">".$listserv[$i]['descripcion']."</option>";
		}
	$cadenaserv=$cadenaserv."</select>";





?>
<html>
<head>
<title>EDITAR DESCANSO DE RADIACION DEL PERSONAL ASISTENCIAL</title>
<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>
    
    <link type="text/css" rel="stylesheet" href="demopage.css" />

<script type="text/javascript"> 

function ventanaClose(){ 
   //alert("hola mundo");
    window.close();
} 

function suspenderdescrad(){ 
    var ugid = document.getElementById('ugid').value;
	var numid = document.getElementById('numid').value;
	window.location ="editardescrad.php?ugid="+ugid+"&idfecha="+numid+"&idt=1";
	//window.opener.location.reload(); window.close();
} 
</script> 
</head>
<body>
<table align='center'>
<tr><td>
<div id='transfpersonal'>
<form action='editardescrad.php' method='POST'>
<?php
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";
echo "<input type='hidden' id='numid' name='numid' value='".$idfecha."'>";
?>
<fieldset>
	<legend align='left'><font color='blue' size='15'>Modifique la Fecha de las Vacaciones </font></legend>
	<br>
		<table align='center' class='FacetFormTABLE' width='450'>
		<tr><td class='FacetFieldCaptionTDT' colspan='4'><center>EDITAR DESCANSO DE RADIACION DEL PERSONAL ASISTENCIAL</center></td></tr>
		<tr><td colspan='4'><center><?php if($error=='1'){ echo "REVISE LOS DATOS, PERSONAL NO REGISTRADO";}elseif($error=='0'){ echo "PERSONAL REGISTRADO";}?></center></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD' style='width:300px'>PERSONAL </td><td colspan='3'><?php echo $nombre; ?></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD' style='width:300px'>FECHA INGRESO </td><td colspan='3'><?php echo $fechaing; ?></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD' style='width:300px'>PERIODO </td><td colspan='3'><?php echo $annoprog; ?></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD'>FECHA INICIAL</td>
		<td>
		<input type='text' id='fechaini' name='fechaini' size='15' value='<?php if(isset($_GET['ugid'])){ echo $fechaini;}?>'>
		<button id="f_rangeStart_trigger1">...</button>
                <button id="f_clearRangeStart1" onclick="clearRangeStart1()">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: "fechaini",
                          dateFormat: "%d/%m/%Y",
                          trigger: "f_rangeStart_trigger1",
                          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 clearRangeStart1() {
                          document.getElementById("fechaini").value = "";
                          LEFT_CAL.args.min = null;
                          LEFT_CAL.redraw();
                  };
                </script>
		</td>
		<td align='right' class='FacetFieldCaptionTD'>FECHA FINAL</td>
		<td>
		<input type='text' id='fechafin' name='fechafin' size='15' value='<?php if(isset($_GET['ugid'])){ echo $fechafin;}?>'>
		<button id="f_rangeStart_trigger2">...</button>
                <button id="f_clearRangeStart2" onclick="clearRangeStart2()">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: "fechafin",
                          dateFormat: "%d/%m/%Y",
                          trigger: "f_rangeStart_trigger2",
                          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 clearRangeStart2() {
                          document.getElementById("fechafin").value = "";
                          LEFT_CAL.args.min = null;
                          LEFT_CAL.redraw();
                  };
                </script>
		</td>
		</tr>
		
		<tr><td align='center' colspan='4'><input type='submit' id='pprog' style='width:150px' class='FacetButton'  value='Modificar'>
		<button type='button' id='pprog' style='width:150px' class='FacetButton' onClick='suspenderdescrad();' >Suspender</button>
		<button type='button' id='pprog' style='width:150px' class='FacetButton' onClick='ventanaClose();' >Cancelar</button>
		</td></tr></table>
	  <br>
	</fieldset>
</div>
</td><tr>
</table>
</body>
</html>