<?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='vt000.php';</script>";
endif;
include_once ("lib/fpdf/funci.php");
$conex = conectar();
date_default_timezone_set('America/La_Paz');
$xusua = $_GET["id"];
$almco = $_SESSION["user_ac"];
$almve = $_SESSION["user_av"];
$datos = mysql_query("select * from adusr where adusrusua = '$xusua'");
if ($mirow = mysql_fetch_array($datos)):
   $xnomb = $mirow[1];
   $xmail = $mirow[2];
   $almco = $mirow[3];
   $almve = $mirow[4];
   $xauto = $mirow[6];
   ?>
   <html>
   <head>
   <div class="main-wrapper">
   <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 =/[1-4.]/;
      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;
   }

   .camcen{
      border-radius: 5px;
      border: 1px solid #39c;
      text-align: center;
      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 Usuario</h1></center>
   <form method="post" autocomplete="off">
   <center><table bgcolor= "#E0FFFF" border="1" width="62%" cellpadding="1" cellspacing="1" class="redondo">
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Usuario</strong></FONT>
      &nbsp;
      <input name="xusua" type="text" style="text-align: left" class="campos" value="<?php echo $xusua;?>" size="15" maxlength="15" disabled=true>
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre Completo</strong></FONT>
      &nbsp;
      <input name="xnomb" type="text" style="text-align: left" class="campos" value="<?php echo $xnomb;?>" size="40" maxlength="40">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Correo</strong></FONT>
      &nbsp;
      <input name="xmail" type="email" class="campos" value="<?php echo $xmail;?>" size="30" maxlength="30">
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Almacen Compras</strong></FONT>
      &nbsp;
      <select name="alcom" style="width:180px" class="campos">
      <?php
      $almcom = "select * from incal where incalstat = 0
                order  by 1";
      $sqcom = mysql_query($almcom);
      while ($licom = mysql_fetch_array($sqcom)):
         if ($licom[0] == $almco):
            echo "<option  value='".$licom[0]."' selected>".$licom[1]."</option>";
         else:
            echo "<option  value='".$licom[0]."'>".$licom[1]."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Almacen Ventas</strong></FONT>
      &nbsp;
      <select name="alven" style="width:180px" class="campos">
      <?php
      $almven = "select * from incal where incalstat = 0
                order  by 1";
      $sqven = mysql_query($almven);
      while ($liven = mysql_fetch_array($sqven)):
         if ($liven[0] == $almve):
            echo "<option  value='".$liven[0]."' selected>".$liven[1]."</option>";
         else:
            echo "<option  value='".$liven[0]."'>".$liven[1]."</option>";
         endif;
      endwhile;
      ?>
      </select>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Autorizacion</strong></FONT>
      &nbsp;
      <input name="xauto" type="text" class="camcen" value="<?php echo $xauto;?>" size="2" maxlength="1" onkeypress="return validanum(event)">
      </td>
   </tr>
   <tr height="50">
      <td><center>
      <button type="submit" name="enviar" class="btn btn-success">Grabar el Formulario</button>
      &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
      <a href="vt511.php" class="btn btn-danger">Salir del Formulario</a>
      </center></td>
   </tr>
   </center></table>
   </form>
   <script src="js/valida_registro.js"></script>
   </body>
   </html>
   <?php
   if (isset($_POST["enviar"])):
      if ($_POST["xnomb"] == ""):
         print '<script language="JavaScript">';
         print 'alert("Llenar los Campos Requeridos");';
         print '</script>';
      else:
         $xnomb = trim(strip_tags($_POST["xnomb"]));
	 $xmail = trim(strip_tags($_POST["xmail"]));
         $alcom = trim(strip_tags($_POST["alcom"]));
         $alven = trim(strip_tags($_POST["alven"]));
	 $xauto = trim(strip_tags($_POST["xauto"]));
         $arsql = "update adusr set adusrnomb='$xnomb',adusracom='$alcom',adusraven='$alven',
                                    adusrmail='$xmail',adusrauto='$xauto'
                   where adusrusua = '$xusua'";
         mysql_query("lock tables adusr write");
         mysql_query($arsql);
         mysql_query("unlock tables");
         $_SESSION["user_ac"]=$alcom;
         $_SESSION["user_av"]=$alven;
         print "<script>alert(\"Se Actualizo el Usuario!\");
         window.location='vt511.php';</script>";
      endif;
   endif;
endif;
?>
