<?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');
set_time_limit(3000); 
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);
	$_SESSION['per_validar']=mostrar_fecha($row['desde']).' al '.mostrar_fecha($row['hasta'])." (Nom:".$row['nomina'].")";
	$cierreperiodo= ($row['pre']==0?'PRE-CIERRE':'CIERRE AUDITADO'); 	
} else $_SESSION['per_validar']=''; 
//================================================ pantalla 
menu();
echo "<b>Observaci&oacute;n:</b> &nbsp;&nbsp;El Reproceso NO es reversible y podria eliminar una nomina v&aacute;lida, verifique antes de efectuarla.";
echo "<hr><h2>Reprocesar N&oacute;mina Auditadas</h2>";
$entra=0;

//================================================ reporcesar
if ($_POST['bandera']==1) {
	if (strtoupper($_POST['si'])=='SISI') {

		$va=0;
		$tabla1="zr1_".trim($_SESSION['id_validar']);
		$a=mysqli_query($enlace,"select * from $tabla1");
		if (mysqli_num_rows($a)>0) {
			$va++;
			mysqli_query($enlace,"delete from constante_individual where id='".$_SESSION['id_validar']."' ");
			mysqli_query($enlace,"insert into constante_individual select * from `$tabla1`");
		}
		
		$tabla2="zr2_".trim($_SESSION['id_validar']);
		$a=mysqli_query($enlace,"select * from $tabla2");
		if (mysqli_num_rows($a)>0) {
			$va++;
			mysqli_query($enlace,"delete from prestamo where id='".$_SESSION['id_validar']."' ");
			mysqli_query($enlace,"insert into prestamo select * from `$tabla2`");
		}
	
		if ($va==2) mysqli_query($enlace,"delete from periodo where id='".$_SESSION['id_validar']."' and nomina='".substr($_POST['periodo1'],13,3)."' and periodo ='".substr($_POST['periodo1'],0,3)."' ");
		
		$mensaje = 'Reproceso efectuado Satisfactoriamente....';
		
	}	
} 


//================================================ pantalla iniciar
echo "<form name='entrada' action='".$_SERVER['PHP_SELF']."' target='blank' method='POST' enctype='multipart/form-data'>";
echo "<input type = 'hidden' name = 'bandera' value = '1'>";		
echo "<table align='center'>";
		$consulta = mysqli_query($enlace,"select * from periodo where id='".$_SESSION['id_validar']."' order by nomina,periodo") or die ("select * from periodo order by periodo, nomina");	
		$numr = mysqli_num_rows($consulta);
		echo "<td align = 'right'> <font color=red>Per&iacute;odo / N&oacute;mina: </font></td>";
		echo "<td align = 'left'> <select style='width:300px;' name = 'periodo1'>";
			for ($x=1;$x<=$numr;$x++) {
				$row1 = mysqli_fetch_array($consulta); 
				if ($x!=1) {
					echo "<option>".$row1['periodo']." - Nomina:".$row1['nomina']." - ".$row1['desde']." al ".$row1['hasta'];
				}	
			}
		echo "</select></td></tr>";
		echo "<tr>";
			echo "<td align = 'right'> Reprocesar? (SIx2) </td>";
			echo "<td align = 'left'> <input type = 'text' name = 'si' size = '5' maxlength = '4' </td>";
		echo "</tr>";
		echo "<tr><td align='center'></td>";
			echo "<td align='center'><input name='ver' type='submit' value='Reprocesar Nomina'>";
		echo "</td></tr>";
echo "</table></form>";
		
if ($mensaje!='') echo "<br><br><center><font style='color:black; font-size:2em;' face='Verdana' ><b>".$mensaje."</b></font></center>";	

?>