<?php session_start();
require ("conexion.php");
include ("class.phpmailer.php");
include ("correo.php");  
//$sql = mysqli_query($enlace,"SELECT usuario_nombre FROM usuarios");//Este es el script SQL que necesitas para jalar el ultimo registro
$today = date("Y-m-d");
$ipvisitante = $_SERVER["REMOTE_ADDR"];
$usuariom = $_SESSION['usuario_nombre'];
$usuarioc = $_SESSION['usuario_email'];
$Perfil=$_SESSION['Perfil'];

if (isset($_SESSION['usuario_nombre'])) {    
    if ($Perfil==1 or $Perfil==2){
		$pedido=$_GET['Pedido'];
		$OK = true;
			if (isset($_GET['Pedido'])) {
				$result = mysqli_query($enlace, "SELECT * FROM planeacion WHERE Pedido = '$pedido'");
				($row = mysqli_fetch_array($result));
				if (empty($row)) {
					$result = "No se encontraron resultados !!";
				}else{
						$OK = (array($_POST['Fecha_PD'],$_POST['EDS_EMPRESA'], $_POST['Petrolera'],$_POST['Tipo_Trabajo'],$_POST['Cliente'],$_POST['Proveedor'], $_POST['Fecha_EC'],$_POST['Solicitado'],$_POST['Responsable'], $_POST['CorreoComercial'],$_POST['Observaciones'],$_GET['Pedido']));
        
					if (!$OK) {
						echo $error[2];
					} else {
?>
							<!DOCTYPE html>
								<html lang="en">
									<head>
									</head>

										<fieldset style="width:480px"    >
											<legend>Editar Pedido</legend>
											<form action="" method="post">
												<table>
													<tr>
														<td><label for="id">Pedido:</label></td>
														<td><input type="text" name="Pedido" id="Pedido"/ disabled="disabled" value="<?php echo $row['Pedido'];?>"></td>
													</tr>
													<tr>
														<td><label for="Fecha_PD">Fecha Pedido:</label></td>
														<td><input type="date" name="Fecha_PD" id="Fecha_PD"/ value="<?php echo $row['Fecha_PD'];?>"></td>
													</tr>
													<tr>
														<td><label for="EDS_EMPRESA">EDS_EMPRESA:</label></td>
														<td><input type="text" name="EDS_EMPRESA" id="EDS_EMPRESA" value="<?php echo $row['EDS_EMPRESA'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Petrolera">Petrolera:</label></td>
														<td><input type="text" name="Petrolera" id="Petrolera" value="<?php echo $row['Petrolera'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Tipo_Trabajo">Tipo_Trabajo:</label></td>
														<td><input type="text" name="Tipo_Trabajo" id="Tipo_Trabajo" value="<?php echo $row['Tipo_Trabajo'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Cliente">Cliente:</label></td>
														<td><input type="text" name="Cliente" id="Cliente" value="<?php echo $row['Cliente'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Proveedor">Proveedor:</label></td>
														<td><input type="text" name="Proveedor" id="Proveedor" value="<?php echo $row['Proveedor'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Fecha_EC">Fecha Entrega Cliente:</label></td>
														<td><input type="date" name="Fecha_EC" id="Fecha_EC" value="<?php echo $row['Fecha_EC'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Solicitado">Solicitado:</label></td>
														<td><input type="text" name="Solicitado" id="Solicitado" value="<?php echo $row['Solicitado'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Responsable">Responsable:</label></td>
														<td><input type="text" name="Responsable" id="Responsable" value="<?php echo $row['Responsable'];?>"/></td>
													</tr>
													<tr>
														<td><label for="CorreoComercial">Comercial a cargo:</label></td>
														<td><input type="email" name="CorreoComercial" id="CorreoComercial" value="<?php echo $row['CorreoComercial'];?>"/></td>
													</tr>
													<tr>
														<td><label for="Observaciones">Observaciones:</label></td>
														<td><input type="text" name="Observaciones" id="Observaciones" value="<?php echo $row['Observaciones'];?>"/></td>
													</tr>
													<tr>
														<td><label for="attachment">Adjuntar archivo: </label></td>
														<td><input id="attachment" name="attachment" type="file"></td>
													</tr>
													<tr>
														<td><input type="submit" name="update" value="Actualizar"/></td>
														<td><input type="submit" name="delete" value="Eliminar" disabled="disabled"/></td>
													</tr>
												</table>
											</form>
										</fieldset>
								 
										<p><a href="unicuadromodificacion.php">&lt;&lt; Regresar</a></p>
							<body>
								</html>
<?php
					mysqli_close($enlace); //Cerramos la conexion a la db
					}
		}else{
        header("refresh: 5; URL=http://indicadores.insepet.com/modificacion.php?Pedido=".$_GET['Pedido']);       
	   echo 'El registro no puede ser diferente de Remanufactura o Pintura.';
	   mysqli_close($enlace); //Cerramos la conexion a la db
		}
    }
 ?>

<?php
		$FECHAOLD=$_SESSION['UltimoIngreso'];
		$HORA=date('Y-n-j H:i:s');
		$tiempo=(strtotime($HORA) - strtotime($FECHAOLD));

		if($tiempo>=600){
			session_destroy();
			echo '<script language=javascript> alert ("su session a sido caducada por su seguridad, por favor ingrese nuevamente.") self.location="index.php"</script>';
			}else{
				$_SESSION['UltimoIngreso']=$HORA;
			}
	}else{
        echo 'El usuario no tiene los permisos suficientes para acceder a la web';
         mysqli_close($enlace); //Cerramos la conexion a la db
    }
	}else{
		echo 'El usuario no tiene acceso a esta pagina web comuniquese con el administrador del sistema';
		mysqli_close($enlace); //Cerramos la conexion a la db
		}
?>