<?php 
session_start();

//RESTRICCIÓN DE ACCESO A TRABAJADOR (ACCESO INDIVIDUAL) 
if (isset($_SESSION['tipousuario']))
		{if ($_SESSION['tipousuario']=='1')
		header ('location:menu_personal.php');
		}
		
if  (trim($_SESSION['nombre_validar'])=='') header ('location:index.php');
require('fphp.php');

if ($_POST['imprime']==1 ) {
///////////////////////////////////////////////// imprimir registros ////////////////////////////////////////////////////////////////
	$enlace=cargar_conexion();
	$consulta=mysql_query("select * from empresa where id='".$_SESSION['id_validar']."'");
	if (mysql_num_rows($consulta)!=0){
			$row=mysql_fetch_array($consulta);
			$_POST['pie']=$row['pie'];
			$_POST['encabeza']=$row['encabeza'];
			$_POST['empresa']=(substr($_POST['nomina'],6,100)==""?$_SESSION['empresa_validar']:substr($_POST['nomina'],6,100)) ;
	}   
	require('fpdf.php');

	class PDF extends FPDF {
	function Header()
	{
	    $this->Image($_SESSION['logo_validar'],10,10,20,20);
	    $this->SetFont('arial','',12);
		$this->Ln(2);
	    $this->Cell(0,0,$_POST['empresa'],0,1,'R'); $this->Ln(5);
		$this->Cell(0,0,$_POST['encabeza'],0,1,'R');$this->Ln(5);
		$this->SetFont('arial','',10);
	    $this->Cell(140);$this->Cell(0,0,'Fecha: '.hoy(),0,1,'L'); $this->Ln(5);
	    $this->Cell(140);$this->Cell(0,0,'Usuario: '.$usuario,0,1,'L'); $this->Ln(5);

		$this->Ln(10);
		$this->SetFont('arial','B',8);
		$this->Cell(0,0,'Reporte General de Empleados',0,1,'C');$this->Ln(5);
	    $header=array('Item','Cédula','Nombres','Apellidos','Cargo','Status','F_ingreso');
	    $this->SetFillColor(255,0,0);
	    $this->SetTextColor(255);
	    $this->SetDrawColor(128,0,0);
	    $this->SetLineWidth(.3);
	    $this->SetFont('','');
	    //Cabecera
	    $w=array(15,20,30,30,50,20,20);
		for($i=0;$i<count($header);$i++)
	        $this->Cell($w[$i],5,$header[$i],1,0,'C',1);
	    $this->Ln();
	    //Restauración de colores y fuentes
	    $this->SetFillColor(224,235,255);
	    $this->SetTextColor(0);
	    $this->SetFont('');
	}


//Pie de página ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function Footer()
	{
	$this->SetY(-15);
	$this->Cell(0,0,'',1,1,'C');
	$this->SetFont('Times','I',8);
	$this->ln(2);
	$this->Cell(20);$this->Cell(0,0,$_POST['pie'],0,1,'C');
	$this->Cell(0,10,'Página '.$this->PageNo().'/{nb}',0,0,'C');
	}
}
//Cuerpo ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$pdf=new PDF();
	$pdf->AddPage();
	$pdf->AliasNbPages();
	$pdf->SetFont('Arial','',6);
	$pdf->SetFillColor(224,235,255);
	$pdf->SetTextColor(0);
	$consulta=mysql_query("SELECT * from personal where id='".$_SESSION['id_validar']."'  order by codigo");
	$linea=0;
	$color=0;
	while($row=mysql_fetch_array($consulta)) {
		$linea++;
		$tcargo=$row['cargo'];
		$pdf->cell(15,5,$linea,0,0,'C',$color);
		$pdf->cell(20,5,$row['codigo'],0,0,'C',$color);
		$pdf->cell(30,5,$row['nombres'],0,0,'',$color);
		$pdf->cell(28,5,$row['apellidos'],0,0,'',$color);
		$cons1=mysql_query("select tablas.detalle as car from tablas where codigo='".$row['cargo']."' and tabla='CARGO' and id='".$_SESSION['id_validar']."'" ) ;
		while($row1=mysql_fetch_array($cons1))
		$pdf->cell(60,5,$row1['car'],0,0,'L',$color);
		$pdf->cell(15,5,$row['status'],0,0,'L',$color);
		$pdf->cell(20,5,$row['fechai'],0,1,'C',$color);
		$color=!$color;
	}
	$pdf->Output();
}
else {
$accion=$_REQUEST["accion"];
$codigo=$_REQUEST["codigo"];
$cedula=$_REQUEST["cedula"];
$enlace=cargar_conexion();
$consulta=mysql_query("select * from periodo where id='".$_SESSION['id_validar']."' order by nomina,periodo desc limit 1");
if (mysql_num_rows($consulta)!=0){
	$row=mysql_fetch_array($consulta);
	$_SESSION['per_validar']=mostrar_fecha($row['desde']).' al '.mostrar_fecha($row['hasta'])." (Nom:".$row['nomina'].")";
} else $_SESSION['per_validar']=''; 

///////////////////////////////////////////////// inicio del programa ////////////////////////////////////////////////////////////////
menu();
$entra=0;

///////////////////////////////////////////////// bajar foto ////////////////////////////////////////////////////////////////
 if ($_POST['bandera']==33) {
		$tamano = $_FILES["archivo"]['size'];
		$tipo = $_FILES["archivo"]['type'];
		$archivo = $_FILES["archivo"]['name'];
		$prefijo = substr(md5(uniqid(rand())),0,6);
		if ($archivo != "") {
			$destino =  "fotos/".$_POST['cedulafoto'].".jpg";
			if (copy($_FILES['archivo']['tmp_name'],$destino)) {
				$status = "Archivo subido: <b>".$archivo."</b>";
			} else {
				$status = "Error al subir el archivo";
			}
		} else {
			$status = "Error al subir archivo";
		}
}

///////////////////////////////////////////////// cargar fotos ////////////////////////////////////////////////////////////////
if ($accion==33) {
		echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='images/b_regresa.png' alt='Regresar'><a href='".$_SERVER['PHP_SELF']."'>Regresar</a>";
		echo "<hr><h2>Cargar Foto de la C&eacute;dula Nro: ".$cedula."</h2>";
		echo "<form name = 'entrada4' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data'>";
		echo "<input type = 'hidden' name = 'bandera' value = '33'>";
		echo "<input type = 'hidden' name = 'cedulafoto' value = '".$cedula."'>";
		echo "<table cellpadding=2 cellspacing=0 >";
		echo "<tr>";
			echo "<td align=right> Archivo de Foto? (Imagen formato: JPG):</td>";
			echo "<td> <input name='archivo' type='file' size='35' /></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td colspan=2><input name='contrato' type = 'submit' value = 'Bajar Foto a SAIREH? / Regresar'></td>";
		echo "</tr>";
		echo "</table>";
		echo"</form>"; 

} else {

///////////////////////////////////////////////// ACTUALIZAR TRABAJADOR ////////////////////////////////////////////////////////////////
echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='img2/icono_07.png' alt='Elimina'>&nbsp;Eliminar	
&nbsp;&nbsp;<img border = 0 src='img2/icono_01.png' alt='Modificar'>&nbsp;Modificar
&nbsp;&nbsp;<img border = 0 src='img2/sueldos.png' alt='Sueldo'>&nbsp;Sueldo";
echo "&nbsp;&nbsp;<a href='".$_SERVER['PHP_SELF']."?accion=11'><img border = 0 src='img2/icono_04.png' alt='Nuevo Trabajador'>&nbsp;Nuevo Trabajador</a>";
echo "&nbsp;&nbsp;<a href='profesional_trabajador_estructura.php'><img border = 0 src='img2/icono_03.png' alt='Estructuras'>&nbsp;Estructuras</a>";
	
echo "<hr><h2>Actualizaci&oacute;n de Trabajadores</h2>";

///////////////////////////////////////////////// graba registros  ////////////////////////////////////////////////////////////////
if ($_POST['graba']==1 ) {

	$query = "select * from personal where id='".$_SESSION['id_validar']."' ";
	$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");
	$resultadox = mysql_num_rows($consulta);
		
	$noentrar=0;	
	if ($_SESSION['modo_validar']==2) {
		if ($resultadox>0) $noentrar=1;	
	}	
	
	if ($noentrar==0) {
		$query = "select * from personal where codigo = '".$_POST['cedula']."' and id='".$_SESSION['id_validar']."' ";
		$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");
		$resultado = mysql_num_rows($consulta);
		if ($resultado == 0) {
			$fing = crear_fecha($_POST['fecing']);
			$fegr = crear_fecha($_POST['fecegr']);
		
			$query = "insert into personal  ( id, apellidos1, nombres1,codigo,nombres,apellidos,departamento,cargo, empresa,";
			$query.= "fechai, fechae,smes,status) values ( '".$_SESSION['id_validar']."', ";
			$query.= "ucase(trim('".$_POST['apellidos1']."')), ";
			$query.= "ucase(trim('".$_POST['nombres1']."')), ";
			$query.= "ucase(trim('".$_POST['cedula']."')), ";
			$query.= "ucase(trim('".$_POST['nombres']."')), ";
			$query.= "ucase(trim('".$_POST['apellidos']."')), ";
			$query.= "ucase(trim('".$_POST['departamento']."')), ";
			$query.= "ucase(trim('".$_POST['cargo']."')), ";
			$query.= "ucase(trim('".$_POST['empresa']."')), ";
			$query.= "ucase(trim('".$fing."')), ";
			$query.= "ucase(trim('".$fegr."')), ";
			$query.= "'".$_POST['smes']."', "; 
			$query.= "'A')"; 
			
			$consulta = mysql_query ($query) or die ("no se pudo ingresar los datos...".mysql_error().$query);

			$consulta="select * from personal_sueldo where codigo='".$_POST['cedula']."' and fec='".$fing."' and id='".$_SESSION['id_validar']."' ";
			$resultado = mysql_query($consulta) or die($consulta . mysql_error());
			if (mysql_num_rows($resultado)==0) {
				$query = "insert into personal_sueldo  ( id, codigo, fec, sueldo) values('".$_SESSION['id_validar']."', ucase(trim('".$_POST['cedula']."')), '".$fing."', '".$_POST['smes']."') ";
				$consulta = mysql_query ($query) or die ("no se pudo ingresar los datos...".mysql_error().$query);
			} else {
				$query = "update personal_sueldo  set sueldo='".$_POST['smes']."' where codigo='".$_POST['cedula']."' and fec='".$fing."' and id='".$_SESSION['id_validar']."' ";
				$consulta = mysql_query ($query) or die ("no se pudo ingresar los datos...".mysql_error().$query);
			}
		}	
	}	
}

///////////////////////////////////////////////// actualizar registros  ////////////////////////////////////////////////////////////////
if ($_POST['modifica']==1 ) {
	$consulta3=mysql_query("select * from periodo where nomina='".substr($_POST['nomina'],0,3)."' and id='".$_SESSION['id_validar']."' order by periodo DESC limit 1");
	if (mysql_num_rows($consulta3)!=0){
			$row3=mysql_fetch_array($consulta3);
			if ($row3['pre']==1) $nograbar=1;
			else $nograbar=0;
	} 
	if ($nograbar==1)
		echo "<center><font color=red>".($nograbar==1?"No se puede procesar al trabajador porque la Nómina esta en Pre-Cierre":"")."</font></center>";
	else {	

		$fing = crear_fecha($_POST['fecing']);
		$fegr = crear_fecha($_POST['fecegr']);
		
		$query = "update personal set ";		
		$query.= "nombres = ucase(trim('".$_POST['nombres']."')), ";
		$query.= "apellidos = ucase(trim('".$_POST['apellidos']."')), ";
		$query.= "nombres1 = ucase(trim('".$_POST['nombres1']."')), ";
		$query.= "apellidos1 = ucase(trim('".$_POST['apellidos1']."')), ";
		$query.= "departamento = ucase(trim('".$_POST['departamento']."')), ";
		$query.= "cargo = ucase(trim('".$_POST['cargo']."')), ";
		$query.= "empresa = ucase(trim('".$_POST['empresa']."')), ";
		$query.= "fechai = ucase(trim('".$fing."')), ";
		$query.= "fechae = ucase(trim('".$fegr."')), ";
		$query.= "smes = '".$_POST['smes']."', ";
		$query.= "status = 'A' ";
		$query.= "where codigo = '".$_POST['cedula']."' and id='".$_SESSION['id_validar']."' ";
		mysql_query ($query) or die (mysql_error().$query);
	}	
}

///////////////////////////////////////////////// eliminar registros ////////////////////////////////////////////////////////////////
if ($accion==2) { 
	if ($_SESSION['modo_validar']!=2) {
		$consulta="select cedula from historico where cedula='".$cedula."' and id='".$_SESSION['id_validar']."' ";
		$resultado = mysql_query($consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysql_error());
		if (mysql_num_rows($resultado)!=0) $mensaje='Trabajador NO puede eliminarse por tener informaci&oacute;n en Historicos...';
		else {	
			$consulta="delete from personal where codigo='".$cedula."' and id='".$_SESSION['id_validar']."' ";
			$resultado = mysql_query($consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysql_error());
		}	
	}	
}
	
///////////////////////////////////////////////// mostrar entrada de datos  ////////////////////////////////////////////////////////////////
if ((!$_POST || $accion==2 || $_POST['graba']==1 || $_POST['modifica']==1 || $_POST['bandera']==33) && $accion!=3 && $accion!=11) {
	echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data'>";
	echo "<input type = 'hidden' name = 'busca' value = '1'>";
	echo "<table cellpadding=2 cellspacing=0 width='500' align='center'>";
	echo "<tr>";
		echo "<td align=right> C&eacute;dula/Nombre/Apellido:</td>";
		echo "<td> <input name='cedula' size = '30' maxlength = '8'></td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td align=right> Ordenado por:</td>";
		echo "<td>";
		echo "	<input type = 'radio' name = 'orden' value = 'ced' checked> cedula";
		echo "	<input type = 'radio' name = 'orden' value = 'nom'> nombre";
		echo "	<input type = 'radio' name = 'orden' value = 'ape'> apellido";
		echo "	<input type = 'radio' name = 'orden' value = 'sso'> Ficha";
	echo "</tr>";
	echo "<tr>";
		echo "<td> </td>";
		echo "<td colspan=3><input type='image' src='img2/boton_buscar.jpg' value='Entrar' ></td>";
	echo "</tr>";
	echo "</table></form>";
	echo "<script language='javascript' type='text/javascript'>document.entrada.cedula.focus();</script>";
	if ($mensaje!='') echo "<br><br><center><font style='color:black; font-size:1em;' face='Verdana' ><b>".$mensaje."</b></font></center>";	
	
}

///////////////////////////////////////////////// agregar registros ////////////////////////////////////////////////////////////////
if ($_POST['agrega']==1 || $accion==11 ) {
	if ($_POST['cedula']=='' ) {
			echo "<form name = 'entrada3' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data' onsubmit='return validar_cedula(this)'>";
			echo "<input type = 'hidden' name = 'agrega' value = '1'>";		
			echo "<table align ='center'>";
			echo "<tr>";
				echo "<td align = 'right'> C&eacute;dula a ingresar: </td>";
				echo "<td align = 'left'> <input type = 'text' name = 'cedula' size = '30' maxlength = '8' onkeyup='verificar_cedula(this.form)'> * </td>";
				echo "<td ><input name='procesar' type = 'submit' value = 'Procesar Registro Nuevo' disabled></td></form>";
				echo "<script language='javascript' type='text/javascript'>document.entrada3.cedula.focus();</script>";	
				echo "<form name = 'entrada2' method = 'POST' action = '".$_SERVER['PHP_SELF']."'>";
				echo "<td ><input type = 'submit' value = 'Regresar al Inicio'></td>";
			echo "</tr>";
			echo "</table></form>";		
	} else {
		$consulta="select * from personal where codigo='".$_POST['cedula']."' and id='".$_SESSION['id_validar']."' ";
		$resultado = mysql_query($consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysql_error());
		$num_rows = mysql_num_rows($resultado);
		if ($num_rows!=0) {
				echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data' onsubmit='return validar_cedula_nombre_apellido(this)'>";
				echo "<input type = 'hidden' name = 'agrega' value = '1'>";
				echo "<table width = '100%' align ='center'>";
				echo "<tr>";
				echo "<td width = '20%' align = 'right'> C&eacute;dula a ingresar: </td>";
				echo "<td width = '36%' align = 'left'> <input type = 'text' name = 'cedula' size = '30' maxlength = '8' > * </td>";
				echo "</tr>";
				echo "</table>";
				echo "<table width = '20%' align ='center'>";
				echo "<tr><td><input type = 'submit' value = 'Procesar'></td></form>";
				echo "<form action = '".$_SERVER['PHP_SELF']."'>";
				echo "<td><input type = 'submit' value = 'Regresar'></td></tr></table></form>";
				echo "<center>registro existente.....</center>";
				echo "	<script language='javascript' type='text/javascript'> document.entrada.cedula.focus(); </script>";
		} else {
				include ("calendario/calendario.php");
				echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data' onsubmit='return validar_cedula_nombre_apellido(this)'>";
				echo "<input type = 'hidden' name = 'graba' value = '1'>";
				
				echo "<table rules=none border=0 cellpadding=2 cellspacing=0 align='center' style='border-width: 1px; border-color: 75263C;border-style: solid;'>";

				//=================================================================================================///
				echo "<tr bgcolor='#43bced' height='25'>";
				echo "<td colspan=4 align = center><font color='white'> Datos Personales del Trabajador</font></td>";
				echo "</tr>";
				
				echo "<tr bgcolor='#F5F6CE'>";
					echo "<td  align = 'right'> C&eacute;dula: </td>";
					echo "<td  align = 'left'> <input type = 'text' name = 'cedula' size = '30' maxlength = '8' readonly value = '".$_POST['cedula']."' readonly> * </td>";
					echo "<td align = 'right' > Nacionalidad: </td>";
					echo "<td align = 'left'>";
					echo "<select name = 'nacionalidad'>";
						echo "<option value='V' ".($row['nacionalidad'] != 'E'?'selected':'')."> Venezolano(a)"; 
						echo "<option value='E' ".($row['nacionalidad'] == 'E'?'selected':'')."> Extranjero(a)"; 
					echo  "</select></td>";				
				echo "</tr>";
				echo "<tr bgcolor='#F5F6CE'>";
					echo "<td  align = 'right'> Primer Nombre: </td>";
					echo "<td  align = 'left'> <input type = 'text' name = 'nombres' size = '30' maxlength = '50' value = '".$row['nombres']."'> * </td>";
					echo "<td  align = 'right'> Segundo Nombre: </td>";
					echo "<td  align = 'left'> <input type = 'text' name = 'nombres1' size = '30' maxlength = '50' value = '".$row['nombres1']."'>  </td>";
				echo "</tr>";
				echo "<tr bgcolor='#F5F6CE'>";
					echo "<td align = 'right'> Primer Apellido: </td>";
					echo "<td align = 'left'> <input type = 'text' name = 'apellidos' size = '30' maxlength = '50' value = '".$row['apellidos']."'> * </td>";
					echo "<td align = 'right'> Segundo Apellido: </td>";
					echo "<td align = 'left'> <input type = 'text' name = 'apellidos1' size = '30' maxlength = '50' value = '".$row['apellidos1']."'>  </td>";
				echo "</tr>";
												
				echo "<tr bgcolor='#F5F6CE'>";
					cargar_select("empresa","Empresa", $row['empresa']); 	
					cargar_select("departamento","Departamento", $row['departamento']); echo "</tr>";
				echo "<tr bgcolor='#F5F6CE'>";
					cargar_select("cargo","Cargo", $row['cargo']); 
					$query = "select * from turno where id='".$_SESSION['id_validar']."' order by detalle";
					$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");	
					$resultado = mysql_num_rows($consulta);
					echo "<td align = 'right' > <font color=blue>Salario Mes: </td></font>";
					echo "<td align = 'left'> <input type = 'text' name = 'smes' size = '30' maxlength = '30' value = '".$row['smes']."'></td>";
				echo "<tr bgcolor='#F5F6CE'>";
					echo "<td align = 'right' > Fecha/Ingreso (ddmmaaaa): </td>";
					echo "<td align = 'left'>";
					escribe_formulario_fecha_vacio("fecing","entrada");
					echo "</td>";
					echo "<td align = 'right' > Fecha/Egreso: </td>";
					echo "<td align = 'left'>";
					escribe_formulario_fecha_vacio("fecegr","entrada");
					echo "</td>";
				echo "</tr>";

				echo "</table>";
				echo "<br><br>";	
				echo "<table width = '20%' align ='center'>";
				echo "<tr><td><input type = 'submit' value = 'Grabar Nuevo Registro?' ".(substr($_SESSION['acceso_validar'],16,1)=='1'?'':'disabled')."></td></form>";
				echo "<form name = 'regresar' method = 'POST' action = '".$_SERVER['PHP_SELF']."'>";
				echo "<td><input type = 'submit' value = 'Regresar al Inicio'></td></tr></form>";
				echo "	<script language='javascript' type='text/javascript'>";
				echo "		document.entrada.nombres.focus()";
				echo "	</script>";				

		}	
		}
}
	
///////////////////////////////////////////////// modificar registros ////////////////////////////////////////////////////////////////
if ($accion==3) {
	$consulta="select * from personal where codigo='".$cedula."' and id='".$_SESSION['id_validar']."' ";
	$resultado = mysql_query($consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysql_error());
	$num_rows = mysql_num_rows($resultado);
	if ($num_rows!=0) {
		include ("calendario/calendario.php");
		$row=mysql_fetch_array($resultado);
		echo "<center><img src='img2/administrator.png'><font color=black size=5>&nbsp;".trim($row['nombres'])." ".trim($row['nombres1']).' '.trim($row['apellidos'])." ".trim($row['apellidos1'])."</font></center><br>";
		echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data' onsubmit='return validar_cedula_nombre_apellido(this)'>";
		echo "<input type = 'hidden' name = 'modifica' value = '1'>";
		echo "<input type = 'hidden' name = 'status' value = 'I'>";

		echo "<table rules=none border=0 cellpadding=2 cellspacing=0 align='center' style='border-width: 1px; border-color: 75263C;border-style: solid;'>";
		//=================================================================================================///
		echo "<tr bgcolor='#43bced' height='25'>";
		echo "<td colspan=4 align = center><font color='white'> Datos Personales del Trabajador</font></td>";
		echo "</tr>";
		
		echo "<tr bgcolor='#F5F6CE'>";
			echo "<td  align = 'right'> C&eacute;dula: </td>";
			echo "<td  align = 'left'> <input type = 'text' name = 'cedula' size = '30' maxlength = '8' readonly value = '".$row['codigo']."' readonly> * </td>";
			echo "<td align = 'right' > Nacionalidad: </td>";
			echo "<td align = 'left'>";
			echo "<select name = 'nacionalidad'>";
				echo "<option value='V' ".($row['nacionalidad'] != 'E'?'selected':'')."> Venezolano(a)"; 
				echo "<option value='E' ".($row['nacionalidad'] == 'E'?'selected':'')."> Extranjero(a)"; 
			echo  "</select></td>";				
		echo "</tr>";
		echo "<tr bgcolor='#F5F6CE'>";
			echo "<td  align = 'right'> Primer Nombre: </td>";
			echo "<td  align = 'left'> <input type = 'text' name = 'nombres' size = '30' maxlength = '50' value = '".$row['nombres']."'> * </td>";
			echo "<td  align = 'right'> Segundo Nombre: </td>";
			echo "<td  align = 'left'> <input type = 'text' name = 'nombres1' size = '30' maxlength = '50' value = '".$row['nombres1']."'>  </td>";
		echo "</tr>";
		echo "<tr bgcolor='#F5F6CE'>";
			echo "<td align = 'right'> Primer Apellido: </td>";
			echo "<td align = 'left'> <input type = 'text' name = 'apellidos' size = '30' maxlength = '50' value = '".$row['apellidos']."'> * </td>";
			echo "<td align = 'right'> Segundo Apellido: </td>";
			echo "<td align = 'left'> <input type = 'text' name = 'apellidos1' size = '30' maxlength = '50' value = '".$row['apellidos1']."'>  </td>";
		echo "</tr>";
		
		echo "<tr bgcolor='#F5F6CE'>";
			cargar_select_modificar("empresa","Empresa", $row['empresa']); 	
			cargar_select_modificar("departamento","Departamento", $row['departamento']); echo "</tr>";
		echo "<tr bgcolor='#F5F6CE'>";
			cargar_select_modificar("cargo","Cargo", $row['cargo']); 
			$query = "select * from turno where id='".$_SESSION['id_validar']."' order by detalle";
			$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");	
			$resultado = mysql_num_rows($consulta);
			echo "<td align = 'right' > <font color=blue>Salario Mes: </td></font>";
			echo "<td align = 'left'> <input type = 'text' name = 'smes' size = '30' maxlength = '30' value = '".$row['smes']."'></td>";
			
		echo "<tr bgcolor='#F5F6CE'>";
			echo "<td align = 'right' > Fecha/Ingreso (ddmmaaaa): </td>";
			echo "<td align = 'left'>";
				if ($_SESSION['modo_validar']!=2) {
					$valor = (unir_fecha($row['fechai'])=='00000000'?'':unir_fecha($row['fechai']));
					escribe_formulario_fecha_modifica("fecing","entrada",$valor);
				} else {
					echo "<td align = 'left'> <input type = 'text' name = 'fecing' size = '10' maxlength = '10' value = '".mostrar_fecha($row['fechai'])."' readonly> </td>";
				}	
			echo "</td>";
			echo "<td align = 'right' > Fecha/Egreso: </td>";
			echo "<td align = 'left'>";
				if ($_SESSION['modo_validar']!=2) {
					$valor = (unir_fecha($row['fechae'])=='00000000'?'':unir_fecha($row['fechae']));
					escribe_formulario_fecha_modifica("fecegr","entrada",$valor);
				} else {
					echo "<td align = 'left'> <input type = 'text' name = 'fecegr' size = '10' maxlength = '10' value = '".mostrar_fecha($row['fechai'])."' readonly> </td>";
				}	
			echo "</td>";
		echo "</tr>";
		echo "</table><br><br>";
					
		echo "<table width = '20%' align ='center'>";
		echo "<tr><td><input type = 'submit' value = 'Grabar Cambios a Modificar?' ".(substr($_SESSION['acceso_validar'],17,1)=='1'?'':'disabled')."></td></form>";
		echo "<form name = 'regresar' method = 'POST' action = '".$_SERVER['PHP_SELF']."'>";
		echo "<td><input type = 'submit' value = 'Regresar al Inicio'></td></tr></form>";
		echo "	<script language='javascript' type='text/javascript'>";
		echo "		document.entrada.nombres.focus()";
		echo "	</script>";
	}
}

////////////////////////////////////////// busca por filtros en tabla de registros ////////////////////////////////////////////////////////////////
if ( (!$_POST || $_POST['busca']==1 || $_POST['graba']==1 || $_POST['modifica']==1 || $_POST['bandera']==3 || $_POST['bandera']==33) && $accion!=3 && $accion!=11) {
	
	if ($_POST['modifica']==1 ) $_POST['cedula']=='';
		
	if ($_POST['busca']==1 ) {
		echo "<form name = 'entrada' action = '".$_SERVER['PHP_SELF']."' method = 'POST'  enctype='multipart/form-data'>";
		echo "<input type = 'hidden' name = 'busca' value = '1'>";
		echo "<table cellpadding=2 cellspacing=0 width='500' align='center'>";
		echo "<tr>";
			echo "<td align=right> C&eacute;dula/Nombre/Apellido:</td>";
			echo "<td> <input name='cedula' size = '30' maxlength = '8'></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td align=right> Ordenado por:</td>";
			echo "<td>";
			echo "	<input type = 'radio' name = 'orden' value = 'ced' checked> cedula";
			echo "	<input type = 'radio' name = 'orden' value = 'nom'> nombre";
			echo "	<input type = 'radio' name = 'orden' value = 'ape'> apellido";
			echo "	<input type = 'radio' name = 'orden' value = 'sso'> Ficha";
		echo "</tr>";
		echo "</table>";
		echo "	<script language='javascript' type='text/javascript'>";
		echo "		document.entrada.cedula.focus()";
		echo "	</script>";
		echo "<table border=0  align = 'center'><tr>";
		echo "<td colspan=3><input type='image' src='img2/boton_buscar.jpg' value='Entrar' ></td>";
		echo "</form></table>";
	}
	
	$query1 = "";
	if ($_POST['cedula'] != "") {
		$query1 = " and (codigo like '%".$_POST['cedula']."%' or nombres like '%".$_POST['cedula']."%' or apellidos like '%".$_POST['cedula']."%') ";
	}
	if ($_POST['orden'] == "ced") $query2 = " order by codigo";
	else if ($_POST['orden'] == "nom") $query2 = " order by nombres";
	else if ($_POST['orden'] == "ape") $query2 = " order by apellidos";
	else if ($_POST['orden'] == "sso") $query2 = " order by sso";
	else $query2 = " order by nombres"; 
	
	$consulta="select * from personal where status<>'I' and id='".$_SESSION['id_validar']."' ".$query1.$query2;
	$resultado = mysql_query($consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysql_error());
	$num_rows = mysql_num_rows($resultado);
	if ($num_rows != 0){
			echo "<table rules=none border=0 cellpadding=2 cellspacing=0 align='center'>";
			echo "<tr bgcolor='#43bced' height='35'>";
			echo "<th align = center><font color='white'> # </font></th>";
			echo "<th align = center><font color='white'> Foto </font></th>";
			echo "<th align = left><font color='white'> C&eacute;dula </font></th>";
			echo "<th align = left><font color='white'> Nombres </font></th>";
			echo "<th align = left><font color='white'> Apellidos </font></th>";
			echo "<th align = left><font color='white'> Sueldo </font></th>";
			echo "<th align = center><font color='white'> Status </font></th>";
			echo "<th align = center><font color='white'> Ingreso </font></th>";
			echo "<th colspan = 3 align = center><font color='white'> Acci&oacute;n </font></th>";
			for ($cont=0;$cont<$num_rows;$cont++) {
				$row = mysql_fetch_array($resultado);
				$cedula = $row['codigo'];
				if ($color) {
					$tcolor="#dfdfd0";
					if (file_exists('fotos/'.$cedula.'.jpg')) $imagen='fotos/'.$cedula.'.jpg';
					else $imagen = 'img2/nohay2.jpg';
				} else { 
					$tcolor="white";
					if (file_exists('fotos/'.$cedula.'.jpg')) $imagen='fotos/'.$cedula.'.jpg';
					else $imagen = 'img2/nohay.jpg';
				}	
				echo '<tr bgcolor='.$tcolor.' >';
				echo "<td width='20'><font color=red>".($cont+1)."</font></td>";
				echo "<td align'center'><a href='".$_SERVER['PHP_SELF']."?accion=33&cedula=".$cedula."'><img src='".$imagen."' height='64' width='64'></a></td>";
				echo "<td width='100'><a href='".$_SERVER['PHP_SELF']."?accion=3&cedula=".$cedula."'>".$row['codigo']."</a></td>";
				echo "<td width='250'>".trim($row['nombres'])." ".$row['nombres1']."</td>";
				echo "<td width='250'>".trim($row['apellidos'])." ".$row['apellidos1']."</td>";
				echo "<td width='100'>".number_format($row['smes'],2)."</td>";
				echo "<td width='50' align='center'>".($row['status']=='A'?'<img src="img2/status_ver.png">':'<img src="img2/status_ver_naranja.png">')."</td>";
				echo "<td width='120' align=center>".$row['fechai']."</td>";
				
				if (substr($_SESSION['acceso_validar'],18,1)=='1')
				echo "<td width='30' align='center'><a onclick='return validar_elimina()' href='".$_SERVER['PHP_SELF']."?accion=2&cedula=".$cedula."'><img  border = 0  src='img2/icono_07.png'alt='eliminar éste registro' ></a></td>";
				else echo "<td width='30' align='center'>--</td>";
				
				if (substr($_SESSION['acceso_validar'],17,1)=='1')
				echo "<td width='30' align='center'><a href='".$_SERVER['PHP_SELF']."?accion=3&cedula=".$cedula."'><img border = 0 src='img2/icono_01.png' alt='modificar éste registro'></a></td>";
				else echo "<td width='30' align='center'>--</td>";
				
				if (substr($_SESSION['acceso_validar'],7,1)=='1')
				echo "<td width='30' align='center'><a href='archivo_trabajador_sueldo_cambiar.php?cedula=".$cedula."'><img border = 0 src='img2/sueldos.png' alt='modificar Sueldo'></a></td>";
				else echo "<td width='30' align='center'>--</td>";
				
				echo '</tr>';
				$color=!$color;
			}
			echo '</table>';
			echo "<center>Status: <img src='img2/status_ver.png'>(Activo)  -  <img src='img2/status_ver_naranja.png'>(Contratado)</center><br>";

			echo "<form name='imprimir' method='post' target ='_blank' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>";
			echo "  <input type = 'hidden' name = 'imprime' value = '1'>";
			echo "<center><input type = 'submit' value = 'Imprimir Resultado'></center></form>";
	} else echo "<hr>"; 		
	mysql_free_result($resultado);
	}	
} //=========================== CARGAR FOTOS=================================	
mysql_close($enlace);
echo "</font>";
echo "</body>";
echo "</html>";
}
?>