<?php

include("../bd/sql_variables.php");

require_once("../class/class.conectar.php");
require_once("../class/class.usudep.php");
require_once("../class/class.personal.php");
require_once("../class/class.suspperson.php");

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

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

if(isset($_GET['tmov'])){
$fecha=$_GET['fecha'];

$ugid=$_GET['ugid'];
$susdesc=$_GET['descsusp'];

$Objp=new UsuarioDependencia();
$res_ut=array();
$res_ut=$Objp->listar_det_trab_per($conex,$ugid);          
$udid=$res_ut[0]['id'];

$fecha = $_GET['fecha'];
	$uno=substr($fecha, 0, 2);
	$dos=substr($fecha, 3, 2);
	$tres=substr($fecha, 6, 4);
	$fecha = ($tres."-".$dos."-".$uno);

$Objp->modificar_fecha($conex,$ugid,$udid,$fecha);
$Objp->finalizar_trab_dep_per($conex,$ugid,$udid,0);

$Objsp=new SuspenderPersonal($conex);
$Objsp->suspende_personal($conex,$ugid,$udid,$fecha,$susdesc);
echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";

}

//seleccionando al personal
$Objp = new Personal();
$res_per=array();
$res_per=$Objp->buscar_nombre($conex,$ugid);
$nombre = $res_per[0]['nombre'];
?>
<html>
<head>
<title>SUSPENCION DEL PERSONAL ASISTENCIAL</title>
<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 language="JavaScript" type="text/javascript" src="ajax.js"></script>
<script type="text/javascript"> 

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

function validaFechaDDMMAAAA(fecha){    
var dtCh= "/";    
var minYear=1900;
var maxYear=2100;
        function isInteger(s){
        var i;     
		for (i = 0; i < s.length; i++){ 
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
        }
        return true;
		}
		function stripCharsInBag(s, bag){
        var i;
        var returnString = ""; 
		for (i = 0; i < s.length; i++){ 
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;        }
        return returnString;    }
		function daysInFebruary (year){
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );    }
		function DaysArray(n) {
        for (var i = 1; i <= n; i++) { 
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}        
		} 
		return this
		}    
		function isDate(dtStr){
        var daysInMonth = DaysArray(12) 
		var pos1=dtStr.indexOf(dtCh) 
		var pos2=dtStr.indexOf(dtCh,pos1+1) 
		var strDay=dtStr.substring(0,pos1)
        var strMonth=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)        
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)        
		for (var i = 1; i <= 3; i++) {            
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }        
		month=parseInt(strMonth)        
		day=parseInt(strDay)        
		year=parseInt(strYr)        
		if (pos1==-1 || pos2==-1){            
		return false        }        
		if (strMonth.length<1 || month<1 || month>12){            
		return false        }       
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{            return false        }        
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){ 
		return false        }        
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{            return false        }        
		return true    }    
		if(isDate(fecha))
		{        return true;    }
		else{        return false;    }
}

function SuspenderPer(){

	var fecha = document.getElementById("fecha").value;
	var ugid = document.getElementById("ugid").value;
	var descsusp = document.getElementById("descsusp").value;
	
	if(fecha == ''){
		alert("Fecha no Ingresado");
		return false;
	}
	if(validaFechaDDMMAAAA(fecha) == false){
		alert("Fecha No Esta Escrita Correctamente");
		return false;
	}
	
	if(descsusp == ''){
		alert("Detallar la Suspension");
		return false;
	}
	
	document.location= "suspenderpersonal.php?fecha="+fecha+"&ugid="+ugid+"&descsusp="+descsusp+"&tmov=1";
}
</script> 
</head>
<body>
<table align='center'>
<tr><td>
<div id='transfpersonal'>
<?php
//echo "<input type='hidden' id='depa' name='depa' value='".$idj."'>";
//echo "<input type='hidden' id='serv' name='serv' value='".$ids."'>";
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";
?>
<fieldset>
	<legend align='left'><font color='blue' size='15'>Registre Datos de Suspencion </font></legend>
	<br>
		<table align='center' class='FacetFormTABLE' width='450'>
		<tr><td class='FacetFieldCaptionTDT' colspan='3'><center>SUSPENCION DEL PERSONAL ASISTENCIAL</center></td></tr>
		<tr><td colspan='2'><center><?php if(isset($error)){ if($error=='0'){ echo "REVISE LOS DATOS, PERSONAL NO REGISTRADO";}elseif($error=='1'){ echo "PERSONAL REGISTRADO";}}?></center></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD' style='width:300px'>PERSONAL </td><td><?php echo $nombre; ?></td></tr>
		<tr><td align='right' class='FacetFieldCaptionTD'>FECHA DE SUSPENCION</td><td>
		<input type='text' id='fecha' name='fecha' size='15'>
		<button id="f_rangeStart_trigger"><img src="../img/b_calendar.png" ></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='right' class='FacetFieldCaptionTD'>MOTIVO DE SUSPENCION</td><td><input type='text' id='descsusp' name='descsusp' size='60'></td></tr>
		<tr><td align='center' colspan='2'><input type='button' id='pprog' style='width:150px' class='FacetButton'  value='Suspender' onClick='SuspenderPer()'>
		<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>