<?php
session_start();
if (!isset($_SESSION["user_id"]) || $_SESSION["user_id"]==null):
    print "<script>alert(\"Acceso Invalido!\");
    window.location='login.php';</script>";
endif;
if ($_SESSION["user_at"] < 2):
    print "<script>alert(\"Sin Acceso a Transaccion!\");
    window.location='vt000.php';</script>";
endif;
include_once ("lib/fpdf/funci.php");
$conex = conectar();
date_default_timezone_set('America/La_Paz');
$xusua = $_SESSION["user_id"];
$xcart = $_GET['id'];
$datos = mysql_query("select * from inart where inartcart = '$xcart'");
$mirow = mysql_fetch_array($datos);
$nocor = $mirow[1];
$nolar = $mirow[2];
$image = $mirow[3];
$unmed = $mirow[4];
$ubica = $mirow[5];
$grupo = $mirow[6];
$subgr = $mirow[7];
$prven = $mirow[10];
$stmax = $mirow[11];
$stmin = $mirow[12];
$estfe = $mirow[13];
$sqgrp = mysql_query("select * from ingrp where ingrpgrup = '$grupo'");
$sqsgp = mysql_query("select * from insgp
                      where insgpgrup = '$grupo'
                      and   insgpsubg = '$subgr'");
?>
<html>
<head>
   <meta charset="utf-8">
   <link href="css/tabla.css" rel="stylesheet" type="text/css" />
   <link href="bootstrap/css/bootstrap.css" rel="stylesheet" />
   <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
   <script src="//code.jquery.com/jquery-1.9.1.js"></script>
   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
   <link rel="stylesheet" href="/resources/demos/style.css">
<script>
   $(function() {
      $("#fenac").datepicker({
         dateFormat: 'dd-mm-yy'});
      $("#fereg").datepicker({
         dateFormat: 'dd-mm-yy'});
      $("#febaj").datepicker({
         dateFormat: 'dd-mm-yy'});
   });
</script>
<script>
   function validanum(e) {
      tecla = (document.all) ? e.keyCode : e.which;
      //Tecla de retroceso para borrar, siempre la permite
      if (tecla==8){
         return true;
      }
      // Patron de entrada, en este caso solo acepta numeros
      patron =/[0-9.]/;
      tecla_final = String.fromCharCode(tecla);
      return patron.test(tecla_final);
   }
</script>
<script>
   function validalet(e) {
      tecla = (document.all) ? e.keyCode : e.which;
      //Tecla de retroceso para borrar, siempre la permite
      if (tecla==8){
         return true;
      }
      // Patron de entrada, en este caso solo acepta letras
      patron =/[A-Za-z/ ]/;
      tecla_final = String.fromCharCode(tecla);
      return patron.test(tecla_final);
   }
</script>
/*
<script type="text/javascript">
   $(document).ready(function(){
      //$('#grupo').val(1);
      recargarLista();
      $('#grupo').change(function(){
         $('#subgp').find('option').remove().end().append(
           '<option value=""></option>').val();
         recargarLista();
      });
   })
</script>
<script type="text/javascript">
   function recargarLista(){
      $.ajax({
         type:"POST",
         url:"vt227x.php",
         data:"producto=" + $('#grupo').val(),
         success:function(r){
            $('#subgp').html(r);
         }
      });
   }
</script>
*/
<style type="text/css">   
   .campos{
      border-radius: 5px;
      border: 1px solid #39c;
      text-align: left;
      font-family: Arial;
      font-size: 10pt;
      background-color: #E9E9E9;
   }

   .redondo{
      border-radius: 5px;
      border: 1px solid #39c;
   }

   .select{
      border-radius: 5px;
      border: 1px solid #39c;
   }
</style>
</head>
<body>
   <center><h1>Modificar Producto</h1></center>
<form method="post" autocomplete="off">
   <center><table bgcolor= "#E0FFFF" border="1" width="77%" cellpadding="1" cellspacing="1" class="redondo">
   <tr height="50">
      <td>&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Codigo</strong></FONT>
      &nbsp;
      <input name="xcodi" type="text" value="<?php echo $xcart;?>" style="text-align: center" class="campos" size="16" maxlength="15" readonly>
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre Largo</strong></FONT>
      &nbsp;
      <input name="nolar" type="text" value="<?php echo $nolar;?>" class="campos" autofocus size="47" maxlength="40">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre Corto</strong></FONT>
      &nbsp;
      <input name="nocor" type="text" value="<?php echo $nocor;?>" class="campos" size="29" maxlength="25">
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>U/M</strong></FONT>
      &nbsp;
      <select name="unmed" style="width:120px" class="campos">
      <?php
      $daumd = "select * from inumd
                order  by 1";
      $squmd = mysql_query($daumd);
      while ($liumd = mysql_fetch_assoc($squmd)):
         if ($liumd["inumdumed"] == $unmed):
            echo "<option  value='".$liumd['inumdumed']."' selected>".$liumd['inumddesc']."</option>";
         else:
            echo "<option  value='".$liumd['inumdumed']."'>".$liumd['inumddesc']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&emsp;&emsp;&emsp;&emsp;
      <FONT FACE="times new roman"><strong>Ubicacion</strong></FONT>
      &nbsp;
      <select name="ubica" style="width:110px" class="campos">
      <?php
      $daubi = "select * from inubi
                order  by 1";
      $squbi = mysql_query($daubi);
      while ($liubi = mysql_fetch_assoc($squbi)):
         if ($liubi["inubiubic"] == $ubica):
            echo "<option  value='".$liubi['inubiubic']."' selected>".$liubi['inubiubic']."</option>";
         else:
            echo "<option  value='".$liubi['inubiubic']."'>".$liubi['inubiubic']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&emsp;&emsp;&emsp;&emsp;
      <FONT FACE="times new roman"><strong>Grupo</strong></FONT>
      &nbsp;
      <select id="grupo" name="grupo" style="width:150px" class="campos">
      <?php
      while ($ligrp = mysql_fetch_assoc($sqgrp)):
         if ($ligrp['ingrpgrup'] == $grupo):
            echo "<option  value='".$ligrp['ingrpgrup']."' selected>".$ligrp['ingrpdesc']."</option>";
         else:
            echo "<option  value='".$ligrp['ingrpgrup']."'>".$ligrp['ingrpdesc']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&emsp;&emsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Sub-Grupo</strong></FONT>
      &nbsp;
      <select id="subgp" name="subgp" style="width:150px" class="campos" noentry="noentry">
      <?php
      while ($lisgp = mysql_fetch_assoc($sqsgp)):
         if ($lisgp['insgpsubg'] == $subgr):
            echo "<option  value='".$lisgp['insgpsubg']."' selected>".$lisgp['insgpdesc']."</option>";
         else:
            echo "<option  value='".$lisgp['insgpsubg']."'>".$lisgp['insgpdesc']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Stock Max</strong></FONT>
      &nbsp;
      <input name="stmax" type="text" value="<?php echo $stmax;?>" style="text-align: center" class="campos" size="12" maxlength="12" onkeypress="return validanum(event)">
      &emsp;&nbsp;
      <FONT FACE="times new roman"><strong>Stock Min</strong></FONT>
      &nbsp;
      <input name="stmin" type="text" value="<?php echo $stmin;?>" style="text-align: center" class="campos" size="12" maxlength="12" onkeypress="return validanum(event)">
      &emsp;&nbsp;
      <FONT FACE="times new roman"><strong>Precio Venta</strong></FONT>
      &nbsp;
      <input name="prven" type="text" value="<?php echo $prven;?>" style="text-align: center" class="campos" size="15" maxlength="15" onkeypress="return validanum(event)">
      &emsp;&nbsp;
      <FONT FACE="times new roman"><strong>Imagen</strong></FONT>
      &nbsp;
      <input name="image" type="text" value="<?php echo $image;?>" value="<?php echo $xdire;?>" class="campos" size="36" maxlength="30">
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Control Lote y Fecha</strong></FONT>
      &nbsp;
      <select name="estfe" style="width:50px" class="campos" noentry="noentry">
      <?php
      $daven = "select * from inlfv where inlfvcorr = '$estfe'
                order  by 1 desc";
      $sqven = mysql_query($daven);
      while ($liven = mysql_fetch_array($sqven)):
         if ($liven['inlfvcorr'] == $estfe):
            echo "<option  value='".$liven[0]."' selected>".$liven[1]."</option>";
         else:
            echo "<option  value='".$liven[0]."'>".$liven[1]."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
      <button type="submit" name="enviar" class="btn btn-success">Grabar el Formulario</button>
      &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
      <a href="vt229.php" class="btn btn-danger">Salir del Formulario</a>
      </td>
   </tr>
</center></table>
</form>
</body>
</html>
<?php
if (isset($_POST["enviar"])):
    if ($_POST["xcodi"] == "" or $_POST["nolar"] == "" or $_POST["nocor"] == ""):
        print '<script language="JavaScript">';
        print 'alert("Llenar los Campos Requeridos");';
	print '</script>';
    else:
	$nolar = trim(strip_tags($_POST["nolar"]));
	$nocor = trim(strip_tags($_POST["nocor"]));
	$unmed = trim(strip_tags($_POST["unmed"]));
	$ubica = trim(strip_tags($_POST["ubica"]));
        $stmax = trim(strip_tags($_POST["stmax"]));
        $stmin = trim(strip_tags($_POST["stmin"]));
        $prven = trim(strip_tags($_POST["prven"]));
        $image = trim(strip_tags($_POST["image"]));
        mysql_query("lock tables inart write");
        $arsql = "update inart set inartnart = '$nocor', inartdesc = '$nolar',
                                   inartumed = '$unmed', inartubic = '$ubica',
                                   inartsmax = '$stmax', inartsmin = '$stmin',
                                   inartpven = '$prven', inartimag = '$image'
                  where  inartcart = '$xcart'";
        mysql_query($arsql);
        mysql_query("unlock tables");
        print "<script>alert(\"La Modificacion se Grabo!\");
        window.location='vt229.php';</script>";
    endif;
endif;
?>
