<?php
session_start();
include("config.php");
if(!isset($_SESSION['user']) || !isset($_SESSION['pass'])){
  header("Location: login.php");
}else{
  $sql = "SELECT * FROM usuario WHERE usuario = '".$_SESSION['user']."' and clave = '".$_SESSION['pass']."' and estado ='1'";
  
  $result=mysqli_query($con,$sql);
  while ($fila =mysqli_fetch_assoc($result)) {
    $AccesoPermitido = "ok";
  }
  if ( $AccesoPermitido != "ok"){
    header("Location: login.php");
  }else{
    $id = $_POST['id'];
    $estado = $_POST['estado'];
    $orden = $_POST['orden'];
  
    $id_v=filter_var_array($id, FILTER_SANITIZE_STRING);
    $estado_v=filter_var_array($estado, FILTER_SANITIZE_STRING);   
    $orden_v=filter_var_array($orden, FILTER_SANITIZE_STRING);

    if($id_v && $estado_v && $orden_v){
      for ($i=0;$i<count($id_v);$i++) {
        $sql = "UPDATE exito SET estado =".mysqli_real_escape_string($con,$estado_v[$i]).", orden = ".mysqli_real_escape_string($con,$orden_v[$i])." WHERE id=".mysqli_real_escape_string($con,$id_v[$i]); 
        $result=mysqli_query($con,$sql);
      } 
      echo "Grabando...";
      ?>
      <script type="text/javascript">
        window.location.href="casosexito.php";
      </script>
      <?
    }else{
      ?>
      <script type="text/javascript">
      alert('Lo sentimos, los datos estan íncompletos o son incorrectos');
        window.location.href="casosexito.php";
      </script>
      <?php
    }
  }
}
?>
