<?php
$LIMPIAR=0;
$SYS_FOC="TxtNom";
//------------------------------------------------------------------------------------
$StrNom=V($_POST['TxtNom']);
$StrNomApe=V($_POST['TxtNomApe']);
$StrDir=V($_POST['TxtDir']);
$StrDis=V($_POST['CboDis']);
$StrFn=V($_POST['TxtFn']);
$StrDni=V($_POST['TxtDni']);
$StrTel=V($_POST['TxtTel']);	
$StrCel=V($_POST['TxtCel']);	
$StrFi=V($_POST['TxtFi']);	
$StrEma=V($_POST['TxtEma']);	
$StrCar=V($_POST['CboCar']);
//++++++++++++++++++++++++++++++++++++++++++++++
//------------------------------------------------------------------------------------
PID($StrId,V($_GET['Id']),$StrCmd,$LStrPag,V($_GET['Pag']));
//------------------------------------------------------------------------------------	
if(strlen($StrId)>0 && $StrCmd=="AR"){
	$Id=$StrId;
	$StrNom=gs("NOMBRE","vpersonal","ID=$Id");	
	$StrNomApe=gs("per_nom_ape","personal","id_personal=$Id");		
	$StrDir=gs("DIRECCION","vpersonal","ID=$Id");		
	$StrDis=gs("DISTRITO","vpersonal","ID=$Id");		
	$StrFn=gs("DATE_FORMAT(FEC_NAC,'%d-%m-%y')","vpersonal","ID=$Id");
	if($StrFn=="01-01-00" || $StrFn=="00-00-00")$StrFn="";
	$StrDni=gs("DNI","vpersonal","ID=$Id");		
	$StrTel=gs("TEL","vpersonal","ID=$Id");		
	$StrCel=gs("CEL","vpersonal","ID=$Id");		
	$StrFi=gs("DATE_FORMAT(FEC_ING,'%d-%m-%y')","vpersonal","ID=$Id");		
	if($StrFi=="01-01-00" || $StrFi=="00-00-00")$StrFi="";
	$StrEma=gs("EMAIL","vpersonal","ID=$Id");		
	$StrCar=gs("CARGO","vpersonal","ID=$Id");	
	//	
	$SYS_FOC="TxtNom";		
}
//------------------------------------------------------------------------------------
if($StrCmd=="G" || $StrCmd=="M"){		
	$StrDis_=gn("id_distrito","distritos","dis_nombre='$StrDis'");
	$StrCar_=gn("id_cargo","cargos","car_nombre='$StrCar'");
	$StrFn_=ToDate($StrFn);
	$StrFi_=ToDate($StrFi);
}
//------------------------------------------------------------------------------------
if($StrCmd=="G"){
	if(GetC("vpersonal","NOMBRE='$StrNom'")>0){
		$SYS_MSG="Nombre y apellidos ya esta registrado";
		$SYS_FOC="TxtNom";						
		$OK=0;
	}		
	if($OK==1){
		if(strlen($StrDni)>0){
			if(GetC("vpersonal","DNI='$StrDni'")>0){
				$SYS_MSG="Numero de dni ya registrado";
				$SYS_FOC="TxtDni";
				$OK=0;					
			}
		}
	}
	if($OK==1){			
		$Id=GenId("id_personal","personal");
		$s="INSERT INTO personal VALUES ($Id,'$StrNom'
			,'$StrDir',$StrDis_,'$StrFn_','$StrDni','$StrTel'
			,'$StrCel','$StrFi_','$StrEma',$StrCar_,'$StrNomApe')";
		ejt($s);
		//BIT
		$_BIT_MOD_ID=$Id;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="sis_personal.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PERSONAL","GUARDAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT	
		$SYS_MSG="Datos Guardados";
		$SYS_FOC="$SYS_FOC";
		$OK=0;
		//
		$LIMPIAR=1;
	}
}
//------------------------------------------------------------------------------------
if($StrCmd=="M"){
	if(GetC("vpersonal","NOMBRE='$StrNom' AND ID<>$StrId")>0){
		$SYS_MSG="Nombre y apellidos ya esta registrado";
		$SYS_FOC="TxtNom";						
		$OK=0;
	}
	if($OK==1){
		if(strlen($StrDni)>0){
			if(GetC("vpersonal","DNI='$StrDni' AND ID<>$StrId")>0){
				$SYS_MSG="Numero de dni ya registrado";
				$SYS_FOC="TxtDni";
				$OK=0;					
			}
		}
	}	
	if($OK==1){
		$s="UPDATE personal SET per_nombre='$StrNom'
			,per_direccion='$StrDir',per_id_distrito=$StrDis_,per_fecnac='$StrFn_',
			per_dni='$StrDni',per_tel='$StrTel'
			,per_cel='$StrCel',per_fecing='$StrFi_',per_email='$StrEma',
			per_id_cargo=$StrCar_ ,per_nom_ape='$StrNomApe' 
			WHERE id_personal=$StrId";
		ejt($s);
		//BIT
		$_BIT_MOD_ID=$StrId;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="sis_personal.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PERSONAL","MODIFICAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT	
		$SYS_MSG="Datos Actualizados";
		$SYS_FOC="$SYS_FOC";
		$OK=0;
		//
		$LIMPIAR=1;
	}
}
//------------------------------------------------------------------------------------
if($StrCmd=="E"){
	if(GetC("","","")==0){
		
	}
	if($OK==100){
		$s="DELETE FROM personal WHERE id_personal=$StrId";	
		ejt($s);
		//BIT
		$_BIT_MOD_ID=$StrId;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="sis_personal.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PERSONAL","ELIMINAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT	
		$SYS_MSG="Registro Eliminado";
		$SYS_FOC="$SYS_FOC";
		$OK=0;
		//
		$LIMPIAR=1;
	}else{
		$SYS_MSG="Funcion no habilitada";
		$SYS_FOC=$SYS_FOC;
	}
}
//------------------------------------------------------------------------------------
if($StrCmd=="L"){$LIMPIAR=1;}
if($LIMPIAR==1){
$StrId="";
$StrNom="";
$StrDir="";
$StrDis="";
$StrFn="";
$StrDni="";
$StrTel="";
$StrCel="";
$StrFi="";
$StrEma="";
$StrCar="";
$StrNomApe="";
}
//------------------------------------------------------------------------------------
?>