<?php session_start();
include ("class.phpmailer.php");
include ("correo.php"); 
require ("conexion.php");
$today = date("Y-m-d");
$ipvisitante = $_SERVER["REMOTE_ADDR"];
$usuariom = $_SESSION['usuario_nombre'];
$usuarionc = $_SESSION['NombreCompleto'];
$usuarioc = $_SESSION['usuario_email'];
$Perfil=$_SESSION['Perfil'];

if (isset($_SESSION['usuario_nombre'])) {   
            if ($Perfil==1 or $Perfil==6){


    $pedido=$_GET['Pedido'];
    $OK = true;
    if (isset($_GET['Pedido'])) {
	$result = mysqli_query($enlace, "SELECT * FROM almacen WHERE Pedido = '$pedido'");
      
		($row = mysqli_fetch_array($result));
        if (empty($row)) {
            $result = "No se encontraron resultados !!";
        }
    }
    if (array_key_exists('update', $_POST)) {
		$Fecha_REA = $_POST['Fecha_REA'];
		$Observaciones = $_POST['Observaciones'];
		$OK = (array($_POST['Fecha_REA'], $_POST['Observaciones'],$_GET['Pedido']));
        
        if (!$OK) {
            echo $error[2];
        } else {
           $meter = mysqli_query($enlace,"UPDATE almacen SET Fecha_REA = '$Fecha_REA', Observaciones = '$Observaciones', IP = '$ipvisitante', usuariom = '$usuariom' WHERE Pedido = '$pedido'");
                 if($meter){
					header("refresh: 2;ResumenAlmacen.php");
					   echo 'He modificado la Recepcion del Pedido Numero '.$pedido.'. ';
                        
                        
                        $mail->From = "planeacion@insepet.com";     
                        $mail->FromName = "Planeacion Produccion Insepet"; 
                        $mail->Subject = "Se modifico la fecha de Recepcion del Pedido Numero $pedido"; 
                        $mail->AltBody = "Correo Planeacion"; 
                        $mail->MsgHTML("<b>Se ha modificado la recepcion del pedido numero $pedido</b>.
                            <BR>La Fecha de recepcion en almacen es: $Fecha_REA.
                            <BR>El pedido $pedido se ha recibido bajo las siguientes observaciones:
                            <BR><b>$Observaciones.</b>
                            <BR>
                            <BR>
                            <BR>Att: $usuarionc.
                            <BR>Sistema de Planificacion de Pedidos Insepet Ltda"); 
                            //$mail->AddAttachment("files/files.zip"; 
                            //$mail->AddAttachment("files/img03.jpg"; 
                            $mail->AddAddress("aleida.acuna@insepet.com", "Aleida Acuña"); 
                            $mail->AddCC($usuarioc);
                            $mail->IsHTML(true); 
                                if(!$mail->Send()) { 
                                    echo "Error: " . $mail->ErrorInfo; 
                                } else { 
                                    echo "Mensaje enviado correctamente"; 
                                }
                    }   else  {
                                echo 'Ha existido un problema por favor vuelta a intentarlo.';
                                header("refresh: 2;modificar_almacen.php?Pedido=".$_GET['Pedido']);
                            }
            exit;
        }
    }
 ?>
 <!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>ModificacionAlmace</title>
        <meta http-equiv="X-UA-Compatible" content="IE=9,crome" />
        <meta name="copyright" content="Datasoft Engineering 2013"/>
        <meta name="author" content="Javier Martinez" />
        <meta name="email" content="ibarragan@behstant.com"/>
        <meta name="description" content="ModificacionPlaneacion" />
    </head>
    <?php
        if(!$OK) :
            echo "";
        else :
    ?>
        <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_REA">Fecha Recibido Almacen:</label></td>
                        <td><input type="date" name="Fecha_REA" id="Fecha_REA" value="<?php echo $row['Fecha_REA'];?>"/></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><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="ResumenAlmacen.php">&lt;&lt; Regresar</a></p>
    <?php endif;?>
    <body>
</html>

<?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
}
?>