<? session_start();

if (isset($_SESSION['tipousuario']))
		{if ($_SESSION['tipousuario']=='1')
		header ('location:menu_personal.php');
		}

if  (trim($_SESSION['nombre_validar'])=='') header ('location:index.php');
include ("fphp.php");
include ("calendario/calendario.php");
$enlace=cargar_conexion();

$consulta=mysqli_query($enlace,"select * from periodo where id='".$_SESSION['id_validar']."' order by nomina,periodo desc limit 1");
if (mysqli_num_rows($consulta)!=0){
	$row=mysqli_fetch_array($consulta);
	$per=mostrar_fecha($row['desde']).' al '.mostrar_fecha($row['hasta'])." (Nom:".$row['nomina'].")";
} else $per='';
menu();
//alinea iconos
echo "<table width='90%' align='center'><tr><td align=left>";
//alinea iconos
echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='img2/pantalla.png' alt='Seleccionar'>&nbsp;Consultar x Pantalla";
echo "&nbsp;&nbsp;<img border = 0 src='img2/icono_02.png' alt='Seleccionar'>&nbsp;Imprimir Informe";
// cierra alinea iconos
echo "</td></tr></table>";
// cierra alinea iconos
echo "<hr><h2>Informe de Prestaciones e Intereses sobre Prestaciones Sociales</h2>";

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 colspan = 3>";
		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 = 'fechai'> Fecha Ingreso";
	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><input type = 'submit' value = 'Buscar Registros'></td>";
	echo "</tr></table></form>";

	$query1 = "";
	if ($_POST['cedula'] != "") {
		$query1 = " and (codigo like '%".$_POST['cedula']."%' or nombres like '%".$_POST['cedula']."%' or apellidos like '%".$_POST['cedula']."%') ";
	}
	if ($_POST['orden'] == "fechai") $query2 = " order by fechai";
	else if ($_POST['orden'] == "ced") $query2 = " order by codigo";
	else if ($_POST['orden'] == "ape") $query2 = " order by apellidos";
	else $query2 = " order by nombres";

	$consulta="select * from personal where id='".$_SESSION['id_validar']."' and status<>'I'".$query1.$query2;
	//$consulta="select * from personal where id='".$_SESSION['id_validar']."' ".$query1.$query2;
	$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'> 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'> Ficha </font></th>";
			echo "<th align = center><font color='white'> Sueldo </font></th>";
			echo "<th align = center><font color='white'> Ingreso </font></th>";
			echo "<th colspan = 4 align = center><font color='white'> Acci&oacute;n </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 align'center'><img src='".$imagen."' height='64' width='64'></td>";
				echo "<td width='100'><a target='_blank' href='prestaciones_informe_consultar.php?accion=2&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>".mostrar_fecha($row['fechai'])."</td>";

				echo "<td width='30' align='center'><a target='_blank' href='prestaciones_informe_consultar.php?accion=2&cedula=".$cedula."'><img border = 0 src='img2/pantalla.png' alt='Seleccionar �ste registro'></a></td>";
				//echo "<td width='30' align='center'><a target='_blank' href='prestaciones_informe_imprimir.php?accion=2&cedula=".$cedula."'><img border = 0 src='img2/icono_02.png' alt='Seleccionar �ste registro'></a></td>";

				echo '</tr>';
				$color=!$color;
			}
			echo '</table>';
	} else echo "<hr>";
mysqli_free_result($resultado);
mysqli_close($enlace);
echo "<br><br><br><br></body>";
echo "</html>";
?>
