<?php
date_default_timezone_set('America/La_Paz');
if (!empty($_POST)):
   if (isset($_POST["username"]) &&isset($_POST["password"])):
      if ($_POST["username"]!=""&&$_POST["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();
         $xusua = trim($_POST["username"]);
         $xpawd = trim($_POST["password"]);
         $newpw =  f1000_clave($xpawd);
         $sql1= "select * from adusr
                 where  (adusrusua = '$xusua' or adusrmail = '$xusua')
                 and     adusrpawd = '$newpw'";
         $query = mysql_query($sql1);
         $linea = mysql_num_rows($query);
         if ($linea != 1):
            print "<script>alert(\"Acceso Invalido!\");
            window.location='../login.php';</script>";
         else:
            $resul = mysql_fetch_assoc($query);
            $stado = $resul["adusrstat"];
            if ($stado == 1):
               print "<script>alert(\"Usuario Activo!\");
               window.location='../login.php';</script>";
            elseif ($stado == 9):
               print "<script>alert(\"Usuario de Baja!\");
               window.location='../login.php';</script>";
            endif;
            $_SESSION["user_id"]=$xusua;
            $_SESSION["user_at"]=$resul["adusrauto"];
            $_SESSION["user_st"]=$resul["adusrstat"];
            $_SESSION["user_ac"]=$resul["adusracom"];
            $_SESSION["user_av"]=$resul["adusraven"];
            print "<script>window.location='../vt000.php';</script>";				
         endif;
      endif;
   endif;
endif;
?>
