<?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');

///===================================================================================================================== mostrar contrato
if ($_REQUEST['accion'] == '1') {
	$contrato = $_REQUEST['contrato'];
	$lcontrato = 'id' . $_SESSION['id_validar'] . 'nro' . $contrato;
	header('location: contrato/' . $lcontrato . '.html');
	exit();
}

///===================================================================================================================== pantalla inicial
include("fphp.php");
$enlace = cargar_conexion();
menu();
echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='images/b_regresa.png' alt='Regresar'>:<a href='archivo_trabajador_contratos.php'>Regresar</a><hr>";
echo "<h2>Historicos de Contratos</h2></center><br><br>";

$consulta = "select contrato_historico.*, personal.nombres, personal.nombres1, personal.apellidos, personal.apellidos1, personal.smes, personal.status, personal.fechai, personal.codigo from contrato_historico,personal where contrato_historico.id='" . $_SESSION['id_validar'] . "' and personal.id='" . $_SESSION['id_validar'] . "' and contrato_historico.cedula=personal.codigo order by contrato_historico.contrato desc";
$resultado = mysqli_query($enlace, $consulta) or die('verificaci&oacute; del c&oacute;digo fall&oacute;: ' . mysqli_error($enlace));
$num_rows = mysqli_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'> # Contrato </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>";
	for ($cont = 0; $cont < $num_rows; $cont++) {
		$row = mysqli_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'><a target='_blank' href='" . $_SERVER['PHP_SELF'] . "?accion=1&contrato=" . $row['contrato'] . "'><font color=red>" . ($row['contrato']) . "</font></a></td>";
		echo "<td align'center'><img src='" . $imagen . "' height='64' width='64'></td>";
		echo "<td width='100'><a target='_blank' href='" . $_SERVER['PHP_SELF'] . "?accion=1&contrato=" . $row['contrato'] . "'>" . $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>" . mostrar_fecha($row['fechai']) . "</td>";
		echo '</tr>';
		$color = !$color;
	}
	echo '</table>';
} else echo "<hr>";
mysqli_close($enlace);
?>
<br><br>
</body>

</html>