<?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'); 
include ("fphp.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=''; 
$accion=$_REQUEST["accion"];
$codigo=$_REQUEST["codigo"];
$tabla=$_REQUEST["tabla"];
$archivo=$_REQUEST["archivo"];
$exportar=$_REQUEST["exportar"];
$fila=''; $mensaje=0;

menu();
echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='images/b_elimina.png' alt='Elimina'>:Eliminar Usuario	
&nbsp;&nbsp;<img border = 0 src='images/b_edit.png' alt='Modificar'>:Modificar Usuario
</font><Hr>";

$accion=$_REQUEST["accion"];
$codigo=$_REQUEST["codigo"];
$tabla=$_REQUEST["tabla"];
$archivo=$_REQUEST["archivo"];
$exportar=$_REQUEST["exportar"];
///////////////////////////////////////////////// MUESTRA LAS TABLAS A EXPORTAR ////////////////////////////////////////////////////////////////
switch ($exportar) {
		case 1:	///////////////////////////////////////////////	TRABAJADORES //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Trabajadores</font>";
			$query="select * from personal where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=1&accion=1&query=".$query."'>
						<table align='center'><tr><td><input type='submit' value='Exportar trabajadores'></td></tr></table>
				</form>
				<table width = '100%'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&eacute;dula</font></th>
						<th align = center><font face='verdana' size=2>1° Apellidos</font></th>
						<th align = center><font face='verdana' size=2>2° Apellidos</font></th>
						<th align = center><font face='verdana' size=2>1° Nombres</font></th>
						<th align = center><font face='verdana' size=2>2° Nombres</font></th>
						<th align = center><font face='verdana' size=2>Status</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>";
								echo "<td>".$row['codigo']."</td>";
								echo "<td>".$row['apellidos']."</td>";
								echo "<td>".$row['apellidos1']."</td>";
								echo "<td>".$row['nombres']."</td>";
								echo "<td>".$row['nombres1']."</td>";
								echo "<td>".$row['status']."</td>";
							echo "</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 2:	///////////////////////////////////////////////	CONSTANTES //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Constantes</font>";
			$query="select * from constante where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo '<form name="entrada" method="POST" target="_blank" action="varios_exportar_excel.php?exportar=1&accion=7&query='.$query.'">';
				echo "<table align='center'><tr><td><input type='submit' value='Generar Excel'></td></tr></table>
				</form>
				<table width = '800' align='center'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&oacute;digo</font></th>
						<th align = center><font face='verdana' size=2>Detalle</font></th>
						<th align = center><font face='verdana' size=2>Unidad</font></th>
						<th align = center><font face='verdana' size=2>Fijo</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 3:	///////////////////////////////////////////////	CONCEPTOS //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Conceptos</font>";
			$query="select * from concepto where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=3&accion=3&query=$query'>
					<table align='center'><tr><td><input type='submit' value='Exportar conceptos'></td></tr></table>
				</form>
				<table width = '800' align=center>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&oacute;digo</font></th>
						<th align = center><font face='verdana' size=2>Detalle</font></th>
						<th align = center><font face='verdana' size=2>Cuenta</font></th>
						<th align = center><font face='verdana' size=2>Tipo</font></th>
						<th align = center><font face='verdana' size=2>Formula</font></th>
						<th align = center><font face='verdana' size=2>Acumula</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 4:	///////////////////////////////////////////////	CONSTANTE  INDIVIDUAL //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Constantes</font>";
			$query="select * from constante_individual where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=4&accion=4&query=$query'>
					<table align='center'><tr><td><input type='submit' value='Exportar constante individual'></td></tr></table>
				</form>
				<table width = '800' align='center'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&oacute;digo</font></th>
						<th align = center><font face='verdana' size=2>Cedula</font></th>
						<th align = center><font face='verdana' size=2>N&oacute;mina</font></th>
						<th align = center><font face='verdana' size=2>Monto</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 5:	///////////////////////////////////////////////	CONSTANTE  INDIVIDUAL //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Estructuras</font>";
			$query="select * from tablas where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=5&accion=5&query=$query'>
					<table align='center'><tr><td><input type='submit' value='Exportar Estructuras'></td></tr></table>
				</form>
				<table width = '800' align='center'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&oacute;digo</font></th>
						<th align = center><font face='verdana' size=2>Tabla</font></th>
						<th align = center><font face='verdana' size=2>Detalle</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 6:	///////////////////////////////////////////////	CONCEPTOS //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar N&oacute;mina</font>";
			$query="select * from nomina where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=6&accion=6&query=$query'>
					<table align='center'><tr><td><input type='submit' value='Exportar n&oacute;mina'></td></tr></table>
				</form>
				<table width = '800' align='center'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&oacute;digo</font></th>
						<th align = center><font face='verdana' size=2>Detalle</font></th>
						<th align = center><font face='verdana' size=2>Per&iacute;odo</font></th>
						<th align = center><font face='verdana' size=2>Cuenta</font></th>
						<th align = center><font face='verdana' size=2>Tipo</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 7:	///////////////////////////////////////////////	CONSTANTE  INDIVIDUAL //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar Per&iacute;odo</font>";
			$query="select * from periodo where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=7&accion=7&query=$query'>
					<table align='center'><tr><td><input type='submit' value='Exportar per&iacute;odo'></td></tr></table>
				</form>
				<table width = '800' align='center'>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>N&oacute;mina</font></th>
						<th align = center><font face='verdana' size=2>Per&iacute;odo</font></th>
						<th align = center><font face='verdana' size=2>Desde</font></th>
						<th align = center><font face='verdana' size=2>Hasta</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>
								<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td>
							</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
		case 8:	///////////////////////////////////////////////	PAYROLL  //////////////////////////////////////////
			echo "<font face='verdana, arial, helvetica, sans-serif' size=4 >Exportar PAYROLL</font>";
			$query="select * from $tabla where id=".$_SESSION['id_validar']." ";
			$consulta=mysqli_query($enlace,$query) or die ($query);
			$filas=mysqli_num_rows($consulta);
			if ($filas==0) {
				echo "La tabla está VACIA...";
			} else {
				echo "
				<form name='entrada' method='POST' target='_blank' action='varios_exportar_excel.php?exportar=8&accion=8&query=$query&tabla=$tabla&archivo=$archivo'>
					<table align='center'><tr><td><input type='submit' value='Exportar PAYROLL'></td></tr></table>
				</form>
				<table width = '1200' align=center>
					<tr bgcolor = '#00BFFF'>
						<th align = center><font face='verdana' size=2>C&eacute;dula</font></th>
						<th align = center><font face='verdana' size=2>Concepto</font></th>
						<th align = center><font face='verdana' size=2>desconcepto</font></th>
						<th align = center><font face='verdana' size=2>Tipo</font></th>
						<th align = center><font face='verdana' size=2>Monto</font></th>
						<th align = center><font face='verdana' size=2>Saldo</font></th>
						<th align = center><font face='verdana' size=2>Cantidad</font></th>
						<th align = center><font face='verdana' size=2>N&oacute;mina</font></th>
						<th align = center><font face='verdana' size=2>Desn&oacute;mina</font></th>
						<th align = center><font face='verdana' size=2>Per&iacute;odo</font></th>
						<th align = center><font face='verdana' size=2>Desper&iacute;odo</font></th>";
						while ($row = mysqli_fetch_array($consulta)) {
							echo "
							<tr bgcolor = '#cdcdcd'>";
								echo "<td>".$row['codigo']."</td>";
								echo "<td>".$row['apellidos']."</td>";
								echo "<td>".$row['apellidos1']."</td>";
								echo "<td>".$row['nombres']."</td>";
								echo "<td>".$row['nombres1']."</td>";
								echo "<td>".$row['status']."</td>";
							echo "</tr>";
						}
				echo "
					</tr>
				</table>";
			}
			break;
	}
	mysqli_free_result($consulta);
	echo "</font></body></html>";
?>