<?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');
$fereg = date("d-m-Y");
$xusua = $_SESSION["user_id"];
$xcodi = $_GET['id'];
$datos = mysql_query("select * from adage where adageccli = '$xcodi'");
if ($row = mysql_fetch_array($datos)):
   $fereg = date("d-m-Y",strtotime($row["adagefpro"]));
   $xnomb = $row["adagencli"];
   $xdire = $row["adagedire"];
   $telef = $row["adagetelf"];
   $xmail = $row["adagemail"];
   ?>
   <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 Cliente</h1></center>
   <form method="post" autocomplete="off">
   <center><table bgcolor= "#E0FFFF" border="1" width="55%" 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;&nbsp;
      <FONT FACE="times new roman"><strong>Codigo</strong></FONT>
      &nbsp;
      <input name="xcodi" type="text" style="text-align: center" class="campos" value="<?php echo $xcodi;?>" size="10" maxlength="10" onkeypress="return validanum(event)" disabled=true>
      &nbsp;&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Nombre</strong></FONT>
      &nbsp;
      <input name="xnomb" type="text" class="campos" value="<?php echo $xnomb;?>" size="44" maxlength="40">
      </td>
   </tr>
   <tr height="50">
      <td>&nbsp;&nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Direccion</strong></FONT>
      &nbsp;
      <input name="xdire" value="<?php echo $xdire;?>" type="text" class="campos" size="35" maxlength="35">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Telefono</strong></FONT>
      &nbsp;
      <input name="telef" value="<?php echo $telef;?>" type="text" style="text-align: center" class="campos" size="10" maxlength="11" onkeypress="return validanum(event)">
      &nbsp;&nbsp;
      <FONT FACE="times new roman"><strong>Correo</strong></FONT>
      &nbsp;
      <input name="xmail" value="<?php echo $xmail;?>" type="text" class="campos" size="31" maxlength="35">
      </td>
   </tr>
   <tr height="50">
      <td>
      </center>
      &emsp;&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;
      <a href="vt231.php" class="btn btn-danger">Salir del Formulario</a></center>
      </td>
   </tr>
   </center></table>
   </form>
   </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"]));
         $xdire = trim(strip_tags($_POST["xdire"]));
	 $telef = trim(strip_tags($_POST["telef"]));
	 $xmail = trim(strip_tags($_POST["xmail"]));
         mysql_query("lock tables adage write");
         $arsql = "update adage set adagencli='$xnomb',adagedire='$xdire',
                                    adagemail='$xmail',adagetelf='$telef'
                   where adageccli = '$xcodi'";
         mysql_query($arsql);
         mysql_query("unlock tables");
         print "<script>alert(\"La Informacion de Grabo!\");
         window.location='vt231.php';</script>";
      endif;
   endif;
endif;
?>
