<?php
date_default_timezone_set('America/La_Paz');
if (!empty($_POST)):
   if (isset($_POST["usuario"]) &&isset($_POST["contrasenia"])):
      if ($_POST["usuario"]!=""&&$_POST["contrasenia"]!=""):
         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();
         //$fehoy = date("Y-m-d");
         //$local = mysql_query("select * from sapmt where sapmtfech >= '$fehoy'");
         //$rowid = mysql_num_rows($local);
         //if ($rowid == 0) {
         //   print "<script>alert(\"Sistema Caducado llamar al Administrador.\");
         //   window.location='../login.php';</script>";
         //}
         $xusua = trim($_POST["usuario"]);
         $xpawd = trim($_POST["contrasenia"]);
         $newpw =  f1000_clave($xpawd);
         $sql1= "select * from vtusr
                 where  (vtusrusua = '$xusua' or vtusrmail = '$xusua')
                 and     vtusrpawd = '$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["vtusrstat"];
            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["vtusrauto"];
            $_SESSION["user_al"]=$resul["vtusrcalm"];
            $_SESSION["user_st"]=$resul["vtusrstat"];
            print "<script>window.location='../vt000.php';</script>";				
         endif;
      endif;
   endif;
endif;
?>
