<?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"] < 4):
    print "<script>alert(\"Sin Acceso a Transaccion!\");
    window.location='vt221.php';</script>";
endif;
include_once ("lib/fpdf/funci.php");
$coalm = $_SESSION["user_al"];
$conex = conectar();
date_default_timezone_set('America/La_Paz');
$xusua = strtoupper($_SESSION["user_id"]);
$xcart = $_GET['id'];
$datos = mysql_query("select * from vtart where vtartcart = '$xcart' and vtartcalm = '$coalm'");
if ($row = mysql_fetch_array($datos)):
   $fereg = date("d-m-Y",strtotime($row["vtartfpro"]));
   $nolar = $row["vtartdesc"];
   $nocor = $row["vtartnart"];
   $unmed = $row["vtartumed"];
   $categ = $row["vtartcate"];
   $ubica = $row["vtartubic"];
   $prcom = $row["vtartpcom"];
   $prven = $row["vtartpven"];
   $stmax = $row["vtartsmax"];
   $stmin = $row["vtartsmin"];
   ?>
   <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>
   <style type="text/css">   
      .campos{
         border-radius: 5px;
         border: 1px solid #39c;
         text-align: left;
         font-family: Arial;
         font-size: 9pt;
         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="65%" cellpadding="1" cellspacing="1" class="redondo">
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Fecha de Registro</strong></FONT>
      &nbsp;
      <input name="fereg" type="text" style="text-align: center" class="campos" value="<?php echo $fereg;?>" id="fereg" size="10" maxlength="10" disabled=true>
      &nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Codigo</strong></FONT>
      &nbsp;
      <input name="xcart" style="text-align: center" class="campos" type="text" value="<?php echo $xcart;?>" size="16" maxlength="15" disabled=true>
      &nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre Largo</strong></FONT>
      &nbsp;
      <input name="nolar" class="campos" type="text" value="<?php echo $nolar;?>" size="55" maxlength="40">
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre Corto</strong></FONT>
      &nbsp;
      <input name="nocor" class="campos" type="text" value="<?php echo $nocor;?>" size="32" maxlength="25">
      &nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Unidad de Medida</strong></FONT>
      &nbsp;
      <select name="unmed" style="width:120px" class="campos">
      <?php
      $daumd = "select * from vtumd
                order  by 1";
      $squmd = mysql_query($daumd);
      while ($liumd = mysql_fetch_assoc($squmd)):
         if ($liumd["vtumdumed"] == $unmed):
            echo "<option  value='".$liumd['vtumdumed']."' selected>".$liumd['vtumddesc']."</option>";
         else:
            echo "<option  value='".$liumd['vtumdumed']."'>".$liumd['vtumddesc']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Categoria</strong></FONT>
      &nbsp;
      <select name="categ" style="width:166px" class="campos">
      <?php
      $dacat = "select * from vtcat
                order  by 1";
      $sqcat = mysql_query($dacat);
      while ($licat = mysql_fetch_assoc($sqcat)):
         if ($licat["vtcatdesc"] == $categ):
            echo "<option  value='".$licat['vtcatdesc']."' selected>".$licat['vtcatdesc']."</option>";
         else:
            echo "<option  value='".$licat['vtcatdesc']."'>".$licat['vtcatdesc']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Ubicacion</strong></FONT>
      &nbsp;
      <select name="ubica" style="width:120px" class="campos">
      <?php
      $daubi = "select * from vtubi
                order  by 1";
      $squbi = mysql_query($daubi);
      while ($liubi = mysql_fetch_assoc($squbi)):
         if ($liubi["vtubiubic"] == $ubica):
            echo "<option  value='".$liubi['vtubiubic']."' selected>".$liubi['vtubiubic']."</option>";
         else:
            echo "<option  value='".$liubi['vtubiubic']."'>".$liubi['vtubiubic']."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>P.Compra</strong></FONT>
      &nbsp;
      <input name="prcom" style="text-align: center" class="campos" type="text" value="<?php echo $prcom;?>" size="8" maxlength="8" disabled=true>
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>P.Venta</strong></FONT>
      &nbsp;
      <input name="prven" style="text-align: center" class="campos" type="text" value="<?php echo $prven;?>" size="8" maxlength="8" onkeypress="return validanum(event)">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Stock Max</strong></FONT>
      &nbsp;
      <input name="stmax" style="text-align: center" class="campos" type="text" value="<?php echo $stmax;?>" size="8" maxlength="8" onkeypress="return validanum(event)">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Stock Min</strong></FONT>
      &nbsp;
      <input name="stmin" style="text-align: center" class="campos" type="text" value="<?php echo $stmin;?>" size="7" maxlength="8" onkeypress="return validanum(event)">
   </tr>
   <tr height="50">
      <td>
      &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
      &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;&nbsp;
      <button type="submit" name="enviar" class="btn btn-success">Grabar el Formulario</button>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="vt221.php" class="btn btn-danger">Salir del Formulario</a></center>
      </td>
   </tr>
   </center></table>
   </form>
   </body>
   </html>
   <?php
   if (isset($_POST["enviar"])):
      if ($_POST["nolar"] == "" or $_POST["nocor"] == "" or $_POST["prven"] < 1):
         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"]));
         $categ = trim(strip_tags($_POST["categ"]));
         $ubica = trim(strip_tags($_POST["ubica"]));
         //$prcom = trim(strip_tags($_POST["prcom"]));
         $prven = trim(strip_tags($_POST["prven"]));
         $stmax = trim(strip_tags($_POST["stmax"]));
         $stmin = trim(strip_tags($_POST["stmin"]));
         mysql_query("lock tables vtart write");
         $updat = "update vtart set vtartdesc='$nolar',vtartnart='$nocor',vtartumed='$unmed',
                                    vtartcate='$categ',vtartubic='$ubica',
                                    vtartpven='$prven',vtartsmax='$stmax',vtartsmin='$stmin',
                                    vtartusua='$xusua'
                   where vtartcart = '$xcart' and vtartcalm = '$coalm'";
         mysql_query($updat);
         mysql_query("unlock tables");
         print "<script>alert(\"La Informacion de Grabo!\");
         window.location='vt221.php';</script>";
      endif;
   endif;
endif;
?>
