<?php
date_default_timezone_set('America/La_Paz');
if (!empty($_POST)):
   if (isset($_POST["username"]) &&isset($_POST["fullname"]) &&isset($_POST["email"]) &&isset($_POST["password"]) &&isset($_POST["confirm_password"])):
      if ($_POST["username"]!=""&& $_POST["fullname"]!=""&&$_POST["email"]!=""&&$_POST["password"]!=""&&$_POST["password"]==$_POST["confirm_password"]):
         session_start();
         $_SESSION["user_bd"]=chr(67).chr(104).chr(97).chr(121).chr(48).chr(51).chr(54).chr(53);
         include_once "../lib/fpdf/funci.php";
         $conex = conectar();
         $xuser = $_SESSION["user_id"];
         $xusua = trim($_POST["username"]);
         $xnomb = trim($_POST["fullname"]);
         $xmail = trim($_POST["email"]);
         $xpawd = trim($_POST["password"]);
         $datim = date("Y-m-d");
         $sql1= "select * from adusr where adusrusua = '$xusua' or adusrmail = '$xmail'";
         $query = mysql_query($sql1);
         $linea = mysql_num_rows($query);
         if ($linea > 0):
            unset($_SESSION["user_bd"]);
            print "<script>alert(\"Nombre de usuario o email ya estan registrados.\");
            window.location='../vt512.php';</script>";
         endif;
         $micla = f1000_clave($xpawd);
         $xstat = 0;
         if ($xusua == "admin"):
            $xauto = "4";
         else:
            $xauto = "0";
         endif;
         $xdivi = 0;
         $sql = "insert into adusr values ('$xusua','$xnomb','$xmail',0,0,'$micla',
                                           '$xauto','$xstat','$datim','$xuser')";
         mysql_query($sql);
         if ($sql != null):
            unset($_SESSION["user_bd"]);
            print "<script>alert(\"Registro exitoso. $xusua Proceda a logearse\");
            window.location='../vt511.php';</script>";
         endif;
      endif;
   endif;
endif;
?>
