<?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=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'].")";
	$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=mysql_query("select * from $tabla1");
		if (mysql_num_rows($a)>0) {
			$va++;
			mysql_query("delete from constante_individual where id='".$_SESSION['id_validar']."' ");
			mysql_query("insert into constante_individual select * from `$tabla1`");
		}
		
		$tabla2="zr2_".trim($_SESSION['id_validar']);
		$a=mysql_query("select * from $tabla2");
		if (mysql_num_rows($a)>0) {
			$va++;
			mysql_query("delete from prestamo where id='".$_SESSION['id_validar']."' ");
			mysql_query("insert into prestamo select * from `$tabla2`");
		}
	
		if ($va==2) mysql_query("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 = mysql_query("select * from periodo where id='".$_SESSION['id_validar']."' order by nomina,periodo") or die ("select * from periodo order by periodo, nomina");	
		$numr = mysql_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 = mysql_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>";	

?>